33 #define MAXSYSLOGBUF 256
41 vsyslog(priority, fmt, ap);
53 ssize_t
safe_read(
int filedes,
void *buffer,
size_t size)
56 ssize_t p = read(filedes, buffer, size);
57 if (p < 0 && errno == EINTR) {
58 dsyslog(
"EINTR while reading from file handle %d - retrying", filedes);
65 ssize_t
safe_write(
int filedes,
const void *buffer,
size_t size)
68 ssize_t written = size;
69 const unsigned char *ptr = (
const unsigned char *)buffer;
71 p = write(filedes, ptr, size);
74 dsyslog(
"EINTR while writing to file handle %d - retrying", filedes);
82 return p < 0 ? p : written;
94 int w = write(fd, Data + written, Length);
103 Poller.
Poll(RetryMs);
104 if (TimeoutMs > 0 && (TimeoutMs -= t.
Elapsed()) <= 0)
117 int l =
max(dest ? strlen(dest) : 0, strlen(src)) + 1;
118 dest = (
char *)realloc(dest, l);
122 esyslog(
"ERROR: out of memory");
131 char *
strn0cpy(
char *dest,
const char *src,
size_t n)
134 for ( ; --n && (*dest = *src) != 0; dest++, src++) ;
154 if (!s || !s1 || !s2)
156 char *p = strstr(s, s1);
163 if (
char *NewBuffer = (
char *)realloc(s, l + l2 - l1 + 1))
166 esyslog(
"ERROR: out of memory");
172 memmove(sof + l2, sof + l1, l - of - l1 + 1);
173 strncpy(sof, s2, l2);
178 const char *
strchrn(
const char *s,
char c,
size_t n)
184 if (*s == c && --n == 0)
206 for (
char *p = s + strlen(s) - 1; p >= s; p--) {
223 memmove(p + 1, q, strlen(q) + 1);
227 memmove(s, t, strlen(t) + 1);
243 else if (t != s && n == 0) {
262 if (strchr(chars, *p)) {
264 buffer =
MALLOC(
char, 2 * strlen(s) + 1);
265 t = buffer + (p - s);
266 s = strcpy(buffer, s);
282 int l = strlen(name);
284 while (
const char *p = strstr(t, name)) {
286 if (p == s || *(p - 1) <=
' ') {
306 memmove(s, s + n, l - n + 1);
324 const char *se = s + strlen(s) - 1;
325 const char *pe = p + strlen(p) - 1;
327 if (*pe-- != *se-- || (se < s && pe >= p))
362 int64_t n = strtoll(s, &t, 10);
378 if (strcmp(*a, s) == 0)
388 if (*FileName ==
'/')
390 return cString::sprintf(
"%s/%s", DirName && *DirName ? DirName :
".", FileName);
393 #define DECIMAL_POINT_C '.'
397 static lconv *loc = localeconv();
399 char buf[strlen(s) + 1];
403 *p = *loc->decimal_point;
418 static lconv *loc = localeconv();
420 snprintf(buf,
sizeof(buf), Format, d);
429 snprintf(buf,
sizeof(buf),
"%d", n);
436 if (stat(File1, &st) == 0) {
437 dev_t dev1 = st.st_dev;
438 if (stat(File2, &st) == 0)
439 return st.st_dev == dev1;
453 struct statfs statFs;
454 if (statfs(Directory, &statFs) == 0) {
455 double blocksPerMeg = 1024.0 * 1024.0 / statFs.f_bsize;
457 *UsedMB = int((statFs.f_blocks - statFs.f_bfree) / blocksPerMeg);
458 Free = int(statFs.f_bavail / blocksPerMeg);
468 if (stat(DirName, &ds) == 0) {
469 if (S_ISDIR(ds.st_mode)) {
470 if (access(DirName, R_OK | W_OK | X_OK) == 0)
473 esyslog(
"ERROR: can't access %s", DirName);
476 esyslog(
"ERROR: %s is not a directory", DirName);
483 bool MakeDirs(
const char *FileName,
bool IsDirectory)
486 char *s = strdup(FileName);
490 while ((p = strchr(p,
'/')) != NULL || IsDirectory) {
494 if (stat(s, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
495 dsyslog(
"creating directory %s", s);
496 if (mkdir(s, ACCESSPERMS) == -1) {
514 if (stat(FileName, &st) == 0) {
515 if (S_ISDIR(st.st_mode)) {
519 while ((e = d.
Next()) != NULL) {
521 if (FollowSymlinks) {
523 if (lstat(buffer, &st2) == 0) {
524 if (S_ISLNK(st2.st_mode)) {
525 int size = st2.st_size + 1;
526 char *l =
MALLOC(
char, size);
527 int n = readlink(buffer, l, size - 1);
541 else if (errno != ENOENT) {
546 dsyslog(
"removing %s", *buffer);
547 if (remove(buffer) < 0)
556 dsyslog(
"removing %s", FileName);
557 if (remove(FileName) < 0) {
562 else if (errno != ENOENT) {
571 bool HasIgnoredFiles =
false;
576 while ((e = d.
Next()) != NULL) {
577 if (strcmp(e->d_name,
"lost+found")) {
580 if (stat(buffer, &st) == 0) {
581 if (S_ISDIR(st.st_mode)) {
585 else if (RemoveThis && IgnoreFiles &&
StrInArray(IgnoreFiles, e->d_name))
586 HasIgnoredFiles =
true;
596 if (RemoveThis && empty) {
597 if (HasIgnoredFiles) {
598 while (*IgnoreFiles) {
600 if (access(buffer, F_OK) == 0) {
601 dsyslog(
"removing %s", *buffer);
602 if (remove(buffer) < 0) {
610 dsyslog(
"removing %s", DirName);
611 if (remove(DirName) < 0) {
629 while (size >= 0 && (e = d.
Next()) != NULL) {
632 if (stat(buffer, &st) == 0) {
633 if (S_ISDIR(st.st_mode)) {
650 else if (errno != ENOENT)
659 char *TargetName = canonicalize_file_name(FileName);
662 TargetName = strdup(FileName);
671 for (
int n = 0; n < 10; n++) {
677 if (access(buf, F_OK) != 0) {
679 gettimeofday(&tp1, NULL);
680 int f = open(buf, O_WRONLY | O_CREAT, DEFFILEMODE);
683 if (fdatasync(f) < 0)
687 gettimeofday(&tp2, NULL);
688 double seconds = (((
long long)tp2.tv_sec * 1000000 + tp2.tv_usec) - ((
long long)tp1.tv_sec * 1000000 + tp1.tv_usec)) / 1000000.0;
690 dsyslog(
"SpinUpDisk took %.2f seconds", seconds);
697 esyslog(
"ERROR: SpinUpDisk failed");
703 if (utime(FileName, NULL) == -1 && errno != ENOENT)
710 if (stat(FileName, &fs) == 0)
718 if (stat(FileName, &fs) == 0)
735 #if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
736 #define MIN_RESOLUTION 5
737 static bool initialized =
false;
738 static bool monotonic =
false;
742 if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
743 long Resolution = tp.tv_nsec;
745 if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
746 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
747 dsyslog(
"cTimeMs: using monotonic clock (resolution is %ld ns)", Resolution);
751 esyslog(
"cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
754 dsyslog(
"cTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec);
757 esyslog(
"cTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
761 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
762 return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
763 esyslog(
"cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
768 # warning Posix monotonic clock not available
771 if (gettimeofday(&t, NULL) == 0)
772 return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;
799 #define MT(s, m, v) ((*(s) & (m)) == (v))
800 if (
MT(s, 0xE0, 0xC0) &&
MT(s + 1, 0xC0, 0x80))
802 if (
MT(s, 0xF0, 0xE0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80))
804 if (
MT(s, 0xF8, 0xF0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80) &&
MT(s + 3, 0xC0, 0x80))
816 case 2:
return ((*s & 0x1F) << 6) | (*(s + 1) & 0x3F);
817 case 3:
return ((*s & 0x0F) << 12) | ((*(s + 1) & 0x3F) << 6) | (*(s + 2) & 0x3F);
818 case 4:
return ((*s & 0x07) << 18) | ((*(s + 1) & 0x3F) << 12) | ((*(s + 2) & 0x3F) << 6) | (*(s + 3) & 0x3F);
833 *s++ = ((c >> 6) & 0x1F) | 0xC0;
834 *s = (c & 0x3F) | 0x80;
840 *s++ = ((c >> 12) & 0x0F) | 0xE0;
841 *s++ = ((c >> 6) & 0x3F) | 0x80;
842 *s = (c & 0x3F) | 0x80;
848 *s++ = ((c >> 18) & 0x07) | 0xF0;
849 *s++ = ((c >> 12) & 0x3F) | 0x80;
850 *s++ = ((c >> 6) & 0x3F) | 0x80;
851 *s = (c & 0x3F) | 0x80;
863 while (*s && Symbols--) {
905 while (*s && --Size > 0) {
907 *a++ = (
uchar)(*s++);
924 while (*a && NumChars < Size) {
925 if (Max >= 0 && NumSyms++ >= Max)
933 if (NumChars + sl <= Size) {
958 cd = iconv_open(ToCode, FromCode);
966 if (
cd != (iconv_t)-1)
974 if (!strcasestr(CharacterTable,
"UTF-8")) {
977 for (
int i = 0; i < 128; i++)
981 const char *s = csc.
Convert(buf);
995 if (
cd != (iconv_t)-1 && From && *From) {
996 char *FromPtr = (
char *)From;
997 size_t FromLength = strlen(From);
1000 int NewLength =
max(
length, FromLength * 2);
1001 if (
char *NewBuffer = (
char *)realloc(
result, NewLength)) {
1006 esyslog(
"ERROR: out of memory");
1015 char *Converted = ToPtr;
1016 while (FromLength > 0) {
1017 if (iconv(
cd, &FromPtr, &FromLength, &ToPtr, &ToLength) ==
size_t(-1)) {
1018 if (errno == E2BIG || errno == EILSEQ && ToLength < 1) {
1022 size_t d = ToPtr -
result;
1024 int NewLength =
length + r;
1025 if (
char *NewBuffer = (
char *)realloc(
result, NewLength)) {
1027 Converted =
result = NewBuffer;
1030 esyslog(
"ERROR: out of memory");
1036 if (errno == EILSEQ) {
1043 else if (errno != E2BIG)
1057 s = TakePointer ? (
char *)S : S ? strdup(S) : NULL;
1076 s = String.
s ? strdup(String.
s) : NULL;
1086 if (
this == &String)
1089 s = String.
s ? strdup(String.
s) : NULL;
1098 s = String ? strdup(String) : NULL;
1105 int l1 =
s ? strlen(
s) : 0;
1106 int l2 = strlen(String);
1107 if (
char *p = (
char *)realloc(
s, l1 + l2 + 1)) {
1109 strcpy(
s + l1, String);
1112 esyslog(
"ERROR: out of memory");
1122 if (Index >= 0 && Index < l)
1138 if (!fmt || vasprintf(&buffer, fmt, ap) < 0) {
1139 esyslog(
"error in vasprintf('%s', ...)", fmt);
1140 buffer = strdup(
"???");
1149 if (!fmt || vasprintf(&buffer, fmt, ap) < 0) {
1150 esyslog(
"error in vasprintf('%s', ...)", fmt);
1151 buffer = strdup(
"???");
1159 WeekDay = WeekDay == 0 ? 6 : WeekDay - 1;
1160 if (0 <= WeekDay && WeekDay <= 6) {
1162 const char *day =
tr(
"MonTueWedThuFriSatSun");
1174 return WeekDayName(localtime_r(&t, &tm_r)->tm_wday);
1179 WeekDay = WeekDay == 0 ? 6 : WeekDay - 1;
1181 case 0:
return tr(
"Monday");
1182 case 1:
return tr(
"Tuesday");
1183 case 2:
return tr(
"Wednesday");
1184 case 3:
return tr(
"Thursday");
1185 case 4:
return tr(
"Friday");
1186 case 5:
return tr(
"Saturday");
1187 case 6:
return tr(
"Sunday");
1188 default:
return "???";
1204 tm *tm = localtime_r(&t, &tm_r);
1205 snprintf(buffer,
sizeof(buffer),
"%s %02d.%02d. %02d:%02d", *
WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min);
1212 if (ctime_r(&t, buffer)) {
1213 buffer[strlen(buffer) - 1] = 0;
1223 tm *tm = localtime_r(&t, &tm_r);
1226 strftime(p,
sizeof(buf) - (p - buf),
"%d.%m.%Y", tm);
1234 tm *tm = localtime_r(&t, &tm_r);
1235 strftime(buf,
sizeof(buf),
"%d.%m.%y", tm);
1243 strftime(buf,
sizeof(buf),
"%R", localtime_r(&t, &tm_r));
1249 #define JPEGCOMPRESSMEM 500000
1269 int Used = jcd->
size;
1271 if (
uchar *NewBuffer = (
uchar *)realloc(jcd->
mem, NewSize)) {
1272 jcd->
size = NewSize;
1273 jcd->
mem = NewBuffer;
1276 esyslog(
"ERROR: out of memory");
1280 cinfo->dest->next_output_byte = jcd->
mem + Used;
1281 cinfo->dest->free_in_buffer = jcd->
size - Used;
1292 int Used = cinfo->dest->next_output_byte - jcd->
mem;
1293 if (Used < jcd->size) {
1296 jcd->
mem = NewBuffer;
1299 esyslog(
"ERROR: out of memory");
1308 else if (Quality > 100)
1311 jpeg_destination_mgr jdm;
1317 struct jpeg_compress_struct cinfo;
1318 struct jpeg_error_mgr jerr;
1319 cinfo.err = jpeg_std_error(&jerr);
1320 jpeg_create_compress(&cinfo);
1323 cinfo.client_data = &jcd;
1324 cinfo.image_width = Width;
1325 cinfo.image_height = Height;
1326 cinfo.input_components = 3;
1327 cinfo.in_color_space = JCS_RGB;
1329 jpeg_set_defaults(&cinfo);
1330 jpeg_set_quality(&cinfo, Quality, TRUE);
1331 jpeg_start_compress(&cinfo, TRUE);
1334 JSAMPROW rp[Height];
1335 for (
int k = 0; k < Height; k++)
1336 rp[k] = &Mem[rs * k];
1337 jpeg_write_scanlines(&cinfo, rp, Height);
1338 jpeg_finish_compress(&cinfo);
1339 jpeg_destroy_compress(&cinfo);
1349 static char buffer[HOST_NAME_MAX] =
"";
1351 if (gethostname(buffer,
sizeof(buffer)) < 0) {
1353 strcpy(buffer,
"vdr");
1361 const char *
cBase64Encoder::b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1384 c |= (
data[
i] >> 4) & 0x0F;
1387 c = (
data[
i] << 2) & 0x3F;
1389 c |= (
data[
i] >> 6) & 0x03;
1488 Add(FileHandle, Out);
1493 if (FileHandle >= 0) {
1495 if (
pfd[i].fd == FileHandle &&
pfd[i].events == (Out ? POLLOUT : POLLIN))
1505 esyslog(
"ERROR: too many file handles in cPoller");
1512 if (FileHandle >= 0) {
1514 if (
pfd[i].fd == FileHandle &&
pfd[i].events == (Out ? POLLOUT : POLLIN)) {
1549 #if !__GLIBC_PREREQ(2, 24)
1554 if (strcmp(
result->d_name,
".") && strcmp(
result->d_name,
".."))
1570 for (
int i = 0; i < Size(); i++) {
1571 if (!strcmp(s, At(i)))
1579 for (
int i = 0; i < Size(); i++)
1589 Load(Directory, DirsOnly);
1599 while ((e =
d.Next()) != NULL) {
1602 if (stat(
AddDirectory(Directory, e->d_name), &ds) == 0) {
1603 if (!S_ISDIR(ds.st_mode))
1607 Append(strdup(e->d_name));
1636 return Open(open(FileName, Flags, Mode));
1637 esyslog(
"ERROR: attempt to re-open %s", FileName);
1647 if (f < FD_SETSIZE) {
1653 esyslog(
"ERROR: file descriptor %d already in files[]", f);
1657 esyslog(
"ERROR: file descriptor %d is larger than FD_SETSIZE (%d)", f, FD_SETSIZE);
1661 esyslog(
"ERROR: attempt to re-open file descriptor %d", FileDes);
1677 return f >= 0 && AnyFileReady(f, Wait ? 1000 : 0);
1684 for (
int i = 0; i < maxFiles; i++) {
1688 if (0 <= FileDes && FileDes < FD_SETSIZE && !files[FileDes])
1689 FD_SET(FileDes, &set);
1692 struct timeval timeout;
1693 timeout.tv_sec = TimeoutMs / 1000;
1694 timeout.tv_usec = (TimeoutMs % 1000) * 1000;
1695 return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && (FileDes < 0 || FD_ISSET(FileDes, &set));
1701 struct timeval timeout;
1703 FD_SET(FileDes, &set);
1704 if (TimeoutMs >= 0) {
1705 if (TimeoutMs < 100)
1707 timeout.tv_sec = TimeoutMs / 1000;
1708 timeout.tv_usec = (TimeoutMs % 1000) * 1000;
1710 return select(FD_SETSIZE, &set, NULL, NULL, (TimeoutMs >= 0) ? &timeout : NULL) > 0 && FD_ISSET(FileDes, &set);
1716 struct timeval timeout;
1718 FD_SET(FileDes, &set);
1719 if (TimeoutMs < 100)
1722 timeout.tv_usec = TimeoutMs * 1000;
1723 return select(FD_SETSIZE, NULL, &set, NULL, &timeout) > 0 && FD_ISSET(FileDes, &set);
1732 tempName = fileName ?
MALLOC(
char, strlen(fileName) + 5) : NULL;
1734 strcat(strcpy(tempName, fileName),
".$$$");
1748 if (!f && fileName && tempName) {
1749 f = fopen(tempName,
"w");
1760 if (ferror(f) != 0) {
1766 if (fclose(f) < 0) {
1771 if (
result && rename(tempName, fileName) < 0) {
1783 #ifndef USE_FADVISE_READ
1784 #define USE_FADVISE_READ 0
1786 #ifndef USE_FADVISE_WRITE
1787 #define USE_FADVISE_WRITE 1
1790 #define WRITE_BUFFER KILOBYTE(800)
1805 fd = open(FileName, Flags, Mode);
1807 #if USE_FADVISE_READ || USE_FADVISE_WRITE
1808 begin = lastpos = ahead = 0;
1815 posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);
1823 #if USE_FADVISE_READ || USE_FADVISE_WRITE
1826 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
1830 return close(OldFd);
1841 #define FADVGRAN KILOBYTE(4)
1842 #define READCHUNK MEGABYTE(8)
1852 return posix_fadvise(fd, Offset - (
FADVGRAN - 1), Len + (
FADVGRAN - 1) * 2, POSIX_FADV_DONTNEED);
1857 if (Whence == SEEK_SET && Offset == curpos)
1859 curpos = lseek(fd, Offset, Whence);
1866 #if USE_FADVISE_READ
1867 off_t jumped = curpos-lastpos;
1868 if ((cachedstart < cachedend) && (curpos < cachedstart || curpos > cachedend)) {
1870 FadviseDrop(cachedstart, cachedend-cachedstart);
1871 cachedstart = curpos;
1874 cachedstart =
min(cachedstart, curpos);
1876 ssize_t bytesRead =
safe_read(fd, Data, Size);
1877 if (bytesRead > 0) {
1878 curpos += bytesRead;
1879 #if USE_FADVISE_READ
1880 cachedend =
max(cachedend, curpos);
1884 if (jumped >= 0 && jumped <= (off_t)readahead) {
1888 if (ahead - curpos < (off_t)(readahead / 2)) {
1889 posix_fadvise(fd, curpos, readahead, POSIX_FADV_WILLNEED);
1890 ahead = curpos + readahead;
1891 cachedend =
max(cachedend, ahead);
1893 if (readahead < Size * 32) {
1894 readahead = Size * 32;
1901 #if USE_FADVISE_READ
1902 if (cachedstart < cachedend) {
1903 if (curpos - cachedstart >
READCHUNK * 2) {
1905 FadviseDrop(cachedstart, curpos -
READCHUNK - cachedstart);
1908 else if (cachedend > ahead && cachedend - curpos >
READCHUNK * 2) {
1924 ssize_t bytesWritten =
safe_write(fd, Data, Size);
1925 #if USE_FADVISE_WRITE
1926 if (bytesWritten > 0) {
1927 begin =
min(begin, curpos);
1928 curpos += bytesWritten;
1929 written += bytesWritten;
1930 lastpos =
max(lastpos, curpos);
1932 if (lastpos > begin) {
1942 posix_fadvise(fd, begin - headdrop, lastpos - begin + headdrop, POSIX_FADV_DONTNEED);
1944 begin = lastpos = curpos;
1945 totwritten += written;
1960 off_t headdrop =
min(off_t(curpos - totwritten), off_t(totwritten * 2));
1961 posix_fadvise(fd, curpos - totwritten - headdrop, totwritten + headdrop, POSIX_FADV_DONTNEED);
1967 return bytesWritten;
1975 if (File->
Open(FileName, Flags, Mode) < 0) {
1984 #define LOCKFILENAME ".lock-vdr"
1985 #define LOCKFILESTALETIME 600
2003 if (f < 0 && fileName) {
2004 time_t Timeout = time(NULL) + WaitSeconds;
2006 f = open(fileName, O_WRONLY | O_CREAT | O_EXCL, DEFFILEMODE);
2008 if (errno == EEXIST) {
2010 if (stat(fileName, &fs) == 0) {
2012 esyslog(
"ERROR: removing stale lock file '%s'", fileName);
2013 if (remove(fileName) < 0) {
2020 else if (errno != ENOENT) {
2032 }
while (f < 0 && time(NULL) < Timeout);
2060 Object->
prev =
this;
2066 Object->
next =
this;
2092 #define LIST_GARBAGE_COLLECTOR_TIMEOUT 5
2105 esyslog(
"ERROR: ListGarbageCollector destroyed without prior Purge()!");
2111 Object->
next = objects;
2113 lastPut = time(NULL);
2126 objects = Object->next;
2136 :stateLock(NeedsLocking)
2154 esyslog(
"ERROR: cListBase::Lock() called for a list that doesn't require locking");
2176 if (Before && Before !=
objects) {
2213 if (From && To && From != To) {
2270 while (
object && Index-- > 0)
2271 object =
object->
Next();
2290 while (
object && i < n) {
2292 object =
object->
Next();
2296 for (i = 0; i < n; i++) {
2320 if (
size < NewSize) {
2327 esyslog(
"ERROR: out of memory");
2359 unsigned int hash =
hashfn(Id);
2370 if (hob->object == Object) {
2380 for (
int i = 0; i <
size; i++) {
cBase64Encoder(const uchar *Data, int Length, int MaxResult=64)
Sets up a new base 64 encoder for the given Data, with the given Length.
const char * NextLine(void)
Returns the next line of encoded data (terminated by '\0'), or NULL if there is no more encoded data.
bool SetLength(int Length)
cCharSetConv(const char *FromCode=NULL, const char *ToCode=NULL)
Sets up a character set converter to convert from FromCode to ToCode.
static void SetSystemCharacterTable(const char *CharacterTable)
static char * systemCharacterTable
static const char * SystemCharacterTable(void)
const char * Convert(const char *From, char *To=NULL, size_t ToLength=0)
Converts the given Text from FromCode to ToCode (as set in the constructor).
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
cDynamicBuffer(int InitialSize=1024)
bool Realloc(int NewSize)
void Append(const uchar *Data, int Length)
bool Load(const char *Directory, bool DirsOnly=false)
cFileNameList(const char *Directory=NULL, bool DirsOnly=false)
static bool FileReadyForWriting(int FileDes, int TimeoutMs=1000)
static bool FileReady(int FileDes, int TimeoutMs=1000)
static bool AnyFileReady(int FileDes=-1, int TimeoutMs=1000)
bool Ready(bool Wait=true)
bool Open(const char *FileName, int Flags, mode_t Mode=DEFFILEMODE)
void Del(cListObject *Object, unsigned int Id)
cListObject * Get(unsigned int Id) const
cList< cHashObject > ** hashTable
cList< cHashObject > * GetList(unsigned int Id) const
cHashBase(int Size, bool OwnObjects)
Creates a new hash of the given Size.
void Add(cListObject *Object, unsigned int Id)
unsigned int hashfn(unsigned int Id) const
void Ins(cListObject *Object, cListObject *Before=NULL)
bool Contains(const cListObject *Object) const
If a pointer to an object contained in this list has been obtained while holding a lock,...
void Del(cListObject *Object, bool DeleteObject=true)
virtual void Move(int From, int To)
void SetExplicitModify(void)
If you have obtained a write lock on this list, and you don't want it to be automatically marked as m...
void SetModified(void)
Unconditionally marks this list as modified.
bool Lock(cStateKey &StateKey, bool Write=false, int TimeoutMs=0) const
Tries to get a lock on this list and returns true if successful.
const char * needsLocking
cListBase(const char *NeedsLocking=NULL)
const cListObject * Get(int Index) const
void Add(cListObject *Object, cListObject *After=NULL)
void Purge(bool Force=false)
cListGarbageCollector(void)
void Put(cListObject *Object)
cListObject * Prev(void) const
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
cListObject * Next(void) const
void Insert(cListObject *Object)
void Append(cListObject *Object)
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
bool Lock(int WaitSeconds=0)
cLockFile(const char *Directory)
cPoller(int FileHandle=-1, bool Out=false)
bool Add(int FileHandle, bool Out)
bool Poll(int TimeoutMs=0)
void Del(int FileHandle, bool Out)
cReadDir(const char *Directory)
struct dirent * Next(void)
cSafeFile(const char *FileName)
void SetExplicitModify(void)
If you have obtained a write lock on this lock, and you don't want its state to be automatically incr...
void SetModified(void)
Sets this lock to have its state incremented when the current write lock state key is removed.
bool Lock(cStateKey &StateKey, bool Write=false, int TimeoutMs=0)
Tries to get a lock and returns true if successful.
int Find(const char *s) const
cString & CompactChars(char c)
Compact any sequence of characters 'c' to a single character, and strip all of them from the beginnin...
static cString static cString vsprintf(const char *fmt, va_list &ap)
cString(const char *S=NULL, bool TakePointer=false)
static cString sprintf(const char *fmt,...) __attribute__((format(printf
cString & operator=(const cString &String)
cString & Append(const char *String)
cString & Truncate(int Index)
Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string).
static tThreadId ThreadId(void)
uint64_t Elapsed(void) const
void Set(int Ms=0)
Sets the timer.
bool TimedOut(void) const
cTimeMs(int Ms=0)
Creates a timer with ms resolution and an initial timeout of Ms.
static uint64_t Now(void)
cUnbufferedFile is used for large files that are mainly written or read in a streaming manner,...
static cUnbufferedFile * Create(const char *FileName, int Flags, mode_t Mode=DEFFILEMODE)
void SetReadAhead(size_t ra)
ssize_t Write(const void *Data, size_t Size)
int Open(const char *FileName, int Flags, mode_t Mode=DEFFILEMODE)
ssize_t Read(void *Data, size_t Size)
int FadviseDrop(off_t Offset, off_t Len)
off_t Seek(off_t Offset, int Whence)