33#define MAXSYSLOGBUF 256
41 vsyslog(priority, fmt, ap);
53ssize_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);
65ssize_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");
131char *
strn0cpy(
char *dest,
const char *src,
size_t n)
134 for ( ; --n && (*dest = *src) != 0; dest++, src++) ;
154 if (!s || !s1 || !s2 || strcmp(s1, s2) == 0)
157 if (
char *p = strstr(s, s1)) {
164 if (
char *NewBuffer = (
char *)realloc(s, l + l2 - l1 + 1))
167 esyslog(
"ERROR: out of memory");
173 memmove(sof + l2, sof + l1, l - of - l1 + 1);
178 }
while (p = strstr(q, s1));
183const char *
strchrn(
const char *s,
char c,
size_t n)
189 if (*s == c && --n == 0)
210 const char *p = strrchr(s, 0);
212 if (*p == c && --n == 0)
220 const char *p = strrchr(s, c);
221 return p ? p + 1 : s;
227 for (
char *p = s + strlen(s) - 1; p >= s; p--) {
244 memmove(p + 1, q, strlen(q) + 1);
248 memmove(s, t, strlen(t) + 1);
264 else if (t != s && n == 0) {
283 if (strchr(chars, *p)) {
285 buffer =
MALLOC(
char, 2 * strlen(s) + 1);
286 t = buffer + (p - s);
287 s = strcpy(buffer, s);
303 int l = strlen(name);
305 while (
const char *p = strstr(t, name)) {
307 if (p == s || *(p - 1) <=
' ') {
327 memmove(s, s + n, l - n + 1);
345 const char *se = s + strlen(s) - 1;
346 const char *pe = p + strlen(p) - 1;
348 if (*pe-- != *se-- || (se < s && pe >= p))
383 int64_t n = strtoll(s, &t, 10);
399 if (strcmp(*a, s) == 0)
409 if (*FileName ==
'/')
411 return cString::sprintf(
"%s/%s", DirName && *DirName ? DirName :
".", FileName);
414#define DECIMAL_POINT_C '.'
418 static lconv *loc = localeconv();
420 char buf[strlen(s) + 1];
424 *p = *loc->decimal_point;
439 static lconv *loc = localeconv();
441 snprintf(buf,
sizeof(buf), Format, d);
450 snprintf(buf,
sizeof(buf),
"%d", n);
457 if (stat(File1, &st) == 0) {
458 dev_t dev1 = st.st_dev;
459 if (stat(File2, &st) == 0)
460 return st.st_dev == dev1;
474 struct statfs statFs;
475 if (statfs(Directory, &statFs) == 0) {
476 double blocksPerMeg = 1024.0 * 1024.0 / statFs.f_bsize;
478 *UsedMB = int((statFs.f_blocks - statFs.f_bfree) / blocksPerMeg);
479 Free = int(statFs.f_bavail / blocksPerMeg);
489 if (stat(DirName, &ds) == 0) {
490 if (S_ISDIR(ds.st_mode)) {
491 if (access(DirName, R_OK | W_OK | X_OK) == 0)
494 esyslog(
"ERROR: can't access %s", DirName);
497 esyslog(
"ERROR: %s is not a directory", DirName);
504bool MakeDirs(
const char *FileName,
bool IsDirectory)
507 char *s = strdup(FileName);
511 while ((p = strchr(p,
'/')) != NULL || IsDirectory) {
515 if (stat(s, &fs) != 0 || !S_ISDIR(fs.st_mode)) {
516 dsyslog(
"creating directory %s", s);
517 if (mkdir(s, ACCESSPERMS) == -1) {
535 if (stat(FileName, &st) == 0) {
536 if (S_ISDIR(st.st_mode)) {
540 while ((e = d.
Next()) != NULL) {
542 if (FollowSymlinks) {
544 if (lstat(buffer, &st2) == 0) {
545 if (S_ISLNK(st2.st_mode)) {
546 int size = st2.st_size + 1;
547 char *l =
MALLOC(
char, size);
548 int n = readlink(buffer, l, size - 1);
562 else if (errno != ENOENT) {
567 dsyslog(
"removing %s", *buffer);
568 if (remove(buffer) < 0)
577 dsyslog(
"removing %s", FileName);
578 if (remove(FileName) < 0) {
583 else if (errno != ENOENT) {
592 bool HasIgnoredFiles =
false;
597 while ((e = d.
Next()) != NULL) {
598 if (strcmp(e->d_name,
"lost+found")) {
601 if (stat(buffer, &st) == 0) {
602 if (S_ISDIR(st.st_mode)) {
606 else if (RemoveThis && IgnoreFiles &&
StrInArray(IgnoreFiles, e->d_name))
607 HasIgnoredFiles =
true;
617 if (RemoveThis && empty) {
618 if (HasIgnoredFiles) {
619 while (*IgnoreFiles) {
621 if (access(buffer, F_OK) == 0) {
622 dsyslog(
"removing %s", *buffer);
623 if (remove(buffer) < 0) {
631 dsyslog(
"removing %s", DirName);
632 if (remove(DirName) < 0) {
650 while (size >= 0 && (e = d.
Next()) != NULL) {
653 if (stat(buffer, &st) == 0) {
654 if (S_ISDIR(st.st_mode)) {
671 else if (errno != ENOENT)
680 char *TargetName = canonicalize_file_name(FileName);
683 TargetName = strdup(FileName);
692 for (
int n = 0; n < 10; n++) {
698 if (access(buf, F_OK) != 0) {
700 gettimeofday(&tp1, NULL);
701 int f = open(buf, O_WRONLY | O_CREAT, DEFFILEMODE);
704 if (fdatasync(f) < 0)
708 gettimeofday(&tp2, NULL);
709 double seconds = (((
long long)tp2.tv_sec * 1000000 + tp2.tv_usec) - ((
long long)tp1.tv_sec * 1000000 + tp1.tv_usec)) / 1000000.0;
711 dsyslog(
"SpinUpDisk took %.2f seconds", seconds);
718 esyslog(
"ERROR: SpinUpDisk failed");
724 if (utime(FileName, NULL) == -1 && errno != ENOENT)
731 if (stat(FileName, &fs) == 0)
739 if (stat(FileName, &fs) == 0)
756#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
757#define MIN_RESOLUTION 5
758 static bool initialized =
false;
759 static bool monotonic =
false;
763 if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
764 long Resolution = tp.tv_nsec;
766 if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
767 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
768 dsyslog(
"cTimeMs: using monotonic clock (resolution is %ld ns)", Resolution);
772 esyslog(
"cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
775 dsyslog(
"cTimeMs: not using monotonic clock - resolution is too bad (%jd s %ld ns)", intmax_t(tp.tv_sec), tp.tv_nsec);
778 esyslog(
"cTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
782 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
783 return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
784 esyslog(
"cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
789# warning Posix monotonic clock not available
792 if (gettimeofday(&t, NULL) == 0)
793 return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;
820#define MT(s, m, v) ((*(s) & (m)) == (v))
821 if (
MT(s, 0xE0, 0xC0) &&
MT(s + 1, 0xC0, 0x80))
823 if (
MT(s, 0xF0, 0xE0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80))
825 if (
MT(s, 0xF8, 0xF0) &&
MT(s + 1, 0xC0, 0x80) &&
MT(s + 2, 0xC0, 0x80) &&
MT(s + 3, 0xC0, 0x80))
837 case 2:
return ((*s & 0x1F) << 6) | (*(s + 1) & 0x3F);
838 case 3:
return ((*s & 0x0F) << 12) | ((*(s + 1) & 0x3F) << 6) | (*(s + 2) & 0x3F);
839 case 4:
return ((*s & 0x07) << 18) | ((*(s + 1) & 0x3F) << 12) | ((*(s + 2) & 0x3F) << 6) | (*(s + 3) & 0x3F);
854 *s++ = ((c >> 6) & 0x1F) | 0xC0;
855 *s = (c & 0x3F) | 0x80;
861 *s++ = ((c >> 12) & 0x0F) | 0xE0;
862 *s++ = ((c >> 6) & 0x3F) | 0x80;
863 *s = (c & 0x3F) | 0x80;
869 *s++ = ((c >> 18) & 0x07) | 0xF0;
870 *s++ = ((c >> 12) & 0x3F) | 0x80;
871 *s++ = ((c >> 6) & 0x3F) | 0x80;
872 *s = (c & 0x3F) | 0x80;
884 while (*s && Symbols--) {
926 while (*s && --Size > 0) {
928 *a++ = (
uchar)(*s++);
945 while (*a && NumChars < Size) {
946 if (Max >= 0 && NumSyms++ >= Max)
954 if (NumChars + sl <= Size) {
979 cd = iconv_open(ToCode, FromCode);
987 if (
cd != (iconv_t)-1)
995 if (!strcasestr(CharacterTable,
"UTF-8")) {
998 for (
int i = 0; i < 128; i++)
1002 const char *s = csc.
Convert(buf);
1016 if (
cd != (iconv_t)-1 && From && *From) {
1017 char *FromPtr = (
char *)From;
1018 size_t FromLength = strlen(From);
1021 int NewLength =
max(
length, FromLength * 2);
1022 if (
char *NewBuffer = (
char *)realloc(
result, NewLength)) {
1027 esyslog(
"ERROR: out of memory");
1036 char *Converted = ToPtr;
1037 while (FromLength > 0) {
1038 if (iconv(
cd, &FromPtr, &FromLength, &ToPtr, &ToLength) ==
size_t(-1)) {
1039 if (errno == E2BIG || errno == EILSEQ && ToLength < 1) {
1043 size_t d = ToPtr -
result;
1045 int NewLength =
length + r;
1046 if (
char *NewBuffer = (
char *)realloc(
result, NewLength)) {
1048 Converted =
result = NewBuffer;
1051 esyslog(
"ERROR: out of memory");
1057 if (errno == EILSEQ) {
1064 else if (errno != E2BIG)
1078 s = TakePointer ? (
char *)S : S ? strdup(S) : NULL;
1097 s = String.
s ? strdup(String.
s) : NULL;
1107 if (
this == &String)
1110 s = String.
s ? strdup(String.
s) : NULL;
1116 if (
this != &String) {
1129 s = String ? strdup(String) : NULL;
1136 int l1 =
s ? strlen(
s) : 0;
1137 int l2 = strlen(String);
1138 if (
char *p = (
char *)realloc(
s, l1 + l2 + 1)) {
1140 strcpy(
s + l1, String);
1143 esyslog(
"ERROR: out of memory");
1151 int l1 =
s ? strlen(
s) : 0;
1153 if (
char *p = (
char *)realloc(
s, l1 + l2 + 1)) {
1159 esyslog(
"ERROR: out of memory");
1169 if (Index >= 0 && Index < l)
1185 if (!fmt || vasprintf(&buffer, fmt, ap) < 0) {
1186 esyslog(
"error in vasprintf('%s', ...)", fmt);
1187 buffer = strdup(
"???");
1196 if (!fmt || vasprintf(&buffer, fmt, ap) < 0) {
1197 esyslog(
"error in vasprintf('%s', ...)", fmt);
1198 buffer = strdup(
"???");
1206 WeekDay = WeekDay == 0 ? 6 : WeekDay - 1;
1207 if (0 <= WeekDay && WeekDay <= 6) {
1209 const char *day =
tr(
"MonTueWedThuFriSatSun");
1221 return WeekDayName(localtime_r(&t, &tm_r)->tm_wday);
1226 WeekDay = WeekDay == 0 ? 6 : WeekDay - 1;
1228 case 0:
return tr(
"Monday");
1229 case 1:
return tr(
"Tuesday");
1230 case 2:
return tr(
"Wednesday");
1231 case 3:
return tr(
"Thursday");
1232 case 4:
return tr(
"Friday");
1233 case 5:
return tr(
"Saturday");
1234 case 6:
return tr(
"Sunday");
1235 default:
return "???";
1251 tm *tm = localtime_r(&t, &tm_r);
1252 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);
1259 if (ctime_r(&t, buffer)) {
1260 buffer[strlen(buffer) - 1] = 0;
1270 tm *tm = localtime_r(&t, &tm_r);
1273 strftime(p,
sizeof(buf) - (p - buf),
"%d.%m.%Y", tm);
1281 tm *tm = localtime_r(&t, &tm_r);
1282 strftime(buf,
sizeof(buf),
"%d.%m.%y", tm);
1290 strftime(buf,
sizeof(buf),
"%R", localtime_r(&t, &tm_r));
1296#define JPEGCOMPRESSMEM 500000
1316 int Used = jcd->
size;
1318 if (
uchar *NewBuffer = (
uchar *)realloc(jcd->
mem, NewSize)) {
1319 jcd->
size = NewSize;
1320 jcd->
mem = NewBuffer;
1323 esyslog(
"ERROR: out of memory");
1327 cinfo->dest->next_output_byte = jcd->
mem + Used;
1328 cinfo->dest->free_in_buffer = jcd->
size - Used;
1339 int Used = cinfo->dest->next_output_byte - jcd->
mem;
1340 if (Used < jcd->size) {
1343 jcd->
mem = NewBuffer;
1346 esyslog(
"ERROR: out of memory");
1355 else if (Quality > 100)
1358 jpeg_destination_mgr jdm;
1364 struct jpeg_compress_struct cinfo;
1365 struct jpeg_error_mgr jerr;
1366 cinfo.err = jpeg_std_error(&jerr);
1367 jpeg_create_compress(&cinfo);
1370 cinfo.client_data = &jcd;
1371 cinfo.image_width = Width;
1372 cinfo.image_height = Height;
1373 cinfo.input_components = 3;
1374 cinfo.in_color_space = JCS_RGB;
1376 jpeg_set_defaults(&cinfo);
1377 jpeg_set_quality(&cinfo, Quality, TRUE);
1378 jpeg_start_compress(&cinfo, TRUE);
1381 JSAMPROW rp[Height];
1382 for (
int k = 0; k < Height; k++)
1383 rp[k] = &Mem[rs * k];
1384 jpeg_write_scanlines(&cinfo, rp, Height);
1385 jpeg_finish_compress(&cinfo);
1386 jpeg_destroy_compress(&cinfo);
1396 static char buffer[HOST_NAME_MAX] =
"";
1398 if (gethostname(buffer,
sizeof(buffer)) < 0) {
1400 strcpy(buffer,
"vdr");
1408const char *
cBase64Encoder::b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1431 c |= (
data[
i] >> 4) & 0x0F;
1434 c = (
data[
i] << 2) & 0x3F;
1436 c |= (
data[
i] >> 6) & 0x03;
1535 Add(FileHandle, Out);
1540 if (FileHandle >= 0) {
1542 if (
pfd[i].fd == FileHandle &&
pfd[i].events == (Out ? POLLOUT : POLLIN))
1552 esyslog(
"ERROR: too many file handles in cPoller");
1559 if (FileHandle >= 0) {
1561 if (
pfd[i].fd == FileHandle &&
pfd[i].events == (Out ? POLLOUT : POLLIN)) {
1596#if !__GLIBC_PREREQ(2, 24)
1601 if (strcmp(
result->d_name,
".") && strcmp(
result->d_name,
".."))
1617 for (
int i = 0; i < Size(); i++) {
1618 if (!strcmp(s, At(i)))
1626 for (
int i = 0; i < Size(); i++)
1636 Load(Directory, DirsOnly);
1646 while ((e =
d.Next()) != NULL) {
1649 if (stat(
AddDirectory(Directory, e->d_name), &ds) == 0) {
1650 if (!S_ISDIR(ds.st_mode))
1654 Append(strdup(e->d_name));
1668bool cFile::files[FD_SETSIZE] = {
false };
1669int cFile::maxFiles = 0;
1685 return Open(open(FileName, Flags, Mode));
1686 esyslog(
"ERROR: attempt to re-open %s", FileName);
1697 if (f < FD_SETSIZE) {
1703 esyslog(
"ERROR: file descriptor %d already in files[]", f);
1707 esyslog(
"ERROR: file descriptor %d is larger than FD_SETSIZE (%d)", f, FD_SETSIZE);
1712 esyslog(
"ERROR: attempt to re-open file descriptor %d", FileDes);
1730 return f >= 0 && FileReady(f, Wait ? 1000 : 0);
1734bool cFile::AnyFileReady(
int FileDes,
int TimeoutMs)
1738 for (
int i = 0; i < maxFiles; i++) {
1742 if (0 <= FileDes && FileDes < FD_SETSIZE && !files[FileDes])
1743 FD_SET(FileDes, &set);
1746 struct timeval timeout;
1747 timeout.tv_sec = TimeoutMs / 1000;
1748 timeout.tv_usec = (TimeoutMs % 1000) * 1000;
1749 return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && (FileDes < 0 || FD_ISSET(FileDes, &set));
1756 struct timeval timeout;
1758 FD_SET(FileDes, &set);
1759 if (TimeoutMs >= 0) {
1760 if (TimeoutMs < 100)
1762 timeout.tv_sec = TimeoutMs / 1000;
1763 timeout.tv_usec = (TimeoutMs % 1000) * 1000;
1765 return select(FD_SETSIZE, &set, NULL, NULL, (TimeoutMs >= 0) ? &timeout : NULL) > 0 && FD_ISSET(FileDes, &set);
1769bool cFile::FileReadyForWriting(
int FileDes,
int TimeoutMs)
1772 struct timeval timeout;
1774 FD_SET(FileDes, &set);
1775 if (TimeoutMs < 100)
1778 timeout.tv_usec = TimeoutMs * 1000;
1779 return select(FD_SETSIZE, NULL, &set, NULL, &timeout) > 0 && FD_ISSET(FileDes, &set);
1789 tempName = fileName ?
MALLOC(
char, strlen(fileName) + 5) : NULL;
1791 strcat(strcpy(tempName, fileName),
".$$$");
1805 if (!f && fileName && tempName) {
1806 f = fopen(tempName,
"w");
1817 if (ferror(f) != 0) {
1823 if (fclose(f) < 0) {
1828 if (
result && rename(tempName, fileName) < 0) {
1840#ifndef USE_FADVISE_READ
1841#define USE_FADVISE_READ 0
1843#ifndef USE_FADVISE_WRITE
1844#define USE_FADVISE_WRITE 1
1847#define WRITE_BUFFER KILOBYTE(800)
1862 fd = open(FileName, Flags, Mode);
1864#if USE_FADVISE_READ || USE_FADVISE_WRITE
1865 begin = lastpos = ahead = 0;
1872 posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);
1880#if USE_FADVISE_READ || USE_FADVISE_WRITE
1883 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
1887 return close(OldFd);
1898#define FADVGRAN KILOBYTE(4)
1899#define READCHUNK MEGABYTE(8)
1909 return posix_fadvise(fd, Offset - (
FADVGRAN - 1), Len + (
FADVGRAN - 1) * 2, POSIX_FADV_DONTNEED);
1914 if (Whence == SEEK_SET && Offset == curpos)
1916 curpos = lseek(fd, Offset, Whence);
1924 off_t jumped = curpos-lastpos;
1925 if ((cachedstart < cachedend) && (curpos < cachedstart || curpos > cachedend)) {
1927 FadviseDrop(cachedstart, cachedend-cachedstart);
1928 cachedstart = curpos;
1931 cachedstart =
min(cachedstart, curpos);
1933 ssize_t bytesRead =
safe_read(fd, Data, Size);
1934 if (bytesRead > 0) {
1935 curpos += bytesRead;
1937 cachedend =
max(cachedend, curpos);
1941 if (jumped >= 0 && jumped <= (off_t)readahead) {
1945 if (ahead - curpos < (off_t)(readahead / 2)) {
1946 posix_fadvise(fd, curpos, readahead, POSIX_FADV_WILLNEED);
1947 ahead = curpos + readahead;
1948 cachedend =
max(cachedend, ahead);
1950 if (readahead < Size * 32) {
1951 readahead = Size * 32;
1959 if (cachedstart < cachedend) {
1960 if (curpos - cachedstart >
READCHUNK * 2) {
1962 FadviseDrop(cachedstart, curpos -
READCHUNK - cachedstart);
1965 else if (cachedend > ahead && cachedend - curpos >
READCHUNK * 2) {
1981 ssize_t bytesWritten =
safe_write(fd, Data, Size);
1982#if USE_FADVISE_WRITE
1983 if (bytesWritten > 0) {
1984 begin =
min(begin, curpos);
1985 curpos += bytesWritten;
1986 written += bytesWritten;
1987 lastpos =
max(lastpos, curpos);
1989 if (lastpos > begin) {
1999 posix_fadvise(fd, begin - headdrop, lastpos - begin + headdrop, POSIX_FADV_DONTNEED);
2001 begin = lastpos = curpos;
2002 totwritten += written;
2017 off_t headdrop =
min(off_t(curpos - totwritten), off_t(totwritten * 2));
2018 posix_fadvise(fd, curpos - totwritten - headdrop, totwritten + headdrop, POSIX_FADV_DONTNEED);
2024 return bytesWritten;
2032 if (File->
Open(FileName, Flags, Mode) < 0) {
2041#define LOCKFILENAME ".lock-vdr"
2042#define LOCKFILESTALETIME 600
2060 if (f < 0 && fileName) {
2061 time_t Timeout = time(NULL) + WaitSeconds;
2063 f = open(fileName, O_WRONLY | O_CREAT | O_EXCL, DEFFILEMODE);
2065 if (errno == EEXIST) {
2067 if (stat(fileName, &fs) == 0) {
2069 esyslog(
"ERROR: removing stale lock file '%s'", fileName);
2070 if (remove(fileName) < 0) {
2077 else if (errno != ENOENT) {
2084 if (errno == ENOSPC) {
2085 esyslog(
"ERROR: can't create lock file '%s' - assuming lock anyway!", fileName);
2093 }
while (f < 0 && time(NULL) < Timeout);
2121 Object->
prev =
this;
2127 Object->
next =
this;
2153#define LIST_GARBAGE_COLLECTOR_TIMEOUT 5
2166 esyslog(
"ERROR: ListGarbageCollector destroyed without prior Purge()!");
2172 Object->
next = objects;
2174 lastPut = time(NULL);
2187 objects = Object->next;
2197:stateLock(NeedsLocking)
2215 esyslog(
"ERROR: cListBase::Lock() called for a list that doesn't require locking");
2237 if (Before && Before !=
objects) {
2274 if (From && To && From != To) {
2331 while (
object && Index-- > 0)
2332 object =
object->
Next();
2351 while (
object && i < n) {
2353 object =
object->
Next();
2357 for (i = 0; i < n; i++) {
2381 if (
size < NewSize) {
2388 esyslog(
"ERROR: out of memory");
2420 unsigned int hash =
hashfn(Id);
2431 if (hob->object == Object) {
2441 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 const char * SystemCharacterTable(void)
static void SetSystemCharacterTable(const char *CharacterTable)
static char * systemCharacterTable
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 FileReady(int FileDes, 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",...
void Insert(cListObject *Object)
cListObject * Next(void) const
void Append(cListObject *Object)
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
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)