commit 10d6bf2f4d73f2712a058327885aca19a44cee02
parent 2d45a04b92df641158ca400873a522fede1d9a01
Author: sin <sin@2f30.org>
Date:   Sun, 30 Nov 2014 13:12:15 +0000
Stop using *_FILENO
Diffstat:
9 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/dmesg.c b/dmesg.c
@@ -60,7 +60,7 @@ main(int argc, char *argv[])
 	if (n < 0)
 		eprintf("klogctl:");
 
-	dmesg_show(STDOUT_FILENO, buf, n);
+	dmesg_show(1, buf, n);
 
 	if (cflag && klogctl(SYSLOG_ACTION_CLEAR, NULL, 0) < 0)
 		eprintf("klogctl:");
diff --git a/getty.c b/getty.c
@@ -73,9 +73,9 @@ main(int argc, char *argv[])
 	fd = open(tty, O_RDWR);
 	if (fd < 0)
 		eprintf("open %s:", tty);
-	dup2(fd, STDIN_FILENO);
-	dup2(fd, STDOUT_FILENO);
-	dup2(fd, STDERR_FILENO);
+	dup2(fd, 0);
+	dup2(fd, 1);
+	dup2(fd, 2);
 	if (fchown(fd, 0, 0) < 0)
 		weprintf("fchown %s:", tty);
 	if (fchmod(fd, 0600) < 0)
@@ -118,10 +118,10 @@ main(int argc, char *argv[])
 	fflush(stdout);
 
 	/* Flush pending input */
-	ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+	ioctl(0, TCFLSH, (void *)0);
 	memset(logname, 0, sizeof(logname));
 	while (1) {
-		n = read(STDIN_FILENO, &c, 1);
+		n = read(0, &c, 1);
 		if (n < 0)
 			eprintf("read:");
 		if (n == 0)
diff --git a/login.c b/login.c
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
 	gid = pw->pw_gid;
 
 	/* Flush pending input */
-	ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+	ioctl(0, TCFLSH, (void *)0);
 
 	pass = getpass("Password: ");
 	if (!pass)
@@ -96,7 +96,7 @@ main(int argc, char *argv[])
 	if (pw_check(pw, pass) <= 0)
 		exit(1);
 
-	tty = ttyname(STDIN_FILENO);
+	tty = ttyname(0);
 	if (!tty)
 		eprintf("ttyname:");
 
diff --git a/mesg.c b/mesg.c
@@ -28,10 +28,10 @@ main(int argc, char *argv[])
 	if (argc > 1)
 		usage();
 
-	if (isatty(STDERR_FILENO) == 0)
+	if (isatty(2) == 0)
 		eprintf("stderr: not a tty\n");
 
-	if (fstat(STDERR_FILENO, &sb) < 0)
+	if (fstat(2, &sb) < 0)
 		eprintf("fstat stderr:");
 
 	if (argc == 0) {
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
 	else
 		usage();
 
-	if (fchmod(STDERR_FILENO, mode) < 0)
+	if (fchmod(2, mode) < 0)
 		eprintf("fchmod stderr:");
 
 	return 0;
diff --git a/passwd.c b/passwd.c
@@ -176,7 +176,7 @@ main(int argc, char *argv[])
 	}
 
 	/* Flush pending input */
-	ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+	ioctl(0, TCFLSH, (void *)0);
 
 	if (getuid() == 0) {
 		goto newpass;
@@ -220,7 +220,7 @@ newpass:
 		eprintf("password left unchanged\n");
 
 	/* Flush pending input */
-	ioctl(STDIN_FILENO, TCFLSH, (void *)0);
+	ioctl(0, TCFLSH, (void *)0);
 
 	inpass = getpass("Retype new password: ");
 	if (!inpass)
diff --git a/ps.c b/ps.c
@@ -104,7 +104,7 @@ psout(struct procstat *ps)
 	 * the same controlling terminal as the invoker and the same
 	 * euid as the current user */
 	if (!(flags & (PS_aflag | PS_Aflag | PS_dflag))) {
-		myttystr = ttyname(STDIN_FILENO);
+		myttystr = ttyname(0);
 		if (myttystr) {
 			if (strcmp(myttystr + strlen("/dev/"), ttystr)) {
 				free(ttystr);
@@ -125,7 +125,7 @@ psout(struct procstat *ps)
 
 	sutime = (ps->stime + ps->utime) / sysconf(_SC_CLK_TCK);
 
-	ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
+	ioctl(1, TIOCGWINSZ, &w);
 	if (!(flags & PS_fflag)) {
 		snprintf(buf, sizeof(buf), "%5d %-6s   %02u:%02u:%02u %s", ps->pid, ttystr,
 			 sutime / 3600, (sutime % 3600) / 60, sutime % 60,
diff --git a/stat.c b/stat.c
@@ -41,7 +41,7 @@ main(int argc, char *argv[])
 	} ARGEND;
 
 	if (argc == 0) {
-		if (fstat(STDIN_FILENO, &st) < 0)
+		if (fstat(0, &st) < 0)
 			eprintf("stat <stdin>:");
 		show_stat("<stdin>", &st);
 	}
diff --git a/switch_root.c b/switch_root.c
@@ -117,13 +117,11 @@ main(int argc, char *argv[])
 
 	/* if -c is set, redirect stdin/stdout/stderr to console */
 	if (console) {
-		close(STDIN_FILENO);
+		close(0);
 		if (open(console, O_RDWR) == -1)
 			eprintf("open %s:", console);
-		if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO)
-			eprintf("dup2 %s:", "stdin,stdout");
-		if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
-			eprintf("dup2 %s:", "stdin,stderr");
+		dup2(0, 1);
+		dup2(0, 2);
 	}
 
 	/* execute init */
diff --git a/who.c b/who.c
@@ -28,7 +28,7 @@ main(int argc, char *argv[])
 	ARGBEGIN {
 	case 'm':
 		mflag = 1;
-		tty = ttyname(STDIN_FILENO);
+		tty = ttyname(0);
 		if (!tty)
 			eprintf("ttyname: stdin:");
 		if ((ttmp = strrchr(tty, '/')))