mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Improved usage of 'safe_write()'
This commit is contained in:
parent
ef91debc4d
commit
c751c195c1
37
dvbapi.c
37
dvbapi.c
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: dvbapi.c 1.164 2002/03/23 14:14:03 kls Exp $
|
* $Id: dvbapi.c 1.165 2002/03/23 16:15:00 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dvbapi.h"
|
#include "dvbapi.h"
|
||||||
@ -98,7 +98,7 @@ class cIndexFile {
|
|||||||
private:
|
private:
|
||||||
struct tIndex { int offset; uchar type; uchar number; short reserved; };
|
struct tIndex { int offset; uchar type; uchar number; short reserved; };
|
||||||
int f;
|
int f;
|
||||||
char *fileName, *pFileExt;
|
char *fileName;
|
||||||
int size, last;
|
int size, last;
|
||||||
tIndex *index;
|
tIndex *index;
|
||||||
cResumeFile resumeFile;
|
cResumeFile resumeFile;
|
||||||
@ -120,7 +120,7 @@ cIndexFile::cIndexFile(const char *FileName, bool Record)
|
|||||||
:resumeFile(FileName)
|
:resumeFile(FileName)
|
||||||
{
|
{
|
||||||
f = -1;
|
f = -1;
|
||||||
fileName = pFileExt = NULL;
|
fileName = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
last = -1;
|
last = -1;
|
||||||
index = NULL;
|
index = NULL;
|
||||||
@ -128,7 +128,7 @@ cIndexFile::cIndexFile(const char *FileName, bool Record)
|
|||||||
fileName = new char[strlen(FileName) + strlen(INDEXFILESUFFIX) + 1];
|
fileName = new char[strlen(FileName) + strlen(INDEXFILESUFFIX) + 1];
|
||||||
if (fileName) {
|
if (fileName) {
|
||||||
strcpy(fileName, FileName);
|
strcpy(fileName, FileName);
|
||||||
pFileExt = fileName + strlen(fileName);
|
char *pFileExt = fileName + strlen(fileName);
|
||||||
strcpy(pFileExt, INDEXFILESUFFIX);
|
strcpy(pFileExt, INDEXFILESUFFIX);
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
if (access(fileName, R_OK) == 0) {
|
if (access(fileName, R_OK) == 0) {
|
||||||
@ -177,8 +177,6 @@ cIndexFile::cIndexFile(const char *FileName, bool Record)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_ERROR_STR(fileName);
|
LOG_ERROR_STR(fileName);
|
||||||
delete fileName;
|
|
||||||
fileName = pFileExt = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -223,14 +221,14 @@ bool cIndexFile::CatchUp(int Index)
|
|||||||
last = newLast;
|
last = newLast;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_ERROR;
|
LOG_ERROR_STR(fileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
esyslog(LOG_ERR, "ERROR: can't realloc() index");
|
esyslog(LOG_ERR, "ERROR: can't realloc() index");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_ERROR;
|
LOG_ERROR_STR(fileName);
|
||||||
if (Index >= last)
|
if (Index >= last)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
else
|
else
|
||||||
@ -244,8 +242,8 @@ bool cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset)
|
|||||||
{
|
{
|
||||||
if (f >= 0) {
|
if (f >= 0) {
|
||||||
tIndex i = { FileOffset, PictureType, FileNumber, 0 };
|
tIndex i = { FileOffset, PictureType, FileNumber, 0 };
|
||||||
if (safe_write(f, &i, sizeof(i)) != sizeof(i)) {
|
if (safe_write(f, &i, sizeof(i)) < 0) {
|
||||||
esyslog(LOG_ERR, "ERROR: can't write to index file");
|
LOG_ERROR_STR(fileName);
|
||||||
close(f);
|
close(f);
|
||||||
f = -1;
|
f = -1;
|
||||||
return false;
|
return false;
|
||||||
@ -579,17 +577,12 @@ void cRecordBuffer::Output(void)
|
|||||||
if (NextFile()) {
|
if (NextFile()) {
|
||||||
if (index && pictureType != NO_PICTURE)
|
if (index && pictureType != NO_PICTURE)
|
||||||
index->Write(pictureType, fileName.Number(), fileSize);
|
index->Write(pictureType, fileName.Number(), fileSize);
|
||||||
while (Result > 0) {
|
if (safe_write(recordFile, p, Result) < 0) {
|
||||||
int w = safe_write(recordFile, p, Result);
|
LOG_ERROR_STR(fileName.Name());
|
||||||
if (w < 0) {
|
recording = false;
|
||||||
LOG_ERROR_STR(fileName.Name());
|
return;
|
||||||
recording = false;
|
}
|
||||||
return;
|
fileSize += Result;
|
||||||
}
|
|
||||||
p += w;
|
|
||||||
Result -= w;
|
|
||||||
fileSize += w;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@ -1557,7 +1550,7 @@ void cCuttingBuffer::Action(void)
|
|||||||
}
|
}
|
||||||
LastIFrame = 0;
|
LastIFrame = 0;
|
||||||
}
|
}
|
||||||
if (safe_write(toFile, buffer, Length) != Length) {
|
if (safe_write(toFile, buffer, Length) < 0) {
|
||||||
error = "safe_write";
|
error = "safe_write";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: recording.c 1.58 2002/03/23 11:32:33 kls Exp $
|
* $Id: recording.c 1.59 2002/03/23 16:15:32 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "recording.h"
|
#include "recording.h"
|
||||||
@ -172,7 +172,7 @@ bool cResumeFile::Save(int Index)
|
|||||||
if (fileName) {
|
if (fileName) {
|
||||||
int f = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
int f = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
if (f >= 0) {
|
if (f >= 0) {
|
||||||
if (safe_write(f, &Index, sizeof(Index)) != sizeof(Index))
|
if (safe_write(f, &Index, sizeof(Index)) < 0)
|
||||||
LOG_ERROR_STR(fileName);
|
LOG_ERROR_STR(fileName);
|
||||||
close(f);
|
close(f);
|
||||||
return true;
|
return true;
|
||||||
|
12
svdrp.c
12
svdrp.c
@ -10,7 +10,7 @@
|
|||||||
* and interact with the Video Disk Recorder - or write a full featured
|
* and interact with the Video Disk Recorder - or write a full featured
|
||||||
* graphical interface that sits on top of an SVDRP connection.
|
* graphical interface that sits on top of an SVDRP connection.
|
||||||
*
|
*
|
||||||
* $Id: svdrp.c 1.34 2002/03/08 17:17:05 kls Exp $
|
* $Id: svdrp.c 1.35 2002/03/23 16:17:39 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "svdrp.h"
|
#include "svdrp.h"
|
||||||
@ -340,16 +340,12 @@ bool cSVDRP::Send(const char *s, int length)
|
|||||||
{
|
{
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
length = strlen(s);
|
length = strlen(s);
|
||||||
int wbytes = safe_write(file, s, length);
|
if (safe_write(file, s, length) < 0) {
|
||||||
if (wbytes == length)
|
|
||||||
return true;
|
|
||||||
if (wbytes < 0) {
|
|
||||||
LOG_ERROR;
|
LOG_ERROR;
|
||||||
file.Close();
|
file.Close();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else //XXX while...???
|
return true;
|
||||||
esyslog(LOG_ERR, "Wrote %d bytes to client while expecting %d\n", wbytes, length);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cSVDRP::Reply(int Code, const char *fmt, ...)
|
void cSVDRP::Reply(int Code, const char *fmt, ...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user