io_file_exist(): new function

This commit is contained in:
Frederic Culot 2009-07-27 21:00:41 +00:00
parent b45a8bfbb4
commit 4f0c71585d
2 changed files with 23 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.74 2009/07/26 20:26:15 culot Exp $ */
/* $calcurse: io.c,v 1.75 2009/07/27 21:00:41 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -1499,14 +1499,30 @@ check_directory (char *dir, int *missing)
(*missing)++;
}
unsigned
io_file_exist (char *file)
{
FILE *fd;
if (!file)
return 0;
if ((fd = fopen (file, "r")) == 0)
return 0;
(void)fclose (fd);
return 1;
}
void
io_check_file (char *file, int *missing)
{
FILE *fd;
errno = 0;
if ((fd = fopen (file, "r")) == NULL)
if (!io_file_exist (file))
{
FILE *fd;
if (missing)
(*missing)++;
if ((fd = fopen (file, "w")) == NULL)
@ -1515,8 +1531,8 @@ io_check_file (char *file, int *missing)
file, strerror (errno));
exit_calcurse (EXIT_FAILURE);
}
file_close (fd, __FILE_POS__);
}
file_close (fd, __FILE_POS__);
}
/*

View File

@ -1,4 +1,4 @@
/* $calcurse: io.h,v 1.25 2009/07/26 20:26:15 culot Exp $ */
/* $calcurse: io.h,v 1.26 2009/07/27 21:00:41 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -74,6 +74,7 @@ void io_save_cal (conf_t *, io_save_display_t);
void io_load_app (void);
void io_load_todo (void);
void io_load_keys (char *);
unsigned io_file_exist (char *);
void io_check_file (char *, int *);
int io_check_data_files (void);
void io_startup_screen (unsigned, int);