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

(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.
*
* This file is part of the LysKOM server.
......@@ -87,6 +87,7 @@
#include "unused.h"
#include "local-to-global.h"
#include "server-time.h"
#include "eintr.h"
/*
* Possible improvements:
......@@ -1574,7 +1575,7 @@ is_clean(const char *fn)
{
FILE *fp;
if ( (fp = fopen(fn, "rb")) == NULL )
if ( (fp = i_fopen(fn, "rb")) == NULL )
return FALSE;
if ( getc(fp) == 'C' &&
......@@ -1583,12 +1584,12 @@ is_clean(const char *fn)
getc(fp) == 'A' &&
getc(fp) == 'N' )
{
fclose(fp);
i_fclose(fp);
return TRUE;
}
else
{
fclose(fp);
i_fclose(fp);
return FALSE;
}
}
......@@ -1600,17 +1601,17 @@ get_version(const char *fn)
FILE *fp;
long version;
if ( (fp = fopen(fn, "rb")) == NULL)
if ((fp = i_fopen(fn, "rb")) == NULL)
return -1;
fseek(fp, 5, SEEK_SET);
if (getc(fp) == '\n')
{
fclose(fp);
i_fclose(fp);
return 0;
}
version = fparse_long(fp);
fclose(fp);
i_fclose(fp);
return version;
}
......@@ -1742,14 +1743,14 @@ pre_sync(void)
{
if (is_clean(param.backupfile_name))
{
if (rename(param.backupfile_name,
param.backupfile_name_2) != 0)
if (i_rename(param.backupfile_name,
param.backupfile_name_2) != 0)
{
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");
}
else
......@@ -1758,13 +1759,13 @@ pre_sync(void)
if ( file_b != NULL )
{
kom_log("pre_sync: Save in progress aborted.\n");
fclose(file_b);
i_fclose(file_b);
#ifdef FASTSAVE
file_b = NULL;
#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");
sync_state = sync_wait;
......@@ -1773,9 +1774,9 @@ pre_sync(void)
}
#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;
kom_log("WARNING: pre_sync: can't open file to save in for reading.\n");
sync_state = sync_wait;
......@@ -2065,9 +2066,9 @@ post_sync(void)
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");
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");
sync_state = sync_wait;
......@@ -2241,7 +2242,7 @@ save_one_text(void)
return;
}
if ( fclose(file_b) != 0 )
if (i_fclose(file_b) != 0)
{
file_b = NULL;
......@@ -2253,7 +2254,7 @@ save_one_text(void)
#ifdef FASTSAVE
if ( fclose(file_b_r) != 0 )
if (i_fclose(file_b_r) != 0)
{
file_b_r = NULL;
......@@ -2265,7 +2266,7 @@ save_one_text(void)
file_b_r = NULL;
#endif
file_b = fopen(param.datafile_name, "rb");
file_b = i_fopen(param.datafile_name, "rb");
if (file_b == NULL)
{
kom_log("save_one_text(): failed to reopen file.\n");
......@@ -2289,7 +2290,7 @@ save_one_text(void)
sync_state = sync_error;
return;
}
fclose (file_b);
i_fclose (file_b);
file_b = NULL;
sync_state = sync_ready;
......@@ -2378,12 +2379,12 @@ sync_part(void)
case sync_error:
kom_log("sync: Error saving new file. Retrying.\n");
fclose(file_b);
i_fclose(file_b);
file_b = NULL;
#ifdef FASTSAVE
if (file_b_r != NULL)
{
fclose(file_b_r);
i_fclose(file_b_r);
file_b_r = NULL;
}
#endif
......@@ -2460,7 +2461,7 @@ init_cache(void)
#ifdef LOGACCESSES
if (param.logaccess_file)
{
logfile = fopen(param.logaccess_file, "a");
logfile = i_fopen(param.logaccess_file, "a");
if (logfile)
kom_log("Logging db accesses to %s.\n", param.logaccess_file);
else
......@@ -2487,7 +2488,7 @@ init_cache(void)
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",
"ERROR: init_cache: can't open text file",
......@@ -2496,7 +2497,7 @@ init_cache(void)
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_errno = KOM_INTERNAL_ERROR;
......@@ -2508,7 +2509,7 @@ init_cache(void)
}
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_errno = KOM_INTERNAL_ERROR;
......@@ -2760,7 +2761,7 @@ free_all_cache (void)
#ifdef LOGACCESSES
if (logfile)
fclose(logfile);
i_fclose(logfile);
#endif
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