From af73694245bac3c2f7cc4e183d80ea10b678b1d7 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 4 Feb 1993 18:23:19 +0000 Subject: Formerly main.c.~71~ --- main.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c736881..8201724 100644 --- a/main.c +++ b/main.c @@ -325,6 +325,10 @@ struct stringlist *other_args = 0; char *program; +/* Our current directory after processing all -C options. */ + +char *starting_directory; + /* Value of the MAKELEVEL variable at startup (or 0). */ unsigned int makelevel; @@ -597,6 +601,25 @@ main (argc, argv, envp) construct_include_path (include_directories == 0 ? (char **) 0 : include_directories->list); + /* Figure out where we are now, after chdir'ing. */ + if (directories == 0) + /* We didn't move, so we're still in the same place. */ + starting_directory = current_directory; + else + { + if (getcwd (current_directory, GET_PATH_MAX) == 0) + { +#ifdef HAVE_GETCWD + perror_with_name ("getcwd: ", ""); +#else + error ("getwd: %s", current_directory); +#endif + starting_directory = 0; + } + else + starting_directory = current_directory; + } + /* Tell the user where he is. */ if (print_directory_flag) @@ -1344,7 +1367,7 @@ decode_env_switches (envar, len) args[(value[0] == '-' ? 0 : 1) + len + 1] = '\0'; /* Allocate a vector that is definitely big enough. */ - argv = (char **) alloca (1 + len * sizeof (char *)); + argv = (char **) alloca ((1 + len + 1) * sizeof (char *)); /* getopt will look at the arguments starting at ARGV[1]. Prepend a spacer word. */ @@ -1619,7 +1642,6 @@ log_working_directory (entering) int entering; { static int entered = 0; - PATH_VAR (pwdbuf); char *message = entering ? "Entering" : "Leaving"; if (entering) @@ -1637,15 +1659,8 @@ log_working_directory (entering) else printf ("%s[%u]: %s ", program, makelevel, message); - if (getcwd (pwdbuf, GET_PATH_MAX) == 0) - { -#ifdef HAVE_GETCWD - perror_with_name ("getcwd: ", ""); -#else - error ("getwd: %s", pwdbuf); -#endif - puts ("an unknown directory"); - } + if (starting_directory == 0) + puts ("an unknown directory"); else - printf ("directory `%s'\n", pwdbuf); + printf ("directory `%s'\n", starting_directory); } -- cgit v1.2.3