summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h1
-rw-r--r--src/ical.c4
-rw-r--r--src/io.c16
-rw-r--r--src/note.c4
4 files changed, 4 insertions, 21 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index c1ca2ef..4dc5968 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -936,7 +936,6 @@ void io_set_lock(void);
unsigned io_dump_pid(char *);
unsigned io_get_pid(char *);
int io_files_equal(const char *, const char *);
-int io_file_is_empty(char *);
int io_file_cp(const char *, const char *);
void io_unset_modified(void);
void io_set_modified(void);
diff --git a/src/ical.c b/src/ical.c
index 2ce378c..160afc2 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -213,8 +213,10 @@ static void ical_export_note(FILE *stream, char *name)
int has_desc, has_prop, i;
asprintf(&note_file, "%s/%s", path_notes, name);
- if (!(fp = fopen(note_file, "r")))
+ if (!(fp = fopen(note_file, "r")) || ungetc(getc(fp), fp) == EOF) {
+ fclose(fp);
return;
+ }
string_init(&note);
while (fgets(lbuf, BUFSIZ, fp))
string_catf(&note, "%s", lbuf);
diff --git a/src/io.c b/src/io.c
index cd9b389..ff61dae 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1579,22 +1579,6 @@ unsigned io_get_pid(char *file)
}
/*
- * Check whether a file is empty.
- */
-int io_file_is_empty(char *file)
-{
- FILE *fp;
- int ret = -1;
-
- if (file && (fp = fopen(file, "r"))) {
- ret = (fgetc(fp) == '\n' && fgetc(fp) == EOF) || feof(fp);
- fclose(fp);
- }
-
- return ret;
-}
-
-/*
* Check whether two files are equal.
*/
int io_files_equal(const char *file1, const char *file2)
diff --git a/src/note.c b/src/note.c
index 40e0882..4f20d9d 100644
--- a/src/note.c
+++ b/src/note.c
@@ -94,9 +94,7 @@ void edit_note(char **note, const char *editor)
const char *arg[] = { editor, tmppath, NULL };
wins_launch_external(arg);
- if (io_file_is_empty(tmppath) > 0) {
- erase_note(note);
- } else if ((fp = fopen(tmppath, "r"))) {
+ if ((fp = fopen(tmppath, "r"))) {
sha1_stream(fp, sha1);
fclose(fp);
*note = sha1;