Commit 25422742 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

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
parent 0417a7b7
Showing with 7 additions and 7 deletions
+7 -7
...@@ -11,6 +11,7 @@ CVS code - ...@@ -11,6 +11,7 @@ CVS code -
- Preliminary prepend code. This may be a bad idea, but I've - 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 been wanting it for awhile now and we'll see how bad it messes
everything up. Changes to files.c:do_writeout(), write_file(). everything up. Changes to files.c:do_writeout(), write_file().
Fixes for O_CREAT & append compatibililty by David Benbennick.
- configure.ac: - configure.ac:
- Define NDEBUG to silence asserts (David Benbennick). - Define NDEBUG to silence asserts (David Benbennick).
- files.c: - files.c:
......
...@@ -1243,7 +1243,7 @@ int write_file(char *name, int tmp, int append, int nonamechange) ...@@ -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 /* Use O_EXCL if tmp == 1. This is now copied from joe, because
wiggy says so *shrug*. */ wiggy says so *shrug*. */
if (append) 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) else if (tmp)
fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR)); fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR));
else else
...@@ -1350,8 +1350,9 @@ int write_file(char *name, int tmp, int append, int nonamechange) ...@@ -1350,8 +1350,9 @@ int write_file(char *name, int tmp, int append, int nonamechange)
statusbar(_("Could not reopen %s: %s"), buf, strerror(errno)); statusbar(_("Could not reopen %s: %s"), buf, strerror(errno));
return -1; return -1;
} }
if ((fd2 = open(realname, O_RDONLY)) == -1) { if ((fd2 = open(realname, O_RDONLY | O_CREAT)) == -1) {
statusbar(_("Could open %s for prepend: %s"), realname, strerror(errno)); statusbar(_("Could not open %s for prepend: %s"), realname,
strerror(errno));
return -1; return -1;
} }
...@@ -1510,11 +1511,9 @@ int do_writeout(char *path, int exiting, int append) ...@@ -1510,11 +1511,9 @@ int do_writeout(char *path, int exiting, int append)
TOGGLE(MAC_FILE); TOGGLE(MAC_FILE);
return(do_writeout(answer, exiting, append)); return(do_writeout(answer, exiting, append));
} else if (i == NANO_PREPEND_KEY) } else if (i == NANO_PREPEND_KEY)
return(do_writeout(answer, exiting, 2)); return(do_writeout(answer, exiting, append==2 ? 0 : 2));
else if (i == NANO_APPEND_KEY && append != 1)
return(do_writeout(answer, exiting, 1));
else if (i == NANO_APPEND_KEY) else if (i == NANO_APPEND_KEY)
return(do_writeout(answer, exiting, 0)); return(do_writeout(answer, exiting, append==1 ? 0 : 1));
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("filename is %s"), answer); fprintf(stderr, _("filename is %s"), answer);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment