Prepend fixes for O_CREAT & append compatibililty by David Benbennick

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1191 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-04-21 23:15:36 +00:00
parent 0417a7b7f2
commit 2542274250
2 changed files with 7 additions and 7 deletions

View File

@ -11,6 +11,7 @@ CVS code -
- Preliminary prepend code. This may be a bad idea, but I've
been wanting it for awhile now and we'll see how bad it messes
everything up. Changes to files.c:do_writeout(), write_file().
Fixes for O_CREAT & append compatibililty by David Benbennick.
- configure.ac:
- Define NDEBUG to silence asserts (David Benbennick).
- files.c:

13
files.c
View File

@ -1243,7 +1243,7 @@ int write_file(char *name, int tmp, int append, int nonamechange)
/* Use O_EXCL if tmp == 1. This is now copied from joe, because
wiggy says so *shrug*. */
if (append)
fd = open(realname, O_WRONLY | O_APPEND, (S_IRUSR|S_IWUSR));
fd = open(realname, O_WRONLY | O_CREAT | O_APPEND, (S_IRUSR|S_IWUSR));
else if (tmp)
fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR));
else
@ -1350,8 +1350,9 @@ int write_file(char *name, int tmp, int append, int nonamechange)
statusbar(_("Could not reopen %s: %s"), buf, strerror(errno));
return -1;
}
if ((fd2 = open(realname, O_RDONLY)) == -1) {
statusbar(_("Could open %s for prepend: %s"), realname, strerror(errno));
if ((fd2 = open(realname, O_RDONLY | O_CREAT)) == -1) {
statusbar(_("Could not open %s for prepend: %s"), realname,
strerror(errno));
return -1;
}
@ -1510,11 +1511,9 @@ int do_writeout(char *path, int exiting, int append)
TOGGLE(MAC_FILE);
return(do_writeout(answer, exiting, append));
} else if (i == NANO_PREPEND_KEY)
return(do_writeout(answer, exiting, 2));
else if (i == NANO_APPEND_KEY && append != 1)
return(do_writeout(answer, exiting, 1));
return(do_writeout(answer, exiting, append==2 ? 0 : 2));
else if (i == NANO_APPEND_KEY)
return(do_writeout(answer, exiting, 0));
return(do_writeout(answer, exiting, append==1 ? 0 : 1));
#ifdef DEBUG
fprintf(stderr, _("filename is %s"), answer);