Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): extract MainParseArgChdir into separat...



details:   https://anonhg.NetBSD.org/src/rev/f3cbe7c57043
branches:  trunk
changeset: 944510:f3cbe7c57043
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 01 23:06:56 2020 +0000

description:
make(1): extract MainParseArgChdir into separate function

This removes the struct stat from MainParseArg.

diffstat:

 usr.bin/make/main.c |  47 ++++++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 21 deletions(-)

diffs (78 lines):

diff -r 88f33cf92d8b -r f3cbe7c57043 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Thu Oct 01 23:02:07 2020 +0000
+++ b/usr.bin/make/main.c       Thu Oct 01 23:06:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.354 2020/10/01 23:02:07 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.355 2020/10/01 23:06:56 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #endif
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.354 2020/10/01 23:02:07 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.355 2020/10/01 23:06:56 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
  The Regents of the University of California.  All rights reserved.");
@@ -388,10 +388,32 @@
        return FALSE;
 }
 
+static void
+MainParseArgChdir(const char *argvalue)
+{
+       struct stat sa, sb;
+
+       if (chdir(argvalue) == -1) {
+               (void)fprintf(stderr, "%s: chdir %s: %s\n",
+                   progname, argvalue, strerror(errno));
+               exit(1);
+       }
+       if (getcwd(curdir, MAXPATHLEN) == NULL) {
+               (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
+               exit(2);
+       }
+       if (!is_relpath(argvalue) &&
+           stat(argvalue, &sa) != -1 &&
+           stat(curdir, &sb) != -1 &&
+           sa.st_ino == sb.st_ino &&
+           sa.st_dev == sb.st_dev)
+               strncpy(curdir, argvalue, MAXPATHLEN);
+       ignorePWD = TRUE;
+}
+
 static Boolean
 MainParseArg(char c, char *argvalue)
 {
-       struct stat sa, sb;
        char *p;
        char found_path[MAXPATHLEN + 1];        /* for searching for sys.mk */
 
@@ -404,24 +426,7 @@
                Var_Set(MAKE_MODE, "compat", VAR_GLOBAL);
                break;
        case 'C':
-               if (chdir(argvalue) == -1) {
-                       (void)fprintf(stderr,
-                                     "%s: chdir %s: %s\n",
-                                     progname, argvalue,
-                                     strerror(errno));
-                       exit(1);
-               }
-               if (getcwd(curdir, MAXPATHLEN) == NULL) {
-                       (void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
-                       exit(2);
-               }
-               if (!is_relpath(argvalue) &&
-                   stat(argvalue, &sa) != -1 &&
-                   stat(curdir, &sb) != -1 &&
-                   sa.st_ino == sb.st_ino &&
-                   sa.st_dev == sb.st_dev)
-                       strncpy(curdir, argvalue, MAXPATHLEN);
-               ignorePWD = TRUE;
+               MainParseArgChdir(argvalue);
                break;
        case 'D':
                if (argvalue == NULL || argvalue[0] == 0) return FALSE;



Home | Main Index | Thread Index | Old Index