shithub: riscv

Download patch

ref: 9ccbf1dcb15a69dbe21a6767c137537f3a5863af
parent: ee68dedf53695895630fd9a463429a8d34a9679c
author: spew <devnull@localhost>
date: Sun May 1 16:54:46 EDT 2016

just use wait in "system" call for awk, get rid of unix dependent status code divisor

--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -62,11 +62,11 @@
 int
 system(const char *s)
 {
-	char status[512], *statfld[5];
-	int n, pid;
+	Waitmsg *status;
+	int pid;
 
-	if(!s)
-		return 1; /* a command interpreter is available */
+	if(s == nil)
+		return 1;
 	pid = fork();
 	if(pid == 0) {
 		execl("/bin/rc", "rc", "-c", s, nil);
@@ -76,17 +76,19 @@
 		return -1;
 	}
 	for(;;) {
-		n = await(status, sizeof(status) - 1);
-		status[n] = '\0';
-		if(n == -1)
-			return -1;
-		tokenize(status, statfld, nelem(statfld));
-		if(strtol(statfld[0], nil, 0) == pid)
+		status = wait();
+		if(status == nil)
+			FATAL("Out of memory");
+		if(status->pid == pid)
 			break;
+		free(status);
 	}
 
-	if(*statfld[4] != '\0')
+	if(status->msg[0] != '\0') {
+		free(status);
 		return 1;
+	}
+	free(status);
 	return 0;
 }
 
@@ -1582,7 +1584,7 @@
 		break;
 	case FSYSTEM:
 		Bflush(&stdout);		/* in case something is buffered already */
-		u = (Awkfloat) system(getsval(x)) / 256;   /* 256 is unix-dep */
+		u = (Awkfloat) system(getsval(x));
 		break;
 	case FRAND:
 		/* in principle, rand() returns something in 0..RAND_MAX */