Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Test failure in redirect.



On Jan 30, 10:41pm, Felix Rosencrantz wrote:
} Subject: Test failure in redirect.
}
}   print foo >&-
} Error output:
} (eval):print:1: write error: bad file descriptor

This is of course a result of the error-checking that Clint added to
bin_print().

--- ../zsh-forge/current/Src/builtin.c	Sun Jan 27 15:17:26 2002
+++ Src/builtin.c	Mon Feb  4 10:43:46 2002
@@ -3074,10 +3074,12 @@
 	    } 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 @@
 	}
 	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 @@
 		}
 		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 @@
 	/* 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;
 }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author