/* 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
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by David MacKenzie <djm@gnu.ai.mit.edu> and Jim Meyering. */
/* 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;