- files.c:open_file() - Fix FD leak with file load error (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1390 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2003-01-26 04:11:09 +00:00
parent 149781d827
commit 54c1f7932c
2 changed files with 12 additions and 12 deletions

View File

@ -9,6 +9,9 @@ CVS Code -
do_cut_text()
- Fix incorrect cursor location when cutting long lines
(David Benbennick).
- files.c:
open_file()
- Fix FD leak with file load error (David Benbennick).
- nano.c:
main()
- Call load_file with arg 0 for insert, as we aren't really

21
files.c
View File

@ -339,6 +339,14 @@ int open_file(const char *filename, int insert, int quiet)
statusbar(_("New File"));
new_file();
}
} else if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
/* Don't open character or block files. Sorry, /dev/sndstat! */
statusbar(S_ISDIR(fileinfo.st_mode) ? _("\"%s\" is a directory") :
_("File \"%s\" is a device file"), filename);
if (!insert)
new_file();
return -1;
} else if ((fd = open(filename, O_RDONLY)) == -1) {
/* If we're in multibuffer mode, don't be quiet when an error
occurs while opening a file */
@ -352,23 +360,12 @@ int open_file(const char *filename, int insert, int quiet)
new_file();
return -1;
} else { /* File is A-OK */
if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
if (S_ISDIR(fileinfo.st_mode))
statusbar(_("\"%s\" is a directory"), filename);
else
/* Don't open character or block files. Sorry, /dev/sndstat! */
statusbar(_("File \"%s\" is a device file"), filename);
if (!insert)
new_file();
return -1;
}
if (!quiet)
statusbar(_("Reading File"));
f = fdopen(fd, "rb"); /* Binary for our own line-end munging */
if (f == NULL) {
nperror("fdopen");
close(fd);
return -1;
}
read_file(f, filename, quiet);