vdr 2.6.1
Classes | Macros | Typedefs | Functions | Variables
tools.h File Reference
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <float.h>
#include <iconv.h>
#include <math.h>
#include <poll.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "thread.h"

Go to the source code of this file.

Classes

class  cCharSetConv
 
class  cString
 
class  cNullTerminate
 
class  cBase64Encoder
 
class  cBitStream
 
class  cTimeMs
 
class  cReadLine
 
class  cPoller
 
class  cReadDir
 
class  cFile
 
class  cSafeFile
 
class  cUnbufferedFile
 
class  cLockFile
 
class  cListObject
 
class  cListGarbageCollector
 
class  cListBase
 
class  cList< T >
 
class  cVector< T >
 
class  cStringList
 
class  cFileNameList
 
class  cDynamicBuffer
 
class  cHashObject
 
class  cHashBase
 
class  cHash< T >
 

Macros

#define esyslog(a...)   void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() )
 
#define isyslog(a...)   void( (SysLogLevel > 1) ? syslog_with_tid(LOG_INFO, a) : void() )
 
#define dsyslog(a...)   void( (SysLogLevel > 2) ? syslog_with_tid(LOG_DEBUG, a) : void() )
 
#define LOG_ERROR   esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__)
 
#define LOG_ERROR_STR(s)   esyslog("ERROR (%s,%d): %s: %m", __FILE__, __LINE__, s)
 
#define SECSINDAY   86400
 
#define KILOBYTE(n)   ((n) * 1024)
 
#define MEGABYTE(n)   ((n) * 1024LL * 1024LL)
 
#define MALLOC(type, size)   (type *)malloc(sizeof(type) * (size))
 
#define CHECK(s)   { if ((s) < 0) LOG_ERROR; }
 
#define FATALERRNO   (errno && errno != EAGAIN && errno != EINTR)
 
#define BCDCHARTOINT(x)   (10 * ((x & 0xF0) >> 4) + (x & 0xF))
 
#define IsBitSet(v, b)   ((v) & (1 << (b)))
 
#define Utf8BufSize(s)   ((s) * 4)
 
#define Utf8to(conv, c)   (cCharSetConv::SystemCharacterTable() ? to##conv(c) : tow##conv(c))
 
#define Utf8is(ccls, c)   (cCharSetConv::SystemCharacterTable() ? is##ccls(c) : isw##ccls(c))
 
#define DEPRECATED_CFILE   0
 
#define DEF_LIST_LOCK2(Class, Name)
 
#define DEF_LIST_LOCK(Class)   DEF_LIST_LOCK2(Class, Class)
 
#define USE_LIST_LOCK_READ2(Class, Name)
 
#define USE_LIST_LOCK_READ(Class)   USE_LIST_LOCK_READ2(Class, Class)
 
#define USE_LIST_LOCK_WRITE2(Class, Name)
 
#define USE_LIST_LOCK_WRITE(Class)   USE_LIST_LOCK_WRITE2(Class, Class)
 
#define HASHSIZE   512
 

Typedefs

typedef unsigned char uchar
 

Functions

template<class T >
void DELETENULL (T *&p)
 
template<class T >
min (T a, T b)
 
template<class T >
max (T a, T b)
 
template<class T >
void swap (T &a, T &b)
 
template<class T >
int sgn (T a)
 
template<class T >
constrain (T v, T l, T h)
 
void syslog_with_tid (int priority, const char *format,...) __attribute__((format(printf
 
int BCD2INT (int x)
 
template<class T >
get_unaligned (T *p)
 
template<class T >
void put_unaligned (unsigned int v, T *p)
 
bool DoubleEqual (double a, double b)
 
int Utf8CharLen (const char *s)
 
uint Utf8CharGet (const char *s, int Length=0)
 
int Utf8CharSet (uint c, char *s=NULL)
 
int Utf8SymChars (const char *s, int Symbols)
 
int Utf8StrLen (const char *s)
 
char * Utf8Strn0Cpy (char *Dest, const char *Src, int n)
 
int Utf8ToArray (const char *s, uint *a, int Size)
 
int Utf8FromArray (const uint *a, char *s, int Size, int Max=-1)
 
ssize_t safe_read (int filedes, void *buffer, size_t size)
 
ssize_t safe_write (int filedes, const void *buffer, size_t size)
 
void writechar (int filedes, char c)
 
int WriteAllOrNothing (int fd, const uchar *Data, int Length, int TimeoutMs=0, int RetryMs=0)
 
char * strcpyrealloc (char *dest, const char *src)
 
char * strn0cpy (char *dest, const char *src, size_t n)
 
char * strreplace (char *s, char c1, char c2)
 
char * strreplace (char *s, const char *s1, const char *s2)
 
const char * strchrn (const char *s, char c, size_t n)
 
int strcountchr (const char *s, char c)
 
cString strgetbefore (const char *s, char c, int n=1)
 
const char * strgetlast (const char *s, char c)
 
char * strgetlast (char *s, char c)
 
char * skipspace (const char *s)
 
char * stripspace (char *s)
 
char * compactspace (char *s)
 
char * compactchars (char *s, char c)
 
cString strescape (const char *s, const char *chars)
 
cString strgetval (const char *s, const char *name, char d='=')
 
char * strshift (char *s, int n)
 
bool startswith (const char *s, const char *p)
 
bool endswith (const char *s, const char *p)
 
bool isempty (const char *s)
 
int numdigits (int n)
 
bool isnumber (const char *s)
 
int64_t StrToNum (const char *s)
 
bool StrInArray (const char *a[], const char *s)
 
double atod (const char *s)
 
cString dtoa (double d, const char *Format="%f")
 
cString itoa (int n)
 
uint16_t Peek13 (const uchar *p)
 
void Poke13 (uchar *p, uint16_t v)
 
cString AddDirectory (const char *DirName, const char *FileName)
 
bool EntriesOnSameFileSystem (const char *File1, const char *File2)
 
int FreeDiskSpaceMB (const char *Directory, int *UsedMB=NULL)
 
bool DirectoryOk (const char *DirName, bool LogErrors=false)
 
bool MakeDirs (const char *FileName, bool IsDirectory=false)
 
bool RemoveFileOrDir (const char *FileName, bool FollowSymlinks=false)
 
bool RemoveEmptyDirectories (const char *DirName, bool RemoveThis=false, const char *IgnoreFiles[]=NULL)
 
int DirSizeMB (const char *DirName)
 
char * ReadLink (const char *FileName)
 
bool SpinUpDisk (const char *FileName)
 
void TouchFile (const char *FileName)
 
time_t LastModifiedTime (const char *FileName)
 
off_t FileSize (const char *FileName)
 
cString WeekDayName (int WeekDay)
 
cString WeekDayName (time_t t)
 
cString WeekDayNameFull (int WeekDay)
 
cString WeekDayNameFull (time_t t)
 
cString DayDateTime (time_t t=0)
 
cString TimeToString (time_t t)
 
cString DateString (time_t t)
 
cString ShortDateString (time_t t)
 
cString TimeString (time_t t)
 
ucharRgbToJpeg (uchar *Mem, int Width, int Height, int &Size, int Quality=100)
 
const char * GetHostName (void)
 
int CompareInts (const void *a, const void *b)
 
int CompareStrings (const void *a, const void *b)
 
int CompareStringsIgnoreCase (const void *a, const void *b)
 
int CompareStringsNumerically (const void *a, const void *b)
 

Variables

int SysLogLevel
 
cListGarbageCollector ListGarbageCollector
 

Macro Definition Documentation

◆ BCDCHARTOINT

#define BCDCHARTOINT (   x)    (10 * ((x & 0xF0) >> 4) + (x & 0xF))

Definition at line 74 of file tools.h.

◆ CHECK

#define CHECK (   s)    { if ((s) < 0) LOG_ERROR; }

Definition at line 51 of file tools.h.

◆ DEF_LIST_LOCK

#define DEF_LIST_LOCK (   Class)    DEF_LIST_LOCK2(Class, Class)

Definition at line 696 of file tools.h.

◆ DEF_LIST_LOCK2

#define DEF_LIST_LOCK2 (   Class,
  Name 
)
Value:
class c##Name##_Lock { \
private: \
cStateKey stateKey; \
const c##Class *list; \
public: \
c##Name##_Lock(bool Write = false) \
{ \
if (Write) \
list = c##Class::Get##Name##Write(stateKey); \
else \
list = c##Class::Get##Name##Read(stateKey); \
} \
~c##Name##_Lock() { if (list) stateKey.Remove(); } \
const c##Class *Name(void) const { return list; } \
c##Class *Name(void) { return const_cast<c##Class *>(list); } \
}

Definition at line 679 of file tools.h.

◆ DEPRECATED_CFILE

#define DEPRECATED_CFILE   0

Definition at line 461 of file tools.h.

◆ dsyslog

#define dsyslog (   a...)    void( (SysLogLevel > 2) ? syslog_with_tid(LOG_DEBUG, a) : void() )

Definition at line 37 of file tools.h.

◆ esyslog

#define esyslog (   a...)    void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() )

Definition at line 35 of file tools.h.

◆ FATALERRNO

#define FATALERRNO   (errno && errno != EAGAIN && errno != EINTR)

Definition at line 52 of file tools.h.

◆ HASHSIZE

#define HASHSIZE   512

Definition at line 924 of file tools.h.

◆ IsBitSet

#define IsBitSet (   v,
 
)    ((v) & (1 << (b)))

Definition at line 77 of file tools.h.

◆ isyslog

#define isyslog (   a...)    void( (SysLogLevel > 1) ? syslog_with_tid(LOG_INFO, a) : void() )

Definition at line 36 of file tools.h.

◆ KILOBYTE

#define KILOBYTE (   n)    ((n) * 1024)

Definition at line 44 of file tools.h.

◆ LOG_ERROR

#define LOG_ERROR   esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__)

Definition at line 39 of file tools.h.

◆ LOG_ERROR_STR

#define LOG_ERROR_STR (   s)    esyslog("ERROR (%s,%d): %s: %m", __FILE__, __LINE__, s)

Definition at line 40 of file tools.h.

◆ MALLOC

#define MALLOC (   type,
  size 
)    (type *)malloc(sizeof(type) * (size))

Definition at line 47 of file tools.h.

◆ MEGABYTE

#define MEGABYTE (   n)    ((n) * 1024LL * 1024LL)

Definition at line 45 of file tools.h.

◆ SECSINDAY

#define SECSINDAY   86400

Definition at line 42 of file tools.h.

◆ USE_LIST_LOCK_READ

#define USE_LIST_LOCK_READ (   Class)    USE_LIST_LOCK_READ2(Class, Class)

Definition at line 704 of file tools.h.

◆ USE_LIST_LOCK_READ2

#define USE_LIST_LOCK_READ2 (   Class,
  Name 
)
Value:
c##Name##_Lock Name##_Lock(false); \
const c##Class *Name __attribute__((unused)) = Name##_Lock.Name();
struct __attribute__((packed))
Definition: recording.c:2534

Definition at line 701 of file tools.h.

◆ USE_LIST_LOCK_WRITE

#define USE_LIST_LOCK_WRITE (   Class)    USE_LIST_LOCK_WRITE2(Class, Class)

Definition at line 709 of file tools.h.

◆ USE_LIST_LOCK_WRITE2

#define USE_LIST_LOCK_WRITE2 (   Class,
  Name 
)
Value:
c##Name##_Lock Name##_Lock(true); \
c##Class *Name __attribute__((unused)) = Name##_Lock.Name();

Definition at line 706 of file tools.h.

◆ Utf8BufSize

#define Utf8BufSize (   s)    ((s) * 4)

Definition at line 143 of file tools.h.

◆ Utf8is

#define Utf8is (   ccls,
 
)    (cCharSetConv::SystemCharacterTable() ? is##ccls(c) : isw##ccls(c))

Definition at line 149 of file tools.h.

◆ Utf8to

#define Utf8to (   conv,
 
)    (cCharSetConv::SystemCharacterTable() ? to##conv(c) : tow##conv(c))

Definition at line 148 of file tools.h.

Typedef Documentation

◆ uchar

typedef unsigned char uchar

Definition at line 31 of file tools.h.

Function Documentation

◆ AddDirectory()

cString AddDirectory ( const char *  DirName,
const char *  FileName 
)

◆ atod()

double atod ( const char *  s)

Converts the given string, which is a floating point number using a '.

' as the decimal point, to a double value, independent of the currently selected locale.

Definition at line 411 of file tools.c.

◆ BCD2INT()

int BCD2INT ( int  x)

Definition at line 45 of file tools.c.

◆ compactchars()

char * compactchars ( char *  s,
char  c 
)

removes all occurrences of 'c' from the beginning an end of 's' and replaces sequences of multiple 'c's with a single 'c'.

Definition at line 248 of file tools.c.

Referenced by cString::CompactChars().

◆ compactspace()

char * compactspace ( char *  s)

Definition at line 231 of file tools.c.

◆ CompareInts()

int CompareInts ( const void *  a,
const void *  b 
)
inline

Definition at line 827 of file tools.h.

◆ CompareStrings()

int CompareStrings ( const void *  a,
const void *  b 
)
inline

Definition at line 832 of file tools.h.

Referenced by CompareStringsNumerically(), and cStringList::Sort().

◆ CompareStringsIgnoreCase()

int CompareStringsIgnoreCase ( const void *  a,
const void *  b 
)
inline

Definition at line 837 of file tools.h.

Referenced by cStringList::Sort().

◆ CompareStringsNumerically()

int CompareStringsNumerically ( const void *  a,
const void *  b 
)
inline

Definition at line 842 of file tools.h.

References CompareStrings().

Referenced by cStringList::SortNumerically().

◆ constrain()

template<class T >
T constrain ( v,
l,
h 
)
inline

Definition at line 70 of file tools.h.

◆ DateString()

cString DateString ( time_t  t)

Converts the given time to a string of the form "www dd.mm.yyyy".

Definition at line 1235 of file tools.c.

◆ DayDateTime()

cString DayDateTime ( time_t  t = 0)

Converts the given time to a string of the form "www dd.mm. hh:mm".

If no time is given, the current time is taken.

Definition at line 1214 of file tools.c.

◆ DELETENULL()

template<class T >
void DELETENULL ( T *&  p)
inline

Definition at line 49 of file tools.h.

◆ DirectoryOk()

bool DirectoryOk ( const char *  DirName,
bool  LogErrors = false 
)

Definition at line 481 of file tools.c.

Referenced by cLockFile::cLockFile(), and SpinUpDisk().

◆ DirSizeMB()

int DirSizeMB ( const char *  DirName)

returns the total size of the files in the given directory, or -1 in case of an error

Definition at line 639 of file tools.c.

Referenced by DirSizeMB().

◆ DoubleEqual()

bool DoubleEqual ( double  a,
double  b 
)
inline

Definition at line 97 of file tools.h.

◆ dtoa()

cString dtoa ( double  d,
const char *  Format = "%f" 
)

Converts the given double value to a string, making sure it uses a '.

' as the decimal point, independent of the currently selected locale. If Format is given, it will be used instead of the default.

Definition at line 432 of file tools.c.

◆ endswith()

bool endswith ( const char *  s,
const char *  p 
)

Definition at line 338 of file tools.c.

◆ EntriesOnSameFileSystem()

bool EntriesOnSameFileSystem ( const char *  File1,
const char *  File2 
)

Checks whether the given files are on the same file system.

If either of the files doesn't exist, this function returns true to avoid any actions that might be triggered if files are on different file system.

Definition at line 449 of file tools.c.

◆ FileSize()

off_t FileSize ( const char *  FileName)

returns the size of the given file, or -1 in case of an error (e.g. if the file doesn't exist)

Definition at line 731 of file tools.c.

◆ FreeDiskSpaceMB()

int FreeDiskSpaceMB ( const char *  Directory,
int *  UsedMB = NULL 
)

Definition at line 464 of file tools.c.

◆ get_unaligned()

template<class T >
T get_unaligned ( T *  p)
inline

Definition at line 82 of file tools.h.

References __attribute__().

◆ GetHostName()

const char * GetHostName ( void  )

Gets the host name of this machine.

Definition at line 1363 of file tools.c.

◆ isempty()

bool isempty ( const char *  s)

Definition at line 349 of file tools.c.

◆ isnumber()

bool isnumber ( const char *  s)

Definition at line 364 of file tools.c.

◆ itoa()

cString itoa ( int  n)

Definition at line 442 of file tools.c.

◆ LastModifiedTime()

time_t LastModifiedTime ( const char *  FileName)

Definition at line 723 of file tools.c.

◆ MakeDirs()

bool MakeDirs ( const char *  FileName,
bool  IsDirectory = false 
)

Definition at line 499 of file tools.c.

◆ max()

template<class T >
T max ( a,
b 
)
inline

Definition at line 64 of file tools.h.

◆ min()

template<class T >
T min ( a,
b 
)
inline

Definition at line 63 of file tools.h.

◆ numdigits()

int numdigits ( int  n)

Definition at line 354 of file tools.c.

◆ Peek13()

uint16_t Peek13 ( const uchar p)
inline

Definition at line 290 of file tools.h.

◆ Poke13()

void Poke13 ( uchar p,
uint16_t  v 
)
inline

Definition at line 295 of file tools.h.

◆ put_unaligned()

template<class T >
void put_unaligned ( unsigned int  v,
T *  p 
)
inline

Definition at line 88 of file tools.h.

References __attribute__().

◆ ReadLink()

char * ReadLink ( const char *  FileName)

returns a new string allocated on the heap, which the caller must delete (or NULL in case of an error)

Definition at line 671 of file tools.c.

Referenced by cSafeFile::cSafeFile().

◆ RemoveEmptyDirectories()

bool RemoveEmptyDirectories ( const char *  DirName,
bool  RemoveThis = false,
const char *  IgnoreFiles[] = NULL 
)

Removes all empty directories under the given directory DirName.

If RemoveThis is true, DirName will also be removed if it is empty. IgnoreFiles can be set to an array of file names that will be ignored when considering whether a directory is empty. If IgnoreFiles is given, the array must end with a NULL pointer.

Definition at line 585 of file tools.c.

Referenced by RemoveEmptyDirectories().

◆ RemoveFileOrDir()

bool RemoveFileOrDir ( const char *  FileName,
bool  FollowSymlinks = false 
)

Definition at line 527 of file tools.c.

◆ RgbToJpeg()

uchar * RgbToJpeg ( uchar Mem,
int  Width,
int  Height,
int &  Size,
int  Quality = 100 
)

Converts the given Memory to a JPEG image and returns a pointer to the resulting image.

Mem must point to a data block of exactly (Width * Height) triplets of RGB image data bytes. Upon return, Size will hold the number of bytes of the resulting JPEG data. Quality can be in the range 0..100 and controls the quality of the resulting image, where 100 is "best". The caller takes ownership of the result and has to delete it once it is no longer needed. The result may be NULL in case of an error.

Definition at line 1320 of file tools.c.

◆ safe_read()

ssize_t safe_read ( int  filedes,
void *  buffer,
size_t  size 
)

Definition at line 53 of file tools.c.

Referenced by cUnbufferedFile::Read().

◆ safe_write()

ssize_t safe_write ( int  filedes,
const void *  buffer,
size_t  size 
)

Definition at line 65 of file tools.c.

Referenced by cUnbufferedFile::Write(), and writechar().

◆ sgn()

template<class T >
int sgn ( a)
inline

Definition at line 68 of file tools.h.

◆ ShortDateString()

cString ShortDateString ( time_t  t)

Converts the given time to a string of the form "dd.mm.yy".

Definition at line 1246 of file tools.c.

◆ skipspace()

char * skipspace ( const char *  s)
inline

Definition at line 241 of file tools.h.

References cString::s.

◆ SpinUpDisk()

bool SpinUpDisk ( const char *  FileName)

Definition at line 685 of file tools.c.

◆ startswith()

bool startswith ( const char *  s,
const char *  p 
)

Definition at line 329 of file tools.c.

◆ strchrn()

const char * strchrn ( const char *  s,
char  c,
size_t  n 
)

returns a pointer to the n'th occurrence (counting from 1) of c in s, or NULL if no such character was found. If n is 0, s is returned.

Definition at line 178 of file tools.c.

◆ strcountchr()

int strcountchr ( const char *  s,
char  c 
)

returns the number of occurrences of 'c' in 's'.

Definition at line 191 of file tools.c.

◆ strcpyrealloc()

char * strcpyrealloc ( char *  dest,
const char *  src 
)

Definition at line 114 of file tools.c.

◆ strescape()

cString strescape ( const char *  s,
const char *  chars 
)

Definition at line 272 of file tools.c.

◆ strgetbefore()

cString strgetbefore ( const char *  s,
char  c,
int  n = 1 
)

Definition at line 203 of file tools.c.

◆ strgetlast() [1/2]

char * strgetlast ( char *  s,
char  c 
)
inline

Definition at line 240 of file tools.h.

References cString::s, and strgetlast().

◆ strgetlast() [2/2]

const char * strgetlast ( const char *  s,
char  c 
)

Definition at line 213 of file tools.c.

Referenced by strgetlast().

◆ strgetval()

cString strgetval ( const char *  s,
const char *  name,
char  d = '=' 
)

Returns the value part of a 'name=value' pair in s.

name must either be at the beginning of s, or has to be preceded by white space. There may be any number of white space around the '=' sign. The value is everything up to (and excluding) the next white space, or the end of s. If an other delimiter shall be used (like, e.g., ':'), it can be given as the third parameter. If name occurs more than once in s, only the first occurrence is taken.

Definition at line 295 of file tools.c.

◆ StrInArray()

bool StrInArray ( const char *  a[],
const char *  s 
)

Returns true if the string s is equal to one of the strings pointed to by the (NULL terminated) array a.

Definition at line 390 of file tools.c.

Referenced by RemoveEmptyDirectories().

◆ stripspace()

char * stripspace ( char *  s)

Definition at line 219 of file tools.c.

Referenced by compactspace().

◆ strn0cpy()

char * strn0cpy ( char *  dest,
const char *  src,
size_t  n 
)

Definition at line 131 of file tools.c.

Referenced by Utf8Strn0Cpy(), and WeekDayName().

◆ strreplace() [1/2]

char * strreplace ( char *  s,
char  c1,
char  c2 
)

Definition at line 139 of file tools.c.

Referenced by dtoa().

◆ strreplace() [2/2]

char * strreplace ( char *  s,
const char *  s1,
const char *  s2 
)

re-allocates 's' and deletes the original string if necessary!

Definition at line 152 of file tools.c.

◆ strshift()

char * strshift ( char *  s,
int  n 
)

Shifts the given string to the left by the given number of bytes, thus removing the first n bytes from s.

If n is greater than the length of s, the resulting string will be empty. If n is <= 0 s will be unchanged. Returns s.

Definition at line 317 of file tools.c.

◆ StrToNum()

int64_t StrToNum ( const char *  s)

Converts the given string to a number.

The numerical part of the string may be followed by one of the letters K, M, G or T to abbreviate Kilo-, Mega-, Giga- or Terabyte, respectively (based on 1024). Everything after the first non-numeric character is silently ignored, as are any characters other than the ones mentioned here.

Definition at line 375 of file tools.c.

◆ swap()

template<class T >
void swap ( T &  a,
T &  b 
)
inline

Definition at line 65 of file tools.h.

◆ syslog_with_tid()

void syslog_with_tid ( int  priority,
const char *  format,
  ... 
)

◆ TimeString()

cString TimeString ( time_t  t)

Converts the given time to a string of the form "hh:mm".

Definition at line 1255 of file tools.c.

◆ TimeToString()

cString TimeToString ( time_t  t)

Converts the given time to a string of the form "www mmm dd hh:mm:ss yyyy".

Definition at line 1225 of file tools.c.

◆ TouchFile()

void TouchFile ( const char *  FileName)

Definition at line 717 of file tools.c.

◆ Utf8CharGet()

uint Utf8CharGet ( const char *  s,
int  Length = 0 
)

Returns the UTF-8 symbol at the beginning of the given string.

Length can be given from a previous call to Utf8CharLen() to avoid calculating it again. If no Length is given, Utf8CharLen() will be called.

Definition at line 825 of file tools.c.

Referenced by cCharSetConv::SetSystemCharacterTable(), and Utf8ToArray().

◆ Utf8CharLen()

int Utf8CharLen ( const char *  s)

Returns the number of character bytes at the beginning of the given string that form a UTF-8 symbol.

Definition at line 811 of file tools.c.

Referenced by cCharSetConv::SetSystemCharacterTable(), Utf8CharGet(), Utf8StrLen(), Utf8Strn0Cpy(), Utf8SymChars(), and Utf8ToArray().

◆ Utf8CharSet()

int Utf8CharSet ( uint  c,
char *  s = NULL 
)

Converts the given UTF-8 symbol to a sequence of character bytes and copies them to the given string.

Returns the number of bytes written. If no string is given, only the number of bytes is returned and nothing is copied.

Definition at line 840 of file tools.c.

Referenced by Utf8FromArray().

◆ Utf8FromArray()

int Utf8FromArray ( const uint *  a,
char *  s,
int  Size,
int  Max = -1 
)

Converts the given array of UTF-8 symbols (including the terminating 0) into a sequence of character bytes of at most Size length.

Returns the number of character bytes written (without the terminating 0). If Max is given, only that many symbols will be converted. The resulting string is always zero-terminated if Size is big enough.

Definition at line 936 of file tools.c.

◆ Utf8StrLen()

int Utf8StrLen ( const char *  s)

Returns the number of UTF-8 symbols formed by the given string of character bytes.

Definition at line 887 of file tools.c.

◆ Utf8Strn0Cpy()

char * Utf8Strn0Cpy ( char *  Dest,
const char *  Src,
int  n 
)

Copies at most n character bytes from Src to Dest, making sure that the resulting copy ends with a complete UTF-8 symbol.

The copy is guaranteed to be zero terminated. Returns a pointer to Dest.

Definition at line 899 of file tools.c.

◆ Utf8SymChars()

int Utf8SymChars ( const char *  s,
int  Symbols 
)

Returns the number of character bytes at the beginning of the given string that form at most the given number of UTF-8 symbols.

Definition at line 874 of file tools.c.

Referenced by WeekDayName().

◆ Utf8ToArray()

int Utf8ToArray ( const char *  s,
uint *  a,
int  Size 
)

Converts the given character bytes (including the terminating 0) into an array of UTF-8 symbols of the given Size.

Returns the number of symbols in the array (without the terminating 0).

Definition at line 918 of file tools.c.

◆ WeekDayName() [1/2]

cString WeekDayName ( int  WeekDay)

Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a three letter day name.

Definition at line 1172 of file tools.c.

Referenced by DateString(), DayDateTime(), and WeekDayName().

◆ WeekDayName() [2/2]

cString WeekDayName ( time_t  t)

Converts the week day of the given time to a three letter day name.

Definition at line 1187 of file tools.c.

◆ WeekDayNameFull() [1/2]

cString WeekDayNameFull ( int  WeekDay)

Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a full day name.

Definition at line 1193 of file tools.c.

Referenced by WeekDayNameFull().

◆ WeekDayNameFull() [2/2]

cString WeekDayNameFull ( time_t  t)

Converts the week day of the given time to a full day name.

Definition at line 1208 of file tools.c.

◆ WriteAllOrNothing()

int WriteAllOrNothing ( int  fd,
const uchar Data,
int  Length,
int  TimeoutMs = 0,
int  RetryMs = 0 
)

Writes either all Data to the given file descriptor, or nothing at all.

If TimeoutMs is greater than 0, it will only retry for that long, otherwise it will retry forever. RetryMs defines the time between two retries.

Definition at line 90 of file tools.c.

◆ writechar()

void writechar ( int  filedes,
char  c 
)

Definition at line 85 of file tools.c.

Variable Documentation

◆ ListGarbageCollector

cListGarbageCollector ListGarbageCollector
extern

Definition at line 2120 of file tools.c.

Referenced by cListBase::Del().

◆ SysLogLevel

int SysLogLevel
extern

Definition at line 31 of file tools.c.