summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2002-08-16 18:00:00 +0200
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2002-08-16 18:00:00 +0200
commited643353b100bee75459c4ef2d0330e7a04e1f2a (patch)
tree8a424eba464677a71309e1125ce4e7acef58607e /tools.c
parent527748826c8d3cfacff8a7ab3fda9551c1182590 (diff)
downloadvdr-patch-lnbsharing-ed643353b100bee75459c4ef2d0330e7a04e1f2a.tar.gz
vdr-patch-lnbsharing-ed643353b100bee75459c4ef2d0330e7a04e1f2a.tar.bz2
Version 1.1.7vdr-1.1.7
- Adapted VDR to the NEWSTRUCT driver. To use the new driver, compile VDR with 'make NEWSTRUCT=1' (thanks to Holger Wächtler for some valuable advice). By default it currently still uses the old driver. - Added some missing #includes (thanks to Martin Hammerschmid). - Changed the log error message "can't record MPEG1!" to "error in data stream!", since the mentioning of MPEG1 has irritated many people. - Consistently using malloc/free and new/delete (thanks to Andreas Schultz). - Temporarily made cDevice::ProvidesCa() virtual (Andreas Schultz needs this in his DXR3 plugin). - cDevice no longer exposes a file handle to cPlayer. A derived cPlayer class can now call DevicePoll() to see whether the replay device is ready for further data. A derived cDevice class must implement Poll() and shall check if any of its file handles is ready for data. - Implemented several replay modes to allow players that play only audio (thanks to Stefan Huelswitt). - Improved cCondVar::Wait() and implemented cCondVar::TimedWait() (thanks to Stefan Huelswitt). - VDR no longer gives up if there is no DVB device. It continues to work if there is at least one device, either a DVB device found by the core VDR code itself, or a device implemented by a plugin.
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/tools.c b/tools.c
index 6449a1b..29c5f2d 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.68 2002/08/03 15:44:53 kls Exp $
+ * $Id: tools.c 1.70 2002/08/16 13:43:40 kls Exp $
*/
#include "tools.h"
@@ -80,7 +80,7 @@ char *strcpyrealloc(char *dest, const char *src)
esyslog("ERROR: out of memory");
}
else {
- delete dest;
+ free(dest);
dest = NULL;
}
return dest;
@@ -239,7 +239,7 @@ bool isnumber(const char *s)
const char *AddDirectory(const char *DirName, const char *FileName)
{
static char *buf = NULL;
- delete buf;
+ free(buf);
asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName);
return buf;
}
@@ -303,7 +303,7 @@ bool MakeDirs(const char *FileName, bool IsDirectory)
else
break;
}
- delete s;
+ free(s);
return result;
}
@@ -321,7 +321,7 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
asprintf(&buffer, "%s/%s", FileName, e->d_name);
if (FollowSymlinks) {
int size = strlen(buffer) * 2; // should be large enough
- char *l = new char[size];
+ char *l = MALLOC(char, size);
int n = readlink(buffer, l, size);
if (n < 0) {
if (errno != EINVAL)
@@ -335,12 +335,12 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks)
}
else
esyslog("ERROR: symlink name length (%d) exceeded anticipated buffer size (%d)", n, size);
- delete l;
+ free(l);
}
dsyslog("removing %s", buffer);
if (remove(buffer) < 0)
LOG_ERROR_STR(buffer);
- delete buffer;
+ free(buffer);
}
}
closedir(d);
@@ -384,10 +384,10 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis)
}
else {
LOG_ERROR_STR(buffer);
- delete buffer;
+ free(buffer);
return false;
}
- delete buffer;
+ free(buffer);
}
}
closedir(d);
@@ -429,7 +429,7 @@ bool SpinUpDisk(const char *FileName)
{
static char *buf = NULL;
for (int n = 0; n < 10; n++) {
- delete buf;
+ free(buf);
if (DirectoryOk(FileName))
asprintf(&buf, "%s/vdr-%06d", *FileName ? FileName : ".", n);
else
@@ -482,6 +482,42 @@ const char *DayDateTime(time_t t)
return buffer;
}
+// --- cPoller ---------------------------------------------------------------
+
+cPoller::cPoller(int FileHandle, bool Out)
+{
+ numFileHandles = 0;
+ Add(FileHandle, Out);
+}
+
+bool cPoller::Add(int FileHandle, bool Out)
+{
+ if (FileHandle >= 0) {
+ for (int i = 0; i < numFileHandles; i++) {
+ if (pfd[i].fd == FileHandle)
+ return true;
+ }
+ if (numFileHandles < MaxPollFiles) {
+ pfd[numFileHandles].fd = FileHandle;
+ pfd[numFileHandles].events = Out ? POLLOUT : POLLIN;
+ numFileHandles++;
+ return true;
+ }
+ esyslog("ERROR: too many file handles in cPoller");
+ }
+ return false;
+}
+
+bool cPoller::Poll(int TimeoutMs)
+{
+ if (numFileHandles) {
+ if (poll(pfd, numFileHandles, TimeoutMs) != 0)
+ return true; // returns true even in case of an error, to let the caller
+ // access the file and thus see the error code
+ }
+ return false;
+}
+
// --- cFile -----------------------------------------------------------------
bool cFile::files[FD_SETSIZE] = { false };
@@ -594,7 +630,7 @@ cSafeFile::cSafeFile(const char *FileName)
{
f = NULL;
fileName = ReadLink(FileName);
- tempName = fileName ? new char[strlen(fileName) + 5] : NULL;
+ tempName = fileName ? MALLOC(char, strlen(fileName) + 5) : NULL;
if (tempName)
strcat(strcpy(tempName, fileName), ".$$$");
}
@@ -604,8 +640,8 @@ cSafeFile::~cSafeFile()
if (f)
fclose(f);
unlink(tempName);
- delete fileName;
- delete tempName;
+ free(fileName);
+ free(tempName);
}
bool cSafeFile::Open(void)
@@ -657,7 +693,7 @@ cLockFile::cLockFile(const char *Directory)
cLockFile::~cLockFile()
{
Unlock();
- delete fileName;
+ free(fileName);
}
bool cLockFile::Lock(int WaitSeconds)