Module Name:    src
Committed By:   rillig
Date:           Sat May 25 21:34:38 UTC 2024

Modified Files:
        src/usr.bin/make: job.c meta.c

Log Message:
make: replace magic numbers with POSIX FILENO constants

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.473 -r1.474 src/usr.bin/make/job.c
cvs rdiff -u -r1.208 -r1.209 src/usr.bin/make/meta.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.473 src/usr.bin/make/job.c:1.474
--- src/usr.bin/make/job.c:1.473	Sat May 25 21:07:48 2024
+++ src/usr.bin/make/job.c	Sat May 25 21:34:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.473 2024/05/25 21:07:48 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.474 2024/05/25 21:34:38 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -141,7 +141,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.473 2024/05/25 21:07:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.474 2024/05/25 21:34:38 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1456,11 +1456,11 @@ JobExec(Job *job, char **argv)
 		 * was marked close-on-exec, we must clear that bit in the
 		 * new input.
 		 */
-		if (dup2(fileno(job->cmdFILE), 0) == -1)
+		if (dup2(fileno(job->cmdFILE), STDIN_FILENO) == -1)
 			execDie("dup2", "job->cmdFILE");
-		if (fcntl(0, F_SETFD, 0) == -1)
+		if (fcntl(STDIN_FILENO, F_SETFD, 0) == -1)
 			execDie("fcntl clear close-on-exec", "stdin");
-		if (lseek(0, 0, SEEK_SET) == -1)
+		if (lseek(STDIN_FILENO, 0, SEEK_SET) == -1)
 			execDie("lseek to 0", "stdin");
 
 		if (job->node->type & (OP_MAKE | OP_SUBMAKE)) {
@@ -1477,18 +1477,18 @@ JobExec(Job *job, char **argv)
 		 * Set up the child's output to be routed through the pipe
 		 * we've created for it.
 		 */
-		if (dup2(job->outPipe, 1) == -1)
+		if (dup2(job->outPipe, STDOUT_FILENO) == -1)
 			execDie("dup2", "job->outPipe");
 
 		/*
 		 * The output channels are marked close on exec. This bit
-		 * was duplicated by the dup2(on some systems), so we have
+		 * was duplicated by dup2 (on some systems), so we have
 		 * to clear it before routing the shell's error output to
 		 * the same place as its standard output.
 		 */
-		if (fcntl(1, F_SETFD, 0) == -1)
+		if (fcntl(STDOUT_FILENO, F_SETFD, 0) == -1)
 			execDie("clear close-on-exec", "stdout");
-		if (dup2(1, 2) == -1)
+		if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
 			execDie("dup2", "1, 2");
 
 		/*

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.208 src/usr.bin/make/meta.c:1.209
--- src/usr.bin/make/meta.c:1.208	Sat Apr 27 17:33:46 2024
+++ src/usr.bin/make/meta.c	Sat May 25 21:34:38 2024
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.208 2024/04/27 17:33:46 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.209 2024/05/25 21:34:38 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1643,7 +1643,8 @@ void
 meta_compat_child(void)
 {
     meta_job_child(NULL);
-    if (dup2(childPipe[1], 1) < 0 || dup2(1, 2) < 0)
+    if (dup2(childPipe[1], STDOUT_FILENO) < 0
+	    || dup2(STDOUT_FILENO, STDERR_FILENO) < 0)
 	execDie("dup2", "pipe");
 }
 

Reply via email to