Module Name:    src
Committed By:   rillig
Date:           Sun Nov  8 09:34:55 UTC 2020

Modified Files:
        src/usr.bin/make: dir.c dir.h job.c make.c

Log Message:
make(1): change return type of Dir_MTime to void

Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/usr.bin/make/dir.c
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/make/dir.h
cvs rdiff -u -r1.314 -r1.315 src/usr.bin/make/job.c
cvs rdiff -u -r1.193 -r1.194 src/usr.bin/make/make.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/dir.c
diff -u src/usr.bin/make/dir.c:1.200 src/usr.bin/make/dir.c:1.201
--- src/usr.bin/make/dir.c:1.200	Sun Nov  8 09:15:19 2020
+++ src/usr.bin/make/dir.c	Sun Nov  8 09:34:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.200 2020/11/08 09:15:19 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.201 2020/11/08 09:34:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -100,9 +100,9 @@
  *			then all the directories above it in turn until
  *			the path is found or we reach the root ("/").
  *
- *	Dir_MTime	Return the modification time of a node. The file
- *			is searched for along the default search path.
- *			The path and mtime fields of the node are filled in.
+ *	Dir_UpdateMTime
+ *			Update the modification time and path of a node with
+ *			data from the file corresponding to the node.
  *
  *	Dir_AddDir	Add a directory to a search path.
  *
@@ -134,7 +134,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.200 2020/11/08 09:15:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.201 2020/11/08 09:34:55 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -204,7 +204,7 @@ MAKE_RCSID("$NetBSD: dir.c,v 1.200 2020/
  * Given that an access() is essentially a stat() without the copyout() call,
  * and that the same filesystem overhead would have to be incurred in
  * Dir_MTime, it made sense to replace the access() with a stat() and record
- * the mtime in a cache for when Dir_MTime was actually called.
+ * the mtime in a cache for when Dir_UpdateMTime was actually called.
  */
 
 typedef List CachedDirList;
@@ -1276,26 +1276,12 @@ Dir_FindHereOrAbove(const char *here, co
     return NULL;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Dir_MTime  --
- *	Find the modification time of the file described by gn along the
- *	search path dirSearchPath.
- *
- * Input:
- *	gn		the file whose modification time is desired
+/* Search gn along dirSearchPath and store its modification time in gn->mtime.
+ * If no file is found, store 0 instead.
  *
- * Results:
- *	The modification time or 0 if it doesn't exist
- *
- * Side Effects:
- *	The modification time is placed in the node's mtime slot.
- *	If the node didn't have a path entry before, and Dir_FindFile
- *	found one for it, the full name is placed in the path slot.
- *-----------------------------------------------------------------------
- */
-time_t
-Dir_MTime(GNode *gn, Boolean recheck)
+ * The found file is stored in gn->path, unless the node already had a path. */
+void
+Dir_UpdateMTime(GNode *gn, Boolean recheck)
 {
     char *fullName;		/* the full pathname of name */
     struct make_stat mst;	/* buffer for finding the mod time */
@@ -1303,11 +1289,15 @@ Dir_MTime(GNode *gn, Boolean recheck)
 
     if (gn->type & OP_ARCHV) {
 	Arch_UpdateMTime(gn);
-	return gn->mtime;
-    } else if (gn->type & OP_PHONY) {
+	return;
+    }
+
+    if (gn->type & OP_PHONY) {
 	gn->mtime = 0;
-	return 0;
-    } else if (gn->path == NULL) {
+	return;
+    }
+
+    if (gn->path == NULL) {
 	if (gn->type & OP_NOPATH)
 	    fullName = NULL;
 	else {
@@ -1356,7 +1346,7 @@ Dir_MTime(GNode *gn, Boolean recheck)
 	    if (fullName != gn->path)
 		free(fullName);
 	    Arch_UpdateMemberMTime(gn);
-	    return gn->mtime;
+	    return;
 	}
 
 	mst.mst_mtime = 0;
@@ -1366,7 +1356,6 @@ Dir_MTime(GNode *gn, Boolean recheck)
 	gn->path = fullName;
 
     gn->mtime = mst.mst_mtime;
-    return gn->mtime;
 }
 
 /* Read the list of filenames in the directory and store the result

Index: src/usr.bin/make/dir.h
diff -u src/usr.bin/make/dir.h:1.32 src/usr.bin/make/dir.h:1.33
--- src/usr.bin/make/dir.h:1.32	Sun Oct 25 10:00:20 2020
+++ src/usr.bin/make/dir.h	Sun Nov  8 09:34:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.h,v 1.32 2020/10/25 10:00:20 rillig Exp $	*/
+/*	$NetBSD: dir.h,v 1.33 2020/11/08 09:34:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@ Boolean Dir_HasWildcards(const char *);
 void Dir_Expand(const char *, SearchPath *, StringList *);
 char *Dir_FindFile(const char *, SearchPath *);
 char *Dir_FindHereOrAbove(const char *, const char *);
-time_t Dir_MTime(GNode *, Boolean);
+void Dir_UpdateMTime(GNode *, Boolean);
 CachedDir *Dir_AddDir(SearchPath *, const char *);
 char *Dir_MakeFlags(const char *, SearchPath *);
 void Dir_ClearPath(SearchPath *);

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.314 src/usr.bin/make/job.c:1.315
--- src/usr.bin/make/job.c:1.314	Sun Nov  8 01:16:04 2020
+++ src/usr.bin/make/job.c	Sun Nov  8 09:34:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.314 2020/11/08 01:16:04 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.315 2020/11/08 09:34:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.314 2020/11/08 01:16:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.315 2020/11/08 09:34:55 rillig Exp $");
 
 /* A shell defines how the commands are run.  All commands for a target are
  * written into a single file, which is then given to the shell to execute
@@ -1225,7 +1225,8 @@ Job_CheckCommands(GNode *gn, void (*abor
 	return TRUE;
     }
 
-    if (Dir_MTime(gn, 0) != 0 || (gn->type & OP_SPECIAL))
+    Dir_UpdateMTime(gn, FALSE);
+    if (gn->mtime != 0 || (gn->type & OP_SPECIAL))
 	return TRUE;
 
     /*

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.193 src/usr.bin/make/make.c:1.194
--- src/usr.bin/make/make.c:1.193	Sun Nov  8 09:06:23 2020
+++ src/usr.bin/make/make.c	Sun Nov  8 09:34:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.193 2020/11/08 09:06:23 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.194 2020/11/08 09:34:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -108,7 +108,7 @@
 #include "job.h"
 
 /*	"@(#)make.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: make.c,v 1.193 2020/11/08 09:06:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.194 2020/11/08 09:34:55 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -213,7 +213,7 @@ GNode_IsOODate(GNode *gn)
      * doesn't depend on their modification time...
      */
     if (!(gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
-	(void)Dir_MTime(gn, 1);
+	Dir_UpdateMTime(gn, TRUE);
 	if (DEBUG(MAKE)) {
 	    if (gn->mtime != 0)
 		debug_printf("modified %s...", Targ_FmtTime(gn->mtime));
@@ -366,7 +366,7 @@ MakeFindChild(void *gnp, void *pgnp)
     GNode *gn = gnp;
     GNode *pgn = pgnp;
 
-    (void)Dir_MTime(gn, 0);
+    Dir_UpdateMTime(gn, FALSE);
     GNode_UpdateYoungestChild(pgn, gn);
     pgn->unmade--;
 
@@ -491,7 +491,10 @@ HandleUseNodes(GNode *gn)
 time_t
 Make_Recheck(GNode *gn)
 {
-    time_t mtime = Dir_MTime(gn, 1);
+    time_t mtime;
+
+    Dir_UpdateMTime(gn, TRUE);
+    mtime = gn->mtime;
 
 #ifndef RECHECK
     /*
@@ -531,7 +534,7 @@ Make_Recheck(GNode *gn)
      * using the same file from a common server), there are times
      * when the modification time of a file created on a remote
      * machine will not be modified before the local stat() implied by
-     * the Dir_MTime occurs, thus leading us to believe that the file
+     * the Dir_UpdateMTime occurs, thus leading us to believe that the file
      * is unchanged, wreaking havoc with files that depend on this one.
      *
      * I have decided it is better to make too much than to make too
@@ -1162,7 +1165,7 @@ Make_ExpandUse(GNodeList *targs)
 	    *eon = ')';
 	}
 
-	(void)Dir_MTime(gn, 0);
+	Dir_UpdateMTime(gn, FALSE);
 	Var_Set(TARGET, GNode_Path(gn), gn);
 	UnmarkChildren(gn);
 	HandleUseNodes(gn);

Reply via email to