vdr  2.2.0
tools.h
Go to the documentation of this file.
1 /*
2  * tools.h: Various tools
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: tools.h 3.7 2015/02/07 15:12:26 kls Exp $
8  */
9 
10 #ifndef __TOOLS_H
11 #define __TOOLS_H
12 
13 #include <dirent.h>
14 #include <errno.h>
15 #include <fcntl.h>
16 #include <float.h>
17 #include <iconv.h>
18 #include <math.h>
19 #include <poll.h>
20 #include <stdarg.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <syslog.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 
30 typedef unsigned char uchar;
31 
32 extern int SysLogLevel;
33 
34 #define esyslog(a...) void( (SysLogLevel > 0) ? syslog_with_tid(LOG_ERR, a) : void() )
35 #define isyslog(a...) void( (SysLogLevel > 1) ? syslog_with_tid(LOG_INFO, a) : void() )
36 #define dsyslog(a...) void( (SysLogLevel > 2) ? syslog_with_tid(LOG_DEBUG, a) : void() )
37 
38 #define LOG_ERROR esyslog("ERROR (%s,%d): %m", __FILE__, __LINE__)
39 #define LOG_ERROR_STR(s) esyslog("ERROR (%s,%d): %s: %m", __FILE__, __LINE__, s)
40 
41 #define SECSINDAY 86400
42 
43 #define KILOBYTE(n) ((n) * 1024)
44 #define MEGABYTE(n) ((n) * 1024LL * 1024LL)
45 
46 #define MALLOC(type, size) (type *)malloc(sizeof(type) * (size))
47 
48 template<class T> inline void DELETENULL(T *&p) { T *q = p; p = NULL; delete q; }
49 
50 #define CHECK(s) { if ((s) < 0) LOG_ERROR; } // used for 'ioctl()' calls
51 #define FATALERRNO (errno && errno != EAGAIN && errno != EINTR)
52 
53 #ifndef __STL_CONFIG_H // in case some plugin needs to use the STL
54 template<class T> inline T min(T a, T b) { return a <= b ? a : b; }
55 template<class T> inline T max(T a, T b) { return a >= b ? a : b; }
56 template<class T> inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
57 template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
58 #endif
59 
60 template<class T> inline T constrain(T v, T l, T h) { return v < l ? l : v > h ? h : v; }
61 
62 void syslog_with_tid(int priority, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
63 
64 #define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF))
65 int BCD2INT(int x);
66 
67 #define IsBitSet(v, b) ((v) & (1 << (b))) // checks if the bit at index b is set in v, where the least significant bit has index 0
68 
69 // Unfortunately there are no platform independent macros for unaligned
70 // access, so we do it this way:
71 
72 template<class T> inline T get_unaligned(T *p)
73 {
74  struct s { T v; } __attribute__((packed));
75  return ((s *)p)->v;
76 }
77 
78 template<class T> inline void put_unaligned(unsigned int v, T* p)
79 {
80  struct s { T v; } __attribute__((packed));
81  ((s *)p)->v = v;
82 }
83 
84 // Comparing doubles for equality is unsafe, but unfortunately we can't
85 // overwrite operator==(double, double), so this will have to do:
86 
87 inline bool DoubleEqual(double a, double b)
88 {
89  return fabs(a - b) <= DBL_EPSILON;
90 }
91 
92 // When handling strings that might contain UTF-8 characters, it may be necessary
93 // to process a "symbol" that consists of several actual character bytes. The
94 // following functions allow transparently accessing a "char *" string without
95 // having to worry about what character set is actually used.
96 
97 int Utf8CharLen(const char *s);
100 uint Utf8CharGet(const char *s, int Length = 0);
104 int Utf8CharSet(uint c, char *s = NULL);
108 int Utf8SymChars(const char *s, int Symbols);
111 int Utf8StrLen(const char *s);
114 char *Utf8Strn0Cpy(char *Dest, const char *Src, int n);
119 int Utf8ToArray(const char *s, uint *a, int Size);
123 int Utf8FromArray(const uint *a, char *s, int Size, int Max = -1);
129 
130 // When allocating buffer space, make sure we reserve enough space to hold
131 // a string in UTF-8 representation:
132 
133 #define Utf8BufSize(s) ((s) * 4)
134 
135 // The following macros automatically use the correct versions of the character
136 // class functions:
137 
138 #define Utf8to(conv, c) (cCharSetConv::SystemCharacterTable() ? to##conv(c) : tow##conv(c))
139 #define Utf8is(ccls, c) (cCharSetConv::SystemCharacterTable() ? is##ccls(c) : isw##ccls(c))
140 
142 private:
143  iconv_t cd;
144  char *result;
145  size_t length;
146  static char *systemCharacterTable;
147 public:
148  cCharSetConv(const char *FromCode = NULL, const char *ToCode = NULL);
153  ~cCharSetConv();
154  const char *Convert(const char *From, char *To = NULL, size_t ToLength = 0);
164  static const char *SystemCharacterTable(void) { return systemCharacterTable; }
165  static void SetSystemCharacterTable(const char *CharacterTable);
166  };
167 
168 class cString {
169 private:
170  char *s;
171 public:
172  cString(const char *S = NULL, bool TakePointer = false);
173  cString(const char *S, const char *To);
174  cString(const cString &String);
175  virtual ~cString();
176  operator const void * () const { return s; } // to catch cases where operator*() should be used
177  operator const char * () const { return s; } // for use in (const char *) context
178  const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)
179  cString &operator=(const cString &String);
180  cString &operator=(const char *String);
181  cString &Truncate(int Index);
182  cString &CompactChars(char c);
183  static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
184  static cString vsprintf(const char *fmt, va_list &ap);
185  };
186 
187 ssize_t safe_read(int filedes, void *buffer, size_t size);
188 ssize_t safe_write(int filedes, const void *buffer, size_t size);
189 void writechar(int filedes, char c);
190 int WriteAllOrNothing(int fd, const uchar *Data, int Length, int TimeoutMs = 0, int RetryMs = 0);
194 char *strcpyrealloc(char *dest, const char *src);
195 char *strn0cpy(char *dest, const char *src, size_t n);
196 char *strreplace(char *s, char c1, char c2);
197 char *strreplace(char *s, const char *s1, const char *s2);
198 const char *strchrn(const char *s, char c, size_t n);
199 int strcountchr(const char *s, char c);
200 inline char *skipspace(const char *s)
201 {
202  if ((uchar)*s > ' ') // most strings don't have any leading space, so handle this case as fast as possible
203  return (char *)s;
204  while (*s && (uchar)*s <= ' ') // avoiding isspace() here, because it is much slower
205  s++;
206  return (char *)s;
207 }
208 char *stripspace(char *s);
209 char *compactspace(char *s);
210 char *compactchars(char *s, char c);
211 cString strescape(const char *s, const char *chars);
212 bool startswith(const char *s, const char *p);
213 bool endswith(const char *s, const char *p);
214 bool isempty(const char *s);
215 int numdigits(int n);
216 bool isnumber(const char *s);
217 int64_t StrToNum(const char *s);
223 bool StrInArray(const char *a[], const char *s);
226 double atod(const char *s);
230 cString dtoa(double d, const char *Format = "%f");
234 cString itoa(int n);
235 cString AddDirectory(const char *DirName, const char *FileName);
236 bool EntriesOnSameFileSystem(const char *File1, const char *File2);
240 int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL);
241 bool DirectoryOk(const char *DirName, bool LogErrors = false);
242 bool MakeDirs(const char *FileName, bool IsDirectory = false);
243 bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false);
244 bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false, const char *IgnoreFiles[] = NULL);
250 int DirSizeMB(const char *DirName);
251 char *ReadLink(const char *FileName);
252 bool SpinUpDisk(const char *FileName);
253 void TouchFile(const char *FileName);
254 time_t LastModifiedTime(const char *FileName);
255 off_t FileSize(const char *FileName);
256 cString WeekDayName(int WeekDay);
259 cString WeekDayName(time_t t);
261 cString WeekDayNameFull(int WeekDay);
264 cString WeekDayNameFull(time_t t);
266 cString DayDateTime(time_t t = 0);
269 cString TimeToString(time_t t);
271 cString DateString(time_t t);
273 cString ShortDateString(time_t t);
275 cString TimeString(time_t t);
277 uchar *RgbToJpeg(uchar *Mem, int Width, int Height, int &Size, int Quality = 100);
286 
288 private:
289  const uchar *data;
290  int length;
292  int i;
293  char *result;
294  static const char *b64;
295 public:
296  cBase64Encoder(const uchar *Data, int Length, int MaxResult = 64);
302  ~cBase64Encoder();
303  const char *NextLine(void);
309  };
310 
311 class cBitStream {
312 private:
313  const uint8_t *data;
314  int length; // in bits
315  int index; // in bits
316 public:
317  cBitStream(const uint8_t *Data, int Length) : data(Data), length(Length), index(0) {}
319  int GetBit(void);
320  uint32_t GetBits(int n);
321  void ByteAlign(void);
322  void WordAlign(void);
323  bool SetLength(int Length);
324  void SkipBits(int n) { index += n; }
325  void SkipBit(void) { SkipBits(1); }
326  bool IsEOF(void) const { return index >= length; }
327  void Reset(void) { index = 0; }
328  int Length(void) const { return length; }
329  int Index(void) const { return (IsEOF() ? length : index); }
330  const uint8_t *GetData(void) const { return (IsEOF() ? NULL : data + (index / 8)); }
331  };
332 
333 class cTimeMs {
334 private:
335  uint64_t begin;
336 public:
337  cTimeMs(int Ms = 0);
341  static uint64_t Now(void);
342  void Set(int Ms = 0);
343  bool TimedOut(void) const;
344  uint64_t Elapsed(void) const;
345  };
346 
347 class cReadLine {
348 private:
349  size_t size;
350  char *buffer;
351 public:
352  cReadLine(void);
353  ~cReadLine();
354  char *Read(FILE *f);
355  };
356 
357 class cPoller {
358 private:
359  enum { MaxPollFiles = 16 };
360  pollfd pfd[MaxPollFiles];
362 public:
363  cPoller(int FileHandle = -1, bool Out = false);
364  bool Add(int FileHandle, bool Out);
365  bool Poll(int TimeoutMs = 0);
366  };
367 
368 class cReadDir {
369 private:
370  DIR *directory;
371  struct dirent *result;
372  union { // according to "The GNU C Library Reference Manual"
373  struct dirent d;
374  char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
375  } u;
376 public:
377  cReadDir(const char *Directory);
378  ~cReadDir();
379  bool Ok(void) { return directory != NULL; }
380  struct dirent *Next(void);
381  };
382 
383 class cFile {
384 private:
385  static bool files[];
386  static int maxFiles;
387  int f;
388 public:
389  cFile(void);
390  ~cFile();
391  operator int () { return f; }
392  bool Open(const char *FileName, int Flags, mode_t Mode = DEFFILEMODE);
393  bool Open(int FileDes);
394  void Close(void);
395  bool IsOpen(void) { return f >= 0; }
396  bool Ready(bool Wait = true);
397  static bool AnyFileReady(int FileDes = -1, int TimeoutMs = 1000);
398  static bool FileReady(int FileDes, int TimeoutMs = 1000);
399  static bool FileReadyForWriting(int FileDes, int TimeoutMs = 1000);
400  };
401 
402 class cSafeFile {
403 private:
404  FILE *f;
405  char *fileName;
406  char *tempName;
407 public:
408  cSafeFile(const char *FileName);
409  ~cSafeFile();
410  operator FILE* () { return f; }
411  bool Open(void);
412  bool Close(void);
413  };
414 
417 
419 private:
420  int fd;
421  off_t curpos;
422  off_t cachedstart;
423  off_t cachedend;
424  off_t begin;
425  off_t lastpos;
426  off_t ahead;
427  size_t readahead;
428  size_t written;
429  size_t totwritten;
430  int FadviseDrop(off_t Offset, off_t Len);
431 public:
432  cUnbufferedFile(void);
433  ~cUnbufferedFile();
434  int Open(const char *FileName, int Flags, mode_t Mode = DEFFILEMODE);
435  int Close(void);
436  void SetReadAhead(size_t ra);
437  off_t Seek(off_t Offset, int Whence);
438  ssize_t Read(void *Data, size_t Size);
439  ssize_t Write(const void *Data, size_t Size);
440  static cUnbufferedFile *Create(const char *FileName, int Flags, mode_t Mode = DEFFILEMODE);
441  };
442 
443 class cLockFile {
444 private:
445  char *fileName;
446  int f;
447 public:
448  cLockFile(const char *Directory);
449  ~cLockFile();
450  bool Lock(int WaitSeconds = 0);
451  void Unlock(void);
452  };
453 
454 class cListObject {
455 private:
456  cListObject *prev, *next;
457 public:
458  cListObject(void);
459  virtual ~cListObject();
460  virtual int Compare(const cListObject &ListObject) const { return 0; }
463  void Append(cListObject *Object);
464  void Insert(cListObject *Object);
465  void Unlink(void);
466  int Index(void) const;
467  cListObject *Prev(void) const { return prev; }
468  cListObject *Next(void) const { return next; }
469  };
470 
471 class cListBase {
472 protected:
473  cListObject *objects, *lastObject;
474  cListBase(void);
475  int count;
476 public:
477  virtual ~cListBase();
478  void Add(cListObject *Object, cListObject *After = NULL);
479  void Ins(cListObject *Object, cListObject *Before = NULL);
480  void Del(cListObject *Object, bool DeleteObject = true);
481  virtual void Move(int From, int To);
482  void Move(cListObject *From, cListObject *To);
483  virtual void Clear(void);
484  cListObject *Get(int Index) const;
485  int Count(void) const { return count; }
486  void Sort(void);
487  };
488 
489 template<class T> class cList : public cListBase {
490 public:
491  T *Get(int Index) const { return (T *)cListBase::Get(Index); }
492  T *First(void) const { return (T *)objects; }
493  T *Last(void) const { return (T *)lastObject; }
494  T *Prev(const T *object) const { return (T *)object->cListObject::Prev(); } // need to call cListObject's members to
495  T *Next(const T *object) const { return (T *)object->cListObject::Next(); } // avoid ambiguities in case of a "list of lists"
496  };
497 
498 template<class T> class cVector {
500 private:
501  mutable int allocated;
502  mutable int size;
503  mutable T *data;
504  cVector(const cVector &Vector) {} // don't copy...
505  cVector &operator=(const cVector &Vector) { return *this; } // ...or assign this!
506  void Realloc(int Index) const
507  {
508  if (++Index > allocated) {
509  data = (T *)realloc(data, Index * sizeof(T));
510  if (!data) {
511  esyslog("ERROR: out of memory - abort!");
512  abort();
513  }
514  for (int i = allocated; i < Index; i++)
515  data[i] = T(0);
516  allocated = Index;
517  }
518  }
519 public:
520  cVector(int Allocated = 10)
521  {
522  allocated = 0;
523  size = 0;
524  data = NULL;
525  Realloc(Allocated);
526  }
527  virtual ~cVector() { free(data); }
528  T& At(int Index) const
529  {
530  Realloc(Index);
531  if (Index >= size)
532  size = Index + 1;
533  return data[Index];
534  }
535  const T& operator[](int Index) const
536  {
537  return At(Index);
538  }
539  T& operator[](int Index)
540  {
541  return At(Index);
542  }
543  int IndexOf(const T &Data) // returns the index of Data, or -1 if not found
544  {
545  for (int i = 0; i < size; i++) {
546  if (data[i] == Data)
547  return i;
548  }
549  return -1;
550  }
551  int Size(void) const { return size; }
552  virtual void Insert(T Data, int Before = 0)
553  {
554  if (Before < size) {
555  Realloc(size);
556  memmove(&data[Before + 1], &data[Before], (size - Before) * sizeof(T));
557  size++;
558  data[Before] = Data;
559  }
560  else
561  Append(Data);
562  }
563  bool InsertUnique(T Data, int Before = 0)
564  {
565  if (IndexOf(Data) < 0) {
566  Insert(Data, Before);
567  return true;
568  }
569  return false;
570  }
571  virtual void Append(T Data)
572  {
573  if (size >= allocated)
574  Realloc(allocated * 3 / 2); // increase size by 50%
575  data[size++] = Data;
576  }
577  bool AppendUnique(T Data)
578  {
579  if (IndexOf(Data) < 0) {
580  Append(Data);
581  return true;
582  }
583  return false;
584  }
585  virtual void Remove(int Index)
586  {
587  if (Index < 0)
588  return; // prevents out-of-bounds access
589  if (Index < size - 1)
590  memmove(&data[Index], &data[Index + 1], (size - Index) * sizeof(T));
591  size--;
592  }
593  bool RemoveElement(const T &Data)
594  {
595  int i = IndexOf(Data);
596  if (i >= 0) {
597  Remove(i);
598  return true;
599  }
600  return false;
601  }
602  virtual void Clear(void)
603  {
604  for (int i = 0; i < size; i++)
605  data[i] = T(0);
606  size = 0;
607  }
608  void Sort(__compar_fn_t Compare)
609  {
610  qsort(data, size, sizeof(T), Compare);
611  }
612  };
613 
614 inline int CompareStrings(const void *a, const void *b)
615 {
616  return strcmp(*(const char **)a, *(const char **)b);
617 }
618 
619 inline int CompareStringsIgnoreCase(const void *a, const void *b)
620 {
621  return strcasecmp(*(const char **)a, *(const char **)b);
622 }
623 
624 class cStringList : public cVector<char *> {
625 public:
626  cStringList(int Allocated = 10): cVector<char *>(Allocated) {}
627  virtual ~cStringList();
628  int Find(const char *s) const;
629  void Sort(bool IgnoreCase = false)
630  {
631  if (IgnoreCase)
633  else
635  }
636  virtual void Clear(void);
637  };
638 
639 class cFileNameList : public cStringList {
640 public:
641  cFileNameList(const char *Directory = NULL, bool DirsOnly = false);
642  bool Load(const char *Directory, bool DirsOnly = false);
643  };
644 
645 class cHashObject : public cListObject {
646  friend class cHashBase;
647 private:
648  unsigned int id;
650 public:
651  cHashObject(cListObject *Object, unsigned int Id) { object = Object; id = Id; }
652  cListObject *Object(void) { return object; }
653  };
654 
655 class cHashBase {
656 private:
658  int size;
659  unsigned int hashfn(unsigned int Id) const { return Id % size; }
660 protected:
661  cHashBase(int Size);
662 public:
663  virtual ~cHashBase();
664  void Add(cListObject *Object, unsigned int Id);
665  void Del(cListObject *Object, unsigned int Id);
666  void Clear(void);
667  cListObject *Get(unsigned int Id) const;
668  cList<cHashObject> *GetList(unsigned int Id) const;
669  };
670 
671 #define HASHSIZE 512
672 
673 template<class T> class cHash : public cHashBase {
674 public:
675  cHash(int Size = HASHSIZE) : cHashBase(Size) {}
676  T *Get(unsigned int Id) const { return (T *)cHashBase::Get(Id); }
677 };
678 
679 #endif //__TOOLS_H
bool EntriesOnSameFileSystem(const char *File1, const char *File2)
Checks whether the given files are on the same file system.
Definition: tools.c:395
int sgn(T a)
Definition: tools.h:56
iconv_t cd
Definition: tools.h:143
unsigned char uchar
Definition: tools.h:30
int f
Definition: tools.h:446
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...
Definition: tools.c:338
ssize_t safe_read(int filedes, void *buffer, size_t size)
Definition: tools.c:53
cListObject * prev
Definition: tools.h:456
off_t curpos
Definition: tools.h:421
const char * operator*() const
Definition: tools.h:178
int64_t StrToNum(const char *s)
Converts the given string to a number.
Definition: tools.c:323
bool SpinUpDisk(const char *FileName)
Definition: tools.c:631
cListObject * Get(unsigned int Id) const
Definition: tools.c:2177
cString strescape(const char *s, const char *chars)
Definition: tools.c:254
bool RemoveElement(const T &Data)
Definition: tools.h:593
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.
Definition: tools.c:90
virtual ~cVector()
Definition: tools.h:527
size_t totwritten
Definition: tools.h:429
static char * systemCharacterTable
Definition: tools.h:146
bool DirectoryOk(const char *DirName, bool LogErrors=false)
Definition: tools.c:427
time_t LastModifiedTime(const char *FileName)
Definition: tools.c:669
const uint8_t * GetData(void) const
Definition: tools.h:330
static const char * SystemCharacterTable(void)
Definition: tools.h:164
char * strreplace(char *s, char c1, char c2)
Definition: tools.c:139
virtual void Append(T Data)
Definition: tools.h:571
void writechar(int filedes, char c)
Definition: tools.c:85
void SkipBit(void)
Definition: tools.h:325
char * compactchars(char *s, char c)
removes all occurrences of &#39;c&#39; from the beginning an end of &#39;s&#39; and replaces sequences of multiple &#39;c...
Definition: tools.c:230
cString TimeString(time_t t)
Converts the given time to a string of the form "hh:mm".
Definition: tools.c:1186
char * strcpyrealloc(char *dest, const char *src)
Definition: tools.c:114
ssize_t safe_write(int filedes, const void *buffer, size_t size)
Definition: tools.c:65
int allocated
< cVector may only be used for simple types, like int or pointers - not for class objects that alloca...
Definition: tools.h:501
#define esyslog(a...)
Definition: tools.h:34
uint Utf8CharGet(const char *s, int Length=0)
Returns the UTF-8 symbol at the beginning of the given string.
Definition: tools.c:771
T * Get(int Index) const
Definition: tools.h:491
char * tempName
Definition: tools.h:406
unsigned int id
Definition: tools.h:648
cString itoa(int n)
Definition: tools.c:388
cString WeekDayNameFull(int WeekDay)
Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a full day name.
Definition: tools.c:1124
T max(T a, T b)
Definition: tools.h:55
Definition: tools.h:489
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: tools.c:757
cHashObject(cListObject *Object, unsigned int Id)
Definition: tools.h:651
int size
Definition: tools.h:502
T & operator[](int Index)
Definition: tools.h:539
cString dtoa(double d, const char *Format="%f")
Converts the given double value to a string, making sure it uses a &#39;.
Definition: tools.c:378
DIR * directory
Definition: tools.h:370
int CompareStrings(const void *a, const void *b)
Definition: tools.h:614
off_t lastpos
Definition: tools.h:425
int Count(void) const
Definition: tools.h:485
cBitStream(const uint8_t *Data, int Length)
Definition: tools.h:317
int strcountchr(const char *s, char c)
returns the number of occurrences of &#39;c&#39; in &#39;s&#39;.
Definition: tools.c:189
T * Get(unsigned int Id) const
Definition: tools.h:676
T min(T a, T b)
Definition: tools.h:54
int IndexOf(const T &Data)
Definition: tools.h:543
cUnbufferedFile is used for large files that are mainly written or read in a streaming manner...
Definition: tools.h:418
cVector & operator=(const cVector &Vector)
Definition: tools.h:505
#define HASHSIZE
Definition: tools.h:671
T * data
Definition: tools.h:503
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.
Definition: tools.c:1251
int Length(void) const
Definition: tools.h:328
char * buffer
Definition: tools.h:350
uint64_t begin
Definition: tools.h:335
bool IsOpen(void)
Definition: tools.h:395
cList< cHashObject > ** hashTable
Definition: tools.h:657
virtual void Remove(int Index)
Definition: tools.h:585
T get_unaligned(T *p)
Definition: tools.h:72
T * Last(void) const
Definition: tools.h:493
Definition: tools.h:498
int f
Definition: tools.h:387
off_t begin
Definition: tools.h:424
bool IsEOF(void) const
Definition: tools.h:326
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
Definition: tools.h:460
T * Next(const T *object) const
Definition: tools.h:495
bool AppendUnique(T Data)
Definition: tools.h:577
void TouchFile(const char *FileName)
Definition: tools.c:663
virtual void Insert(T Data, int Before=0)
Definition: tools.h:552
T constrain(T v, T l, T h)
Definition: tools.h:60
int CompareStringsIgnoreCase(const void *a, const void *b)
Definition: tools.h:619
cString DayDateTime(time_t t=0)
Converts the given time to a string of the form "www dd.mm. hh:mm".
Definition: tools.c:1145
char * compactspace(char *s)
Definition: tools.c:213
int BCD2INT(int x)
Definition: tools.c:45
static int maxFiles
Definition: tools.h:386
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 co...
Definition: tools.c:845
cListObject * Next(void) const
Definition: tools.h:468
const uchar * data
Definition: tools.h:289
cListObject * Object(void)
Definition: tools.h:652
void swap(T &a, T &b)
Definition: tools.h:57
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 th...
Definition: tools.c:864
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 give...
Definition: tools.c:820
int length
Definition: tools.h:290
double atod(const char *s)
Converts the given string, which is a floating point number using a &#39;.
Definition: tools.c:357
Definition: tools.h:673
cListObject * object
Definition: tools.h:649
bool Ok(void)
Definition: tools.h:379
cVector(const cVector &Vector)
Definition: tools.h:504
void Realloc(int Index) const
Definition: tools.h:506
void Sort(__compar_fn_t Compare)
Definition: tools.h:608
int Size(void) const
Definition: tools.h:551
off_t ahead
Definition: tools.h:426
void SkipBits(int n)
Definition: tools.h:324
cString ShortDateString(time_t t)
Converts the given time to a string of the form "dd.mm.yy".
Definition: tools.c:1177
size_t readahead
Definition: tools.h:427
bool InsertUnique(T Data, int Before=0)
Definition: tools.h:563
unsigned int hashfn(unsigned int Id) const
Definition: tools.h:659
cString TimeToString(time_t t)
Converts the given time to a string of the form "www mmm dd hh:mm:ss yyyy".
Definition: tools.c:1156
cListObject * objects
Definition: tools.h:473
bool SetSystemCharacterTable(const char *CharacterTable)
Definition: si.c:330
static uint8_t * SetLength(uint8_t *Data, int Length)
Definition: ci.c:55
char * fileName
Definition: tools.h:405
int FreeDiskSpaceMB(const char *Directory, int *UsedMB=NULL)
Definition: tools.c:410
FILE * f
Definition: tools.h:404
cString AddDirectory(const char *DirName, const char *FileName)
Definition: tools.c:350
const char * strchrn(const char *s, char c, size_t n)
returns a pointer to the n&#39;th occurrence (counting from 1) of c in s, or NULL if no such character wa...
Definition: tools.c:176
void Reset(void)
Definition: tools.h:327
cString WeekDayName(int WeekDay)
Converts the given WeekDay (0=Sunday, 1=Monday, ...) to a three letter day name.
Definition: tools.c:1103
cHash(int Size=HASHSIZE)
Definition: tools.h:675
const T & operator[](int Index) const
Definition: tools.h:535
cListObject * Prev(void) const
Definition: tools.h:467
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 ...
Definition: tools.c:882
T * First(void) const
Definition: tools.h:492
int DirSizeMB(const char *DirName)
returns the total size of the files in the given directory, or -1 in case of an error ...
Definition: tools.c:585
const uint8_t * data
Definition: tools.h:313
char * stripspace(char *s)
Definition: tools.c:201
cListObject * Get(int Index) const
Definition: tools.c:2098
bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks=false)
Definition: tools.c:473
int maxResult
Definition: tools.h:291
struct dirent * result
Definition: tools.h:371
cString DateString(time_t t)
Converts the given time to a string of the form "www dd.mm.yyyy".
Definition: tools.c:1166
int SysLogLevel
Definition: tools.c:31
int numFileHandles
Definition: tools.h:361
size_t written
Definition: tools.h:428
bool endswith(const char *s, const char *p)
Definition: tools.c:286
bool MakeDirs(const char *FileName, bool IsDirectory=false)
Definition: tools.c:445
char * s
Definition: tools.h:170
void DELETENULL(T *&p)
Definition: tools.h:48
char * skipspace(const char *s)
Definition: tools.h:200
off_t cachedstart
Definition: tools.h:422
int count
Definition: tools.h:475
void Sort(bool IgnoreCase=false)
Definition: tools.h:629
~cBitStream()
Definition: tools.h:318
char * strn0cpy(char *dest, const char *src, size_t n)
Definition: tools.c:131
int size
Definition: tools.h:658
void put_unaligned(unsigned int v, T *p)
Definition: tools.h:78
bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis=false, const char *IgnoreFiles[]=NULL)
Removes all empty directories under the given directory DirName.
Definition: tools.c:531
Definition: tools.h:333
bool isempty(const char *s)
Definition: tools.c:297
char * result
Definition: tools.h:293
int Utf8StrLen(const char *s)
Returns the number of UTF-8 symbols formed by the given string of character bytes.
Definition: tools.c:833
bool isnumber(const char *s)
Definition: tools.c:312
char * result
Definition: tools.h:144
bool DoubleEqual(double a, double b)
Definition: tools.h:87
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...
Definition: tools.c:786
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: tools.c:617
int Index(void) const
Definition: tools.h:329
int index
Definition: tools.h:315
T & At(int Index) const
Definition: tools.h:528
bool startswith(const char *s, const char *p)
Definition: tools.c:277
virtual void Clear(void)
Definition: tools.h:602
Definition: tools.h:357
int length
Definition: tools.h:314
size_t size
Definition: tools.h:349
off_t cachedend
Definition: tools.h:423
T * Prev(const T *object) const
Definition: tools.h:494
char * fileName
Definition: tools.h:445
cStringList(int Allocated=10)
Definition: tools.h:626
Definition: tools.h:383
cVector(int Allocated=10)
Definition: tools.h:520
Definition: tools.h:168
static const char * b64
Definition: tools.h:294
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&#39;t exist) ...
Definition: tools.c:677
void syslog_with_tid(int priority, const char *format,...) __attribute__((format(printf
size_t length
Definition: tools.h:145
int numdigits(int n)
Definition: tools.c:302