[PATCH 1/2] Remove insane *_FILENO and EXIT_* usage

From: FRIGN <dev_AT_frign.de>
Date: Wed, 8 Jul 2015 23:49:25 +0200

Any system having different assignments than the usual 0, 1, 2 for
the standard file numbers and 0, 1 for the exit-statuses is broken
beyond repair.
Let's keep it simple and just use the numbers, no reason to fall
out of the window here and bend down for POSIX.
In one occasion, the ret-variable was not necessary. The check was
rewritten.
---
 st.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/st.c b/st.c
index b89d094..46c0b6e 100644
--- a/st.c
+++ b/st.c
_AT_@ -513,7 +513,7 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
-static int iofd = STDOUT_FILENO;
+static int iofd = 1;
 static char **opt_cmd = NULL;
 static char *opt_io = NULL;
 static char *opt_title = NULL;
_AT_@ -1207,7 +1207,7 @@ die(const char *errstr, ...) {
 	va_start(ap, errstr);
 	vfprintf(stderr, errstr, ap);
 	va_end(ap);
-	exit(EXIT_FAILURE);
+	exit(1);
 }
 
 void
_AT_@ -1256,12 +1256,12 @@ execsh(void) {
 	signal(SIGALRM, SIG_DFL);
 
 	execvp(prog, args);
-	_exit(EXIT_FAILURE);
+	_exit(1);
 }
 
 void
 sigchld(int a) {
-	int stat, ret;
+	int stat;
 	pid_t p;
 
 	if((p = waitpid(pid, &stat, WNOHANG)) < 0)
_AT_@ -1270,10 +1270,9 @@ sigchld(int a) {
 	if(pid != p)
 		return;
 
-	ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
-	if (ret != EXIT_SUCCESS)
+	if (!WIFEXITED(stat) || WEXITSTATUS(stat))
 		die("child finished with error '%d'\n", stat);
-	exit(EXIT_SUCCESS);
+	exit(0);
 }
 
 
_AT_@ -1309,8 +1308,7 @@ ttynew(void) {
 	if(opt_io) {
 		term.mode |= MODE_PRINT;
 		iofd = (!strcmp(opt_io, "-")) ?
-			  STDOUT_FILENO :
-			  open(opt_io, O_WRONLY | O_CREAT, 0666);
+			  1 : open(opt_io, O_WRONLY | O_CREAT, 0666);
 		if(iofd < 0) {
 			fprintf(stderr, "Error opening %s:%s\n",
 				opt_io, strerror(errno));
_AT_@ -1320,7 +1318,7 @@ ttynew(void) {
 	if (opt_line) {
 		if((cmdfd = open(opt_line, O_RDWR)) < 0)
 			die("open line failed: %s\n", strerror(errno));
-		close(STDIN_FILENO);
+		close(0);
 		dup(cmdfd);
 		stty();
 		return;
_AT_@ -1337,9 +1335,9 @@ ttynew(void) {
 	case 0:
 		close(iofd);
 		setsid(); /* create a new process group */
-		dup2(s, STDIN_FILENO);
-		dup2(s, STDOUT_FILENO);
-		dup2(s, STDERR_FILENO);
+		dup2(s, 0);
+		dup2(s, 1);
+		dup2(s, 2);
 		if(ioctl(s, TIOCSCTTY, NULL) < 0)
 			die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
 		close(s);
_AT_@ -3871,7 +3869,7 @@ cmessage(XEvent *e) {
 	} else if(e->xclient.data.l[0] == xw.wmdeletewin) {
 		/* Send SIGHUP to shell */
 		kill(pid, SIGHUP);
-		exit(EXIT_SUCCESS);
+		exit(0);
 	}
 }
 
-- 
1.8.5.5
--Multipart=_Thu__9_Jul_2015_00_00_40_+0200_.tv8=7PY69q9j7xt
Content-Type: text/x-diff;
 name="0002-Unboolify-st.patch"
Content-Disposition: attachment;
 filename="0002-Unboolify-st.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 09 2015 - 08:00:10 CEST