summaryrefslogtreecommitdiff
path: root/tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools.h')
-rw-r--r--tools.h64
1 files changed, 54 insertions, 10 deletions
diff --git a/tools.h b/tools.h
index 9e0abff..621e589 100644
--- a/tools.h
+++ b/tools.h
@@ -4,15 +4,17 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 1.58 2004/10/31 16:16:37 kls Exp $
+ * $Id: tools.h 1.64 2005/01/04 11:09:51 kls Exp $
*/
#ifndef __TOOLS_H
#define __TOOLS_H
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
+#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
@@ -55,10 +57,20 @@ template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
#define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF))
int BCD2INT(int x);
+class cString {
+private:
+ char *s;
+public:
+ cString(const char *S = NULL);
+ virtual ~cString();
+ operator const char * () const { return s; } // for use in (const char *) context
+ const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.)
+ cString &operator=(const cString &String);
+ };
+
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);
-char *readline(FILE *f);
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);
@@ -66,16 +78,14 @@ char *strreplace(char *s, const char *s1, const char *s2); ///< re-allocates 's'
char *skipspace(const char *s);
char *stripspace(char *s);
char *compactspace(char *s);
-const char *strescape(const char *s, const char *chars); ///< \warning returns a statically allocated string!
+cString strescape(const char *s, const char *chars);
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);
-int time_ms(void);
-void delay_ms(int ms);
bool isnumber(const char *s);
-const char *itoa(int n); ///< \warning returns a statically allocated string!
-const char *AddDirectory(const char *DirName, const char *FileName); ///< \warning returns a statically allocated string!
+cString itoa(int n);
+cString AddDirectory(const char *DirName, const char *FileName);
int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL);
bool DirectoryOk(const char *DirName, bool LogErrors = false);
bool MakeDirs(const char *FileName, bool IsDirectory = false);
@@ -84,9 +94,28 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false);
char *ReadLink(const char *FileName);
bool SpinUpDisk(const char *FileName);
time_t LastModifiedTime(const char *FileName);
-const char *WeekDayName(int WeekDay); ///< \warning returns a statically allocated string!
-const char *WeekDayName(time_t t); ///< \warning returns a statically allocated string!
-const char *DayDateTime(time_t t = 0); ///< \warning returns a statically allocated string!
+cString WeekDayName(int WeekDay);
+cString WeekDayName(time_t t);
+cString DayDateTime(time_t t = 0);
+cString TimeToString(time_t t);
+
+class cTimeMs {
+private:
+ uint64 begin;
+public:
+ cTimeMs(void);
+ static uint64 Now(void);
+ void Set(int Ms = 0);
+ bool TimedOut(void);
+ uint64 Elapsed(void);
+ };
+
+class cReadLine {
+private:
+ char buffer[MAXPARSEBUFFER];
+public:
+ char *Read(FILE *f);
+ };
class cPoller {
private:
@@ -99,6 +128,21 @@ public:
bool Poll(int TimeoutMs = 0);
};
+class cReadDir {
+private:
+ DIR *directory;
+ struct dirent *result;
+ union { // according to "The GNU C Library Reference Manual"
+ struct dirent d;
+ char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
+ } u;
+public:
+ cReadDir(const char *Directory);
+ ~cReadDir();
+ bool Ok(void) { return directory != NULL; }
+ struct dirent *Next(void);
+ };
+
class cFile {
private:
static bool files[];