Drop empty notes after editing.
Keeping empty notes doesn't make sense here. Also, there doesn't seem to be a simple way to erase notes yet. This will make calcurse delete any notes that are empty (meaning that they are either 0-byte files or contain nothing but a newline character) when returning from the editor. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
25
src/io.c
25
src/io.c
@@ -3040,3 +3040,28 @@ io_get_pid (char *file)
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether a file is empty.
|
||||
*/
|
||||
int
|
||||
io_file_is_empty (char *file)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if (file && (fp = fopen (file, "r")))
|
||||
{
|
||||
if (fgetc (fp) == '\n' || feof (fp))
|
||||
{
|
||||
fclose (fp);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user