Commit 97591009 authored by Per Cederqvist's avatar Per Cederqvist

(get_version, is_clean, cache_sync_all, cache_open_new_text_file)

(init_cache): Use i_fopen, i_fclose and i_rename instead of fopen,
	fclose and rename.
parent 87b6f091
/*
* $Id: dbck-cache.c,v 0.51 2002/09/06 22:42:37 ceder Exp $
* $Id: dbck-cache.c,v 0.52 2002/10/31 09:31:00 ceder Exp $
* Copyright (C) 1991-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -75,6 +75,7 @@
#include "dbck-cache.h"
#include "local-to-global.h"
#include "unused.h"
#include "eintr.h"
/*
* All functions that can fail sets kom_errno to a suitable value
......@@ -500,17 +501,17 @@ get_version(const char *fn)
char c;
long version;
if ( (fp = fopen(fn, "rb")) == NULL)
if ((fp = i_fopen(fn, "rb")) == NULL)
return -1;
fseek(fp, 5, SEEK_SET);
if ( (c = getc(fp)) == '\n')
{
fclose(fp);
i_fclose(fp);
return 0;
}
version = fparse_long(fp);
fclose(fp);
i_fclose(fp);
return version;
}
......@@ -521,7 +522,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' &&
......@@ -530,12 +531,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;
}
}
......@@ -596,20 +597,20 @@ cache_sync_all(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)
kom_log("WARNING: cache_sync_all: can't backup.\n");
}
else
kom_log("cache_sync_all: datafile not clean. No backup taken.\n");
if ( (fp=fopen(param.datafile_name, "w") ) == NULL )
if ((fp = i_fopen(param.datafile_name, "w")) == NULL)
{
kom_log("WARNING: cache_sync_all: can't open file to save in.\n");
return;
......@@ -782,7 +783,7 @@ cache_sync_all(void)
rewind(fp);
sync_output_header(fp, "CLEAN", oformat);
fclose(fp);
i_fclose(fp);
#ifdef TIME_SYNC
kom_log("Sync ready.\n"
......@@ -818,7 +819,7 @@ cache_sync_all(void)
void
cache_open_new_text_file(void)
{
if ( ( new_text_file = fopen(param.textfile_name, "w")) == NULL )
if ((new_text_file = i_fopen(param.textfile_name, "w")) == NULL)
{
kom_log("Can't open file to save new texts. Goodbye.\n");
exit(1);
......@@ -861,7 +862,7 @@ init_cache(void)
new_text_file = NULL;
if ( (text_file = fopen(param.textfile_name, "rb")) == NULL )
if ((text_file = i_fopen(param.textfile_name, "rb")) == NULL)
{
perror(param.textfile_name);
restart_kom("ERROR: init_cache: can't open text file %s.\n",
......@@ -871,7 +872,7 @@ init_cache(void)
if ( is_clean(param.datafile_name) )
{
data_file_version = get_version(param.datafile_name);
if ( (fp = fopen(param.datafile_name, "rb")) == NULL )
if ((fp = i_fopen(param.datafile_name, "rb")) == NULL)
{
kom_log("WARNING: init_cache: can't open datafile.\n");
return FAILURE;
......@@ -881,7 +882,7 @@ init_cache(void)
else if ( is_clean(param.backupfile_name) )
{
data_file_version = get_version(param.backupfile_name);
if ( (fp = fopen(param.backupfile_name, "rb")) == NULL )
if ((fp = i_fopen(param.backupfile_name, "rb")) == NULL)
{
kom_log("WARNING: init_cache: can't open backupfile.\n");
return FAILURE;
......@@ -1300,7 +1301,7 @@ init_cache(void)
if (read_text_num == 0 || read_conf_num == 0)
restart_kom("init_cache(): Failed to read next_conf or text num.\n");
fclose(fp);
i_fclose(fp);
return OK;
}
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