From: Chris Allegretta Date: Sun, 21 Apr 2002 23:15:36 +0000 (+0000) Subject: Prepend fixes for O_CREAT & append compatibililty by David Benbennick X-Git-Tag: v1.1.9~20 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=25422742500336338b03e81876c15f90f17fbe0c;p=nano.git 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 --- diff --git a/ChangeLog b/ChangeLog index f5f814df..d3b784e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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: diff --git a/files.c b/files.c index 1617b0d9..d3f4614b 100644 --- a/files.c +++ b/files.c @@ -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);