Commit 2c069236 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(is_clean, get_version, post_sync, save_one_text, sync_part):

(init_cache, free_all_cache): Use i_fopen and i_fclose instead of
	fopen and fclose.
(pre_sync): Ditto, and i_rename instead of rename.
parent 4ae9bc32
/* /*
* $Id: simple-cache.c,v 0.98 2002/10/04 23:39:47 ceder Exp $ * $Id: simple-cache.c,v 0.99 2002/10/31 09:31:37 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association. * Copyright (C) 1991-2002 Lysator Academic Computer Association.
* *
* This file is part of the LysKOM server. * This file is part of the LysKOM server.
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
#include "unused.h" #include "unused.h"
#include "local-to-global.h" #include "local-to-global.h"
#include "server-time.h" #include "server-time.h"
#include "eintr.h"
/* /*
* Possible improvements: * Possible improvements:
...@@ -1574,7 +1575,7 @@ is_clean(const char *fn) ...@@ -1574,7 +1575,7 @@ is_clean(const char *fn)
{ {
FILE *fp; FILE *fp;
if ( (fp = fopen(fn, "rb")) == NULL ) if ( (fp = i_fopen(fn, "rb")) == NULL )
return FALSE; return FALSE;
if ( getc(fp) == 'C' && if ( getc(fp) == 'C' &&
...@@ -1583,12 +1584,12 @@ is_clean(const char *fn) ...@@ -1583,12 +1584,12 @@ is_clean(const char *fn)
getc(fp) == 'A' && getc(fp) == 'A' &&
getc(fp) == 'N' ) getc(fp) == 'N' )
{ {
fclose(fp); i_fclose(fp);
return TRUE; return TRUE;
} }
else else
{ {
fclose(fp); i_fclose(fp);
return FALSE; return FALSE;
} }
} }
...@@ -1600,17 +1601,17 @@ get_version(const char *fn) ...@@ -1600,17 +1601,17 @@ get_version(const char *fn)
FILE *fp; FILE *fp;
long version; long version;
if ( (fp = fopen(fn, "rb")) == NULL) if ((fp = i_fopen(fn, "rb")) == NULL)
return -1; return -1;
fseek(fp, 5, SEEK_SET); fseek(fp, 5, SEEK_SET);
if (getc(fp) == '\n') if (getc(fp) == '\n')
{ {
fclose(fp); i_fclose(fp);
return 0; return 0;
} }
version = fparse_long(fp); version = fparse_long(fp);
fclose(fp); i_fclose(fp);
return version; return version;
} }
...@@ -1742,14 +1743,14 @@ pre_sync(void) ...@@ -1742,14 +1743,14 @@ pre_sync(void)
{ {
if (is_clean(param.backupfile_name)) if (is_clean(param.backupfile_name))
{ {
if (rename(param.backupfile_name, if (i_rename(param.backupfile_name,
param.backupfile_name_2) != 0) param.backupfile_name_2) != 0)
{ {
kom_log("pre_sync: can't do extra backup.\n"); kom_log("pre_sync: can't do extra backup.\n");
} }
} }
if (rename(param.datafile_name, param.backupfile_name) != 0) if (i_rename(param.datafile_name, param.backupfile_name) != 0)
restart_kom("pre_sync: can't backup.\n"); restart_kom("pre_sync: can't backup.\n");
} }
else else
...@@ -1758,13 +1759,13 @@ pre_sync(void) ...@@ -1758,13 +1759,13 @@ pre_sync(void)
if ( file_b != NULL ) if ( file_b != NULL )
{ {
kom_log("pre_sync: Save in progress aborted.\n"); kom_log("pre_sync: Save in progress aborted.\n");
fclose(file_b); i_fclose(file_b);
#ifdef FASTSAVE #ifdef FASTSAVE
file_b = NULL; file_b = NULL;
#endif #endif
} }
if ( (file_b = fopen(param.datafile_name, "wb") ) == NULL ) if ((file_b = i_fopen(param.datafile_name, "wb")) == NULL)
{ {
kom_log("WARNING: pre_sync: can't open file to save in.\n"); kom_log("WARNING: pre_sync: can't open file to save in.\n");
sync_state = sync_wait; sync_state = sync_wait;
...@@ -1773,9 +1774,9 @@ pre_sync(void) ...@@ -1773,9 +1774,9 @@ pre_sync(void)
} }
#ifdef FASTSAVE #ifdef FASTSAVE
if ( (file_b_r = fopen(param.datafile_name, "rb") ) == NULL ) if ((file_b_r = i_fopen(param.datafile_name, "rb")) == NULL)
{ {
fclose(file_b); i_fclose(file_b);
file_b = NULL; file_b = NULL;
kom_log("WARNING: pre_sync: can't open file to save in for reading.\n"); kom_log("WARNING: pre_sync: can't open file to save in for reading.\n");
sync_state = sync_wait; sync_state = sync_wait;
...@@ -2065,9 +2066,9 @@ post_sync(void) ...@@ -2065,9 +2066,9 @@ post_sync(void)
kom_log("WARNING: post_sync(): file_a == NULL. This is only normal %s", kom_log("WARNING: post_sync(): file_a == NULL. This is only normal %s",
"if this is the first sync ever on this data file.\n"); "if this is the first sync ever on this data file.\n");
else else
fclose(file_a); i_fclose(file_a);
if ( ( file_a = fopen(param.datafile_name, "rb") ) == NULL ) if ((file_a = i_fopen(param.datafile_name, "rb")) == NULL)
{ {
kom_log("post_sync: can't open the file I just saved.\n"); kom_log("post_sync: can't open the file I just saved.\n");
sync_state = sync_wait; sync_state = sync_wait;
...@@ -2241,7 +2242,7 @@ save_one_text(void) ...@@ -2241,7 +2242,7 @@ save_one_text(void)
return; return;
} }
if ( fclose(file_b) != 0 ) if (i_fclose(file_b) != 0)
{ {
file_b = NULL; file_b = NULL;
...@@ -2253,7 +2254,7 @@ save_one_text(void) ...@@ -2253,7 +2254,7 @@ save_one_text(void)
#ifdef FASTSAVE #ifdef FASTSAVE
if ( fclose(file_b_r) != 0 ) if (i_fclose(file_b_r) != 0)
{ {
file_b_r = NULL; file_b_r = NULL;
...@@ -2265,7 +2266,7 @@ save_one_text(void) ...@@ -2265,7 +2266,7 @@ save_one_text(void)
file_b_r = NULL; file_b_r = NULL;
#endif #endif
file_b = fopen(param.datafile_name, "rb"); file_b = i_fopen(param.datafile_name, "rb");
if (file_b == NULL) if (file_b == NULL)
{ {
kom_log("save_one_text(): failed to reopen file.\n"); kom_log("save_one_text(): failed to reopen file.\n");
...@@ -2289,7 +2290,7 @@ save_one_text(void) ...@@ -2289,7 +2290,7 @@ save_one_text(void)
sync_state = sync_error; sync_state = sync_error;
return; return;
} }
fclose (file_b); i_fclose (file_b);
file_b = NULL; file_b = NULL;
sync_state = sync_ready; sync_state = sync_ready;
...@@ -2378,12 +2379,12 @@ sync_part(void) ...@@ -2378,12 +2379,12 @@ sync_part(void)
case sync_error: case sync_error:
kom_log("sync: Error saving new file. Retrying.\n"); kom_log("sync: Error saving new file. Retrying.\n");
fclose(file_b); i_fclose(file_b);
file_b = NULL; file_b = NULL;
#ifdef FASTSAVE #ifdef FASTSAVE
if (file_b_r != NULL) if (file_b_r != NULL)
{ {
fclose(file_b_r); i_fclose(file_b_r);
file_b_r = NULL; file_b_r = NULL;
} }
#endif #endif
...@@ -2460,7 +2461,7 @@ init_cache(void) ...@@ -2460,7 +2461,7 @@ init_cache(void)
#ifdef LOGACCESSES #ifdef LOGACCESSES
if (param.logaccess_file) if (param.logaccess_file)
{ {
logfile = fopen(param.logaccess_file, "a"); logfile = i_fopen(param.logaccess_file, "a");
if (logfile) if (logfile)
kom_log("Logging db accesses to %s.\n", param.logaccess_file); kom_log("Logging db accesses to %s.\n", param.logaccess_file);
else else
...@@ -2487,7 +2488,7 @@ init_cache(void) ...@@ -2487,7 +2488,7 @@ init_cache(void)
datafile_version = -1; datafile_version = -1;
if ( (text_file = fopen(param.textfile_name, "a+b")) == NULL ) if ((text_file = i_fopen(param.textfile_name, "a+b")) == NULL)
{ {
restart_kom("%s \"%s\". errno = %d\n", restart_kom("%s \"%s\". errno = %d\n",
"ERROR: init_cache: can't open text file", "ERROR: init_cache: can't open text file",
...@@ -2496,7 +2497,7 @@ init_cache(void) ...@@ -2496,7 +2497,7 @@ init_cache(void)
if (is_clean(param.datafile_name)) if (is_clean(param.datafile_name))
{ {
if ((file_a = fopen(param.datafile_name, "rb")) == NULL) if ((file_a = i_fopen(param.datafile_name, "rb")) == NULL)
{ {
kom_log("WARNING: init_cache: can't open datafile.\n"); kom_log("WARNING: init_cache: can't open datafile.\n");
kom_errno = KOM_INTERNAL_ERROR; kom_errno = KOM_INTERNAL_ERROR;
...@@ -2508,7 +2509,7 @@ init_cache(void) ...@@ -2508,7 +2509,7 @@ init_cache(void)
} }
else if (is_clean(param.backupfile_name)) else if (is_clean(param.backupfile_name))
{ {
if ((file_a = fopen(param.backupfile_name, "rb")) == NULL) if ((file_a = i_fopen(param.backupfile_name, "rb")) == NULL)
{ {
kom_log("WARNING: init_cache: can't open backupfile.\n"); kom_log("WARNING: init_cache: can't open backupfile.\n");
kom_errno = KOM_INTERNAL_ERROR; kom_errno = KOM_INTERNAL_ERROR;
...@@ -2760,7 +2761,7 @@ free_all_cache (void) ...@@ -2760,7 +2761,7 @@ free_all_cache (void)
#ifdef LOGACCESSES #ifdef LOGACCESSES
if (logfile) if (logfile)
fclose(logfile); i_fclose(logfile);
#endif #endif
for ( i = 1; i < next_free_num; i++ ) for ( i = 1; i < next_free_num; i++ )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment