diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-05-05 07:59:48 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-05-05 07:59:48 +0000 |
commit | 280cc680712a70fc7f1827f57d62e98507e6cbb5 (patch) | |
tree | da8ad78dc5e41a287b2851962541437943eca12a /lib/makepath.c | |
parent | 04d5428ad322d277f330ed199d7c11ce87adf69e (diff) | |
download | coreutils-280cc680712a70fc7f1827f57d62e98507e6cbb5.tar.xz |
(make_path): chdir to "//", not "/", if the file name
starts with exactly two slashes.
Diffstat (limited to 'lib/makepath.c')
-rw-r--r-- | lib/makepath.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/makepath.c b/lib/makepath.c index 1bc12c310..5ae89d239 100644 --- a/lib/makepath.c +++ b/lib/makepath.c @@ -1,7 +1,7 @@ /* makepath.c -- Ensure that a directory path exists. - Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free - Software Foundation, Inc. + Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005 + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -207,8 +207,14 @@ make_path (const char *argpath, /* If we've saved the cwd and DIRPATH is an absolute pathname, we must chdir to `/' in order to enable the chdir optimization. So if chdir ("/") fails, turn off the optimization. */ - if (do_chdir && *dirpath == '/' && chdir ("/") < 0) - do_chdir = false; + if (do_chdir && dirpath[0] == '/') + { + /* POSIX says "//" might be special, so chdir to "//" if the + file name starts with exactly two slashes. */ + char const *root = "//" + (dirpath[1] != '/' || dirpath[2] == '/'); + if (chdir (root) != 0) + do_chdir = false; + } slash = dirpath; |