1 /* Copyright (C) 1992, 1993 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
24 __hurd_path_lookup (file_t crdir, file_t cwdir,
25 const char *path, int flags, mode_t mode,
29 file_t startdir, result;
31 enum retry_type doretry;
32 char retryname[PATH_MAX];
51 err = __dir_pathtrans (startdir, path, flags, mode,
52 &doretry, retryname, &result);
55 __mach_port_deallocate (__mach_task_self (), startdir);
65 __io_reauthenticate (*result);
66 _HURD_PORT_USE (&_hurd_auth,
67 __auth_user_authenticate (port, result, &newpt));
68 __mach_port_deallocate (__mach_task_self (), *result);
74 if (nloops++ >= SYMLINK_MAX)
78 if (retryname[0] == '/')
98 __hurd_path_split (file_t crdir, file_t cwdir,
100 file_t *dir, char **name)
102 const char *lastslash;
104 /* Skip leading slashes in the pathname. */
109 --path; /* Leave on one slash. */
112 lastslash = strrchr (path, '/');
114 if (lastslash != NULL)
116 if (lastslash == path)
118 /* "/foobar" => crdir + "foobar". */
120 __mach_port_mod_refs (__mach_task_self (), MACH_PORT_RIGHT_SEND,
127 /* "/dir1/dir2/.../file". */
128 char dirname[lastslash - path + 1];
129 memcpy (dirname, path, lastslash - path);
130 dirname[lastslath - path] = '\0';
131 *name = lastslash + 1;
132 return __hurd_path_lookup (crdir, cwdir, dirname, 0, 0, dir);
137 /* "foobar" => cwdir + "foobar". */
139 __mach_port_mod_refs (__mach_task_self (), MACH_PORT_RIGHT_SEND,
147 __path_lookup (const char *path, int flags, mode_t mode)
150 file_t result, crdir, cwdir;
151 int dealloc_crdir, dealloc_cwdir;
153 crdir = _hurd_port_get (&_hurd_crdir, &dealloc_crdir);
154 cwdir = _hurd_port_get (&_hurd_cwdir, &dealloc_cwdir);
156 err = __hurd_path_lookup (crdir, cwdir, path, flags, mode, &result);
158 _hurd_port_free (crdir, &dealloc_crdir);
159 _hurd_port_free (cwdir, &dealloc_cwdir);
164 return MACH_PORT_NULL;
171 __path_split (const char *path, char **name)
174 file_t dir, crdir, cwdir;
175 int dealloc_crdir, dealloc_cwdir;
177 crdir = _hurd_port_get (&_hurd_crdir, &dealloc_crdir);
178 cwdir = _hurd_port_get (&_hurd_cwdir, &dealloc_cwdir);
180 err = __hurd_path_split (crdir, cwdir, path, &dir, name);
182 _hurd_port_free (crdir, &dealloc_crdir);
183 _hurd_port_free (cwdir, &dealloc_cwdir);
188 return MACH_PORT_NULL;