mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Better error handling when writing configuration files
This commit is contained in:
parent
9be288dbb4
commit
6ceefaf85f
1
HISTORY
1
HISTORY
@ -750,3 +750,4 @@ Video Disk Recorder Revision History
|
|||||||
- Changed obsolete macro VIDEO_WINDOW_CHROMAKEY to VID_TYPE_CHROMAKEY (thanks
|
- Changed obsolete macro VIDEO_WINDOW_CHROMAKEY to VID_TYPE_CHROMAKEY (thanks
|
||||||
to Guido Fiala).
|
to Guido Fiala).
|
||||||
- New version of the "Master-Timer" tool (thanks to Matthias Schniedermeyer).
|
- New version of the "Master-Timer" tool (thanks to Matthias Schniedermeyer).
|
||||||
|
- Better error handling when writing configuration files.
|
||||||
|
27
config.c
27
config.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: config.c 1.70 2001/09/14 14:35:30 kls Exp $
|
* $Id: config.c 1.71 2001/09/16 08:57:58 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -122,24 +122,14 @@ bool cKeys::Load(const char *FileName)
|
|||||||
|
|
||||||
bool cKeys::Save(void)
|
bool cKeys::Save(void)
|
||||||
{
|
{
|
||||||
bool result = true;
|
|
||||||
cSafeFile f(fileName);
|
cSafeFile f(fileName);
|
||||||
if (f.Open()) {
|
if (f.Open()) {
|
||||||
if (fprintf(f, "Code\t%c\nAddress\t%04X\n", code, address) > 0) {
|
fprintf(f, "Code\t%c\nAddress\t%04X\n", code, address);
|
||||||
for (tKey *k = keys; k->type != kNone; k++) {
|
for (tKey *k = keys; k->type != kNone; k++)
|
||||||
if (fprintf(f, "%s\t%08X\n", k->name, k->code) <= 0) {
|
fprintf(f, "%s\t%08X\n", k->name, k->code);
|
||||||
result = false;
|
return f.Close();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
}
|
|
||||||
else
|
|
||||||
result = false;
|
|
||||||
f.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
result = false;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eKeys cKeys::Get(unsigned int Code)
|
eKeys cKeys::Get(unsigned int Code)
|
||||||
@ -928,12 +918,11 @@ bool cSetup::Save(const char *FileName)
|
|||||||
fprintf(f, "MultiSpeedMode = %d\n", MultiSpeedMode);
|
fprintf(f, "MultiSpeedMode = %d\n", MultiSpeedMode);
|
||||||
fprintf(f, "ShowReplayMode = %d\n", ShowReplayMode);
|
fprintf(f, "ShowReplayMode = %d\n", ShowReplayMode);
|
||||||
fprintf(f, "CurrentChannel = %d\n", CurrentChannel);
|
fprintf(f, "CurrentChannel = %d\n", CurrentChannel);
|
||||||
f.Close();
|
if (f.Close()) {
|
||||||
isyslog(LOG_INFO, "saved setup to %s", FileName);
|
isyslog(LOG_INFO, "saved setup to %s", FileName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
LOG_ERROR_STR(FileName);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
esyslog(LOG_ERR, "attempt to save setup without file name");
|
esyslog(LOG_ERR, "attempt to save setup without file name");
|
||||||
|
5
config.h
5
config.h
@ -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: config.h 1.77 2001/09/14 14:35:32 kls Exp $
|
* $Id: config.h 1.78 2001/09/15 15:38:40 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __CONFIG_H
|
#ifndef __CONFIG_H
|
||||||
@ -226,7 +226,8 @@ public:
|
|||||||
}
|
}
|
||||||
l = (T *)l->Next();
|
l = (T *)l->Next();
|
||||||
}
|
}
|
||||||
f.Close();
|
if (!f.Close())
|
||||||
|
result = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = false;
|
result = false;
|
||||||
|
24
tools.c
24
tools.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: tools.c 1.44 2001/09/14 14:35:37 kls Exp $
|
* $Id: tools.c 1.45 2001/09/15 15:41:16 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
@ -554,13 +554,27 @@ bool cSafeFile::Open(void)
|
|||||||
return f != NULL;
|
return f != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cSafeFile::Close(void)
|
bool cSafeFile::Close(void)
|
||||||
{
|
{
|
||||||
|
bool result = true;
|
||||||
if (f) {
|
if (f) {
|
||||||
fclose(f);
|
if (ferror(f) != 0) {
|
||||||
f = NULL;
|
LOG_ERROR_STR(tempName);
|
||||||
rename(tempName, fileName);
|
result = false;
|
||||||
}
|
}
|
||||||
|
if (fclose(f) < 0) {
|
||||||
|
LOG_ERROR_STR(tempName);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
f = NULL;
|
||||||
|
if (result && rename(tempName, fileName) < 0) {
|
||||||
|
LOG_ERROR_STR(fileName);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- cListObject -----------------------------------------------------------
|
// --- cListObject -----------------------------------------------------------
|
||||||
|
4
tools.h
4
tools.h
@ -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: tools.h 1.33 2001/09/14 14:35:40 kls Exp $
|
* $Id: tools.h 1.34 2001/09/15 15:22:57 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TOOLS_H
|
#ifndef __TOOLS_H
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
~cSafeFile();
|
~cSafeFile();
|
||||||
operator FILE* () { return f; }
|
operator FILE* () { return f; }
|
||||||
bool Open(void);
|
bool Open(void);
|
||||||
void Close(void);
|
bool Close(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
class cListObject {
|
class cListObject {
|
||||||
|
Loading…
Reference in New Issue
Block a user