aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorGerd Moellmann2001-07-16 11:20:25 +0000
committerGerd Moellmann2001-07-16 11:20:25 +0000
commit8e4b384ede1be7af9576d87462fd1c91646b8154 (patch)
tree695f9c5841e5db9016d12f0c3247b7f494d0eb2c /lib-src
parent1b85bd12db1f6bf846fa05b56dfbb63ba3eb3a99 (diff)
downloademacs-8e4b384ede1be7af9576d87462fd1c91646b8154.tar.gz
emacs-8e4b384ede1be7af9576d87462fd1c91646b8154.zip
(main): Check that the output file exists and
is non-empty if invoked with `--append'.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ebrowse.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 90388273cec..29eff708325 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -3495,7 +3495,7 @@ open_file (file)
3495#define USAGE "\ 3495#define USAGE "\
3496Usage: ebrowse [options] {files}\n\ 3496Usage: ebrowse [options] {files}\n\
3497\n\ 3497\n\
3498 -a, --append append output\n\ 3498 -a, --append append output to existing file\n\
3499 -f, --files=FILES read input file names from FILE\n\ 3499 -f, --files=FILES read input file names from FILE\n\
3500 -I, --search-path=LIST set search path for input files\n\ 3500 -I, --search-path=LIST set search path for input files\n\
3501 -m, --min-regexp-length=N set minimum regexp length to N\n\ 3501 -m, --min-regexp-length=N set minimum regexp length to N\n\
@@ -3740,6 +3740,32 @@ main (argc, argv)
3740 /* Open output file */ 3740 /* Open output file */
3741 if (*out_filename) 3741 if (*out_filename)
3742 { 3742 {
3743 if (f_append)
3744 {
3745 /* Check that the file to append to exists, and is not
3746 empty. More specifically, it should be a valid file
3747 produced by a vaprevious run of ebrowse, but that's too
3748 difficult to check. */
3749 FILE *fp;
3750 int rc;
3751
3752 fp = fopen (out_filename, "r");
3753 if (fp == NULL)
3754 yyerror ("file `%s' must exist for --append", out_filename);
3755
3756 rc = fseek (fp, 0, SEEK_END);
3757 if (rc == -1)
3758 yyerror ("error seeking in file `%s'", out_filename);
3759
3760 rc = ftell (fp);
3761 if (rc == -1)
3762 yyerror ("error getting size of file `%s'", out_filename);
3763 else if (rc == 0)
3764 yyerror ("file `%s' is empty", out_filename);
3765
3766 fclose (fp);
3767 }
3768
3743 yyout = fopen (out_filename, f_append ? "a" : "w"); 3769 yyout = fopen (out_filename, f_append ? "a" : "w");
3744 if (yyout == NULL) 3770 if (yyout == NULL)
3745 { 3771 {