summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2002-02-04 19:38:40 +0000
committerBart Schaefer <barts@users.sourceforge.net>2002-02-04 19:38:40 +0000
commitc6d589aadd706b366b5207ac155f83510e5c408e (patch)
tree2f90c87ad16c97fea69847994ccc92bf2f0a5751
parent8db461b8e464c6abdee36a71a26d0af97bb4ef59 (diff)
downloadzsh-c6d589aadd706b366b5207ac155f83510e5c408e.tar.gz
zsh-c6d589aadd706b366b5207ac155f83510e5c408e.tar.xz
zsh-c6d589aadd706b366b5207ac155f83510e5c408e.zip
16556: No error on `print >&-'.
-rw-r--r--ChangeLog5
-rw-r--r--Src/builtin.c27
2 files changed, 22 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f05eb32e..8c492e92c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-02-04  Bart Schaefer  <schaefer@zsh.org>
+
+	* 16556: Src/builtin.c: Error messages added in 16503 should not
+	change the behavior of >&- redirections.
+
 2002-02-04  Clint Adams  <clint@zsh.org>
 
 	* 16553, 16555: Completion/Unix/Command/_ssh: differentiate
diff --git a/Src/builtin.c b/Src/builtin.c
index 6725b6043..3ae18a907 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3074,10 +3074,12 @@ bin_print(char *name, char **args, char *ops, int func)
 	    } while (*ap);
 	    fputc(ops['N'] ? '\0' : '\n', fout);
 	}
-	if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) {
+	/* Testing EBADF special-cases >&- redirections */
+	if ((fout != stdout) ? (fclose(fout) != 0) :
+	    (fflush(fout) != 0 && errno != EBADF)) {
             zwarnnam(name, "write error: %e", NULL, errno);
             ret = 1;
-        }
+	}
 	return ret;
     }
     
@@ -3090,11 +3092,12 @@ bin_print(char *name, char **args, char *ops, int func)
 	}
 	if (!(ops['n'] || nnl))
 	    fputc(ops['N'] ? '\0' : '\n', fout);
-	if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) {
+	/* Testing EBADF special-cases >&- redirections */
+	if ((fout != stdout) ? (fclose(fout) != 0) :
+	    (fflush(fout) != 0 && errno != EBADF)) {
             zwarnnam(name, "write error: %e", NULL, errno);
             ret = 1;
 	}
-	
 	return ret;
     }
     
@@ -3279,9 +3282,11 @@ bin_print(char *name, char **args, char *ops, int func)
 		}
 		zwarnnam(name, "%s: invalid directive", start, 0);
 		if (*c) c[1] = save;
-		if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) {
-	            zwarnnam(name, "write error: %e", NULL, errno);
-	        }
+		/* Testing EBADF special-cases >&- redirections */
+		if ((fout != stdout) ? (fclose(fout) != 0) :
+		    (fflush(fout) != 0 && errno != EBADF)) {
+		    zwarnnam(name, "write error: %e", NULL, errno);
+		}
 		return 1;
 	    }
 
@@ -3345,9 +3350,11 @@ bin_print(char *name, char **args, char *ops, int func)
 	/* if there are remaining args, reuse format string */
     } while (*args && args != first && !ops['r']);
 
-    if (((fout != stdout) ? fclose(fout) : fflush(fout)) != 0) {
-        zwarnnam(name, "write error: %e", NULL, errno);
-        ret = 1;
+    /* Testing EBADF special-cases >&- redirections */
+    if ((fout != stdout) ? (fclose(fout) != 0) :
+	(fflush(fout) != 0 && errno != EBADF)) {
+	zwarnnam(name, "write error: %e", NULL, errno);
+	ret = 1;
     }
     return ret;
 }