about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-06-29 19:01:31 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-06-29 19:01:31 +0100
commit7708849b2186ce60e80e0dbc9ade89ad7404499e (patch)
tree2b5f1d4025e63fd5e8c339930811c564130c52ae
parent7bc47c91e92cc6642e6dd416c4f94fb22bc6309c (diff)
downloadzsh-7708849b2186ce60e80e0dbc9ade89ad7404499e.tar.gz
zsh-7708849b2186ce60e80e0dbc9ade89ad7404499e.tar.xz
zsh-7708849b2186ce60e80e0dbc9ade89ad7404499e.zip
35655: APPEND_CREATE option for POSIX copmatible NO_CLOBBER
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/options.yo25
-rw-r--r--Src/exec.c3
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
5 files changed, 31 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index c37b78ed9..faa0f777b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-06-29  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 35655: Doc/Zsh/options.yo, Src/exec.c, Src/options.c,
+	Src/zsh.h: APPEND_CREATE option gives POSIX compatible behaviour
+	for NO_CLOBBER.
+
 2015-06-28  Barton E. Schaefer  <schaefer@zsh.org>
 
 	* 35660: Functions/Prompts/prompt_adam1_setup: avoid perl, fix help
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 2371e358c..833c9755e 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1094,10 +1094,12 @@ pindex(NOCLOBBER)
 cindex(clobbering, of files)
 cindex(file clobbering, allowing)
 item(tt(CLOBBER) (tt(PLUS()C), ksh: tt(PLUS()C)) <D>)(
-Allows `tt(>)' redirection to truncate existing files,
-and `tt(>>)' to create files.
-Otherwise `tt(>!)' or `tt(>|)' must be used to truncate a file,
-and `tt(>>!)' or `tt(>>|)' to create a file.
+Allows `tt(>)' redirection to truncate existing files.
+Otherwise `tt(>!)' or `tt(>|)' must be used to truncate a file.
+
+If the option is not set, and the option tt(APPEND_CREATE) is also
+not set, `tt(>>!)' or `tt(>>|)' must be used to create a file.
+If either option is set, `tt(>>)' may be used.
 )
 pindex(CORRECT)
 pindex(NO_CORRECT)
@@ -1792,6 +1794,21 @@ enditem()
 
 subsect(Shell Emulation)
 startitem()
+pindex(APPEND_CREATE
+pindex(NO_APPEND_CREATE)
+pindex(APPENDCREATE)
+pindex(NOAPPENDCREATE)
+cindex(clobbering, POSIX compatibility)
+cindex(file clobbering, POSIX compatibility)
+cindex(no clobber, POSIX compatible)
+item(tt(APPEND_CREATE) <K> <S>)(
+This option only applies when tt(NO_CLOBBER) (-tt(C)) is in effect.
+
+If this option is not set, the shell will report an error when a
+append redirection (tt(>>)) is used on a file that does not already
+exists (the traditional zsh behaviour of tt(NO_CLOBBER)).  If the option
+is set, no error is reported (POSIX behaviour).
+)
 pindex(BASH_REMATCH)
 pindex(NO_BASH_REMATCH)
 pindex(BASHREMATCH)
diff --git a/Src/exec.c b/Src/exec.c
index 39d132647..960601f29 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3315,7 +3315,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    fil = -1;
 		else if (IS_APPEND_REDIR(fn->type))
 		    fil = open(unmeta(fn->name),
-			       (unset(CLOBBER) && !IS_CLOBBER_REDIR(fn->type)) ?
+			       ((unset(CLOBBER) && unset(APPENDCREATE)) &&
+				!IS_CLOBBER_REDIR(fn->type)) ?
 			       O_WRONLY | O_APPEND | O_NOCTTY :
 			       O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, 0666);
 		else
diff --git a/Src/options.c b/Src/options.c
index da3d8308a..1fb102f1d 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -81,6 +81,7 @@ static struct optname optns[] = {
 {{NULL, "allexport",	      OPT_EMULATE},		 ALLEXPORT},
 {{NULL, "alwayslastprompt",   OPT_ALL},			 ALWAYSLASTPROMPT},
 {{NULL, "alwaystoend",	      0},			 ALWAYSTOEND},
+{{NULL, "appendcreate",	      OPT_EMULATE|OPT_BOURNE},	 APPENDCREATE},
 {{NULL, "appendhistory",      OPT_ALL},			 APPENDHISTORY},
 {{NULL, "autocd",	      OPT_EMULATE},		 AUTOCD},
 {{NULL, "autocontinue",	      0},			 AUTOCONTINUE},
diff --git a/Src/zsh.h b/Src/zsh.h
index ce9b97903..183620f93 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2120,6 +2120,7 @@ enum {
     CHASELINKS,
     CHECKJOBS,
     CLOBBER,
+    APPENDCREATE,
     COMBININGCHARS,
     COMPLETEALIASES,
     COMPLETEINWORD,