about summary refs log tree commit diff
path: root/Src/Modules/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Modules/system.c')
-rw-r--r--Src/Modules/system.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index ecd4e2546..929a8b002 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -74,6 +74,8 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
     int infd = 0, outfd = -1, bufsize = SYSREAD_BUFSIZE, count;
     char *outvar = NULL, *countvar = NULL, *inbuf;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -i: input file descriptor if not stdin */
     if (OPT_ISSET(ops, 'i')) {
 	infd = getposint(OPT_ARG(ops, 'i'), nam);
@@ -83,10 +85,6 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
 
     /* -o: output file descriptor, else store in REPLY */
     if (OPT_ISSET(ops, 'o')) {
-	if (*args) {
-	    zwarnnam(nam, "no argument allowed with -o");
-	    return 1;
-	}
 	outfd = getposint(OPT_ARG(ops, 'o'), nam);
 	if (outfd < 0)
 	    return 1;
@@ -242,6 +240,8 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
     int outfd = 1, len, count, totcount;
     char *countvar = NULL;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -o: output file descriptor if not stdout */
     if (OPT_ISSET(ops, 'o')) {
 	outfd = getposint(OPT_ARG(ops, 'o'), nam);
@@ -280,7 +280,7 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
 }
 
 
-static struct { char *name; int oflag; } openopts[] = {
+static struct { const char *name; int oflag; } openopts[] = {
 #ifdef O_CLOEXEC
     { "cloexec", O_CLOEXEC },
 #else
@@ -297,6 +297,9 @@ static struct { char *name; int oflag; } openopts[] = {
 #ifdef O_NOATIME
     { "noatime", O_NOATIME },
 #endif
+#ifdef O_NONBLOCK
+    { "nonblock", O_NONBLOCK},
+#endif
     { "excl", O_EXCL | O_CREAT },
     { "creat", O_CREAT },
     { "create", O_CREAT },
@@ -304,6 +307,13 @@ static struct { char *name; int oflag; } openopts[] = {
     { "trunc", O_TRUNC }
 };
 
+/*
+ * Return values of bin_sysopen:
+ *	0	Success
+ *	1	Error in parameters to command
+ *	2	Error on open, ERRNO set by system
+ */
+
 /**/
 static int
 bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
@@ -320,6 +330,8 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
     int fdflags = 0;
 #endif
 
+    errno = 0;	/* Distinguish non-system errors */
+
     if (!OPT_ISSET(ops, 'u')) {
 	zwarnnam(nam, "file descriptor not specified");
 	return 1;
@@ -375,12 +387,12 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
 
     if (fd == -1) {
 	zwarnnam(nam, "can't open file %s: %e", *args, errno);
-	return 1;
+	return 2;
     }
     moved_fd = (explicit > -1) ? redup(fd, explicit) : movefd(fd);
     if (moved_fd == -1) {
 	zwarnnam(nam, "can't open file %s", *args);
-	return 1;
+	return 2;
     }
 
 #ifdef FD_CLOEXEC
@@ -424,6 +436,8 @@ bin_sysseek(char *nam, char **args, Options ops, UNUSED(int func))
     char *whence;
     off_t pos;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -u:  file descriptor if not stdin */
     if (OPT_ISSET(ops, 'u')) {
 	fd = getposint(OPT_ARG(ops, 'u'), nam);