diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2000-04-15 18:00:00 +0200 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2000-04-15 18:00:00 +0200 |
commit | 37250a0568d5b1d689d5c59f983e9be228ed49c2 (patch) | |
tree | f5b3cb133d5ec1ede63de04cf9c394bcf4a514a2 /tools.c | |
parent | 6feebe674c09b65e43012bf439c201cfb65aa82c (diff) | |
download | vdr-patch-lnbsharing-37250a0568d5b1d689d5c59f983e9be228ed49c2.tar.gz vdr-patch-lnbsharing-37250a0568d5b1d689d5c59f983e9be228ed49c2.tar.bz2 |
Version 0.03vdr_osm-0.03
- Actual record/replay now works.
- Dropped the idea of different "recording qualities" (a 36GB harddisk is
able to store some 18 hours in full quality, so we don't really need that).
- Termination signals are now caught and the program cleans up before exiting.
- Support for CICAM.
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 91 |
1 files changed, 83 insertions, 8 deletions
@@ -4,18 +4,46 @@ * See the main source file 'osm.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.2 2000/03/05 14:33:58 kls Exp $ + * $Id: tools.c 1.3 2000/04/15 15:10:05 kls Exp $ */ +#define _GNU_SOURCE #include "tools.h" +#include <dirent.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/time.h> +#include <unistd.h> #define MaxBuffer 1000 +int SysLogLevel = 3; + +void writechar(int filedes, char c) +{ + write(filedes, &c, sizeof(c)); +} + +void writeint(int filedes, int n) +{ + write(filedes, &n, sizeof(n)); +} + +char readchar(int filedes) +{ + char c; + read(filedes, &c, 1); + return c; +} + +bool readint(int filedes, int &n) +{ + //XXX timeout!! + return read(filedes, &n, sizeof(n)); +} + char *readline(FILE *f) { static char buffer[MaxBuffer]; @@ -30,36 +58,83 @@ char *readline(FILE *f) int time_ms(void) { + static time_t t0 = 0; struct timeval t; - if (gettimeofday(&t, NULL) == 0) - return t.tv_sec * 1000 + t.tv_usec / 1000; + if (gettimeofday(&t, NULL) == 0) { + if (t0 == 0) + t0 = t.tv_sec; // this avoids an overflow (we only work with deltas) + return (t.tv_sec - t0) * 1000 + t.tv_usec / 1000; + } return 0; } -bool MakeDirs(const char *FileName) +void delay_ms(int ms) +{ + int t0 = time_ms(); + while (time_ms() - t0 < ms) + ; +} + +bool MakeDirs(const char *FileName, bool IsDirectory) { bool result = true; char *s = strdup(FileName); char *p = s; if (*p == '/') p++; - while ((p = strchr(p, '/')) != NULL) { - *p = 0; + while ((p = strchr(p, '/')) != NULL || IsDirectory) { + if (p) + *p = 0; struct stat fs; if (stat(s, &fs) != 0 || !S_ISDIR(fs.st_mode)) { isyslog(LOG_INFO, "creating directory %s", s); if (mkdir(s, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) { - esyslog(LOG_ERR, "ERROR while creating directory %s: %s", s, strerror(errno)); + esyslog(LOG_ERR, "ERROR: %s: %s", s, strerror(errno)); result = false; break; } } - *p++ = '/'; + if (p) + *p++ = '/'; + else + break; } delete s; return result; } +bool RemoveFileOrDir(const char *FileName) +{ + struct stat st; + if (stat(FileName, &st) == 0) { + if (S_ISDIR(st.st_mode)) { + DIR *d = opendir(FileName); + if (d) { + struct dirent *e; + while ((e = readdir(d)) != NULL) { + if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { + char *buffer; + asprintf(&buffer, "%s/%s", FileName, e->d_name); + if (remove(buffer) < 0) + esyslog(LOG_ERR, "ERROR: %s: %s", buffer, strerror(errno)); + delete buffer; + } + } + closedir(d); + } + else { + esyslog(LOG_ERR, "ERROR: %s: %s", FileName, strerror(errno)); + return false; + } + } + if (remove(FileName) == 0) + return true; + } + else + esyslog(LOG_ERR, "ERROR: %s: %s", FileName, strerror(errno)); + return false; +} + // --- cListObject ----------------------------------------------------------- cListObject::cListObject(void) |