aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorFrederic Culot <calcurse@culot.org>2009-07-27 21:00:41 +0000
committerFrederic Culot <calcurse@culot.org>2009-07-27 21:00:41 +0000
commit4f0c71585d9dfe09060ee750a6528c44ddd2c1b9 (patch)
treeed3ac0c2dbbcfd15e92d4487dc74d18159f58ba3 /src/io.c
parentb45a8bfbb454160e8e4a2f4925a0c1ad27ef92c2 (diff)
downloadcalcurse-4f0c71585d9dfe09060ee750a6528c44ddd2c1b9.tar.gz
calcurse-4f0c71585d9dfe09060ee750a6528c44ddd2c1b9.zip
io_file_exist(): new function
Diffstat (limited to 'src/io.c')
-rwxr-xr-xsrc/io.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/io.c b/src/io.c
index ed4266f..094042b 100755
--- a/src/io.c
+++ b/src/io.c
@@ -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)++;
}
-void
-io_check_file (char *file, int *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)
+{
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__);
}
/*