mirror of
git://sourceware.org/git/glibc.git
synced 2025-01-18 12:16:13 +08:00
hurd: Consolidate file_name_lookup implementation
Instead of __file_name_lookup_at delegating to __file_name_lookup in simple cases, make __file_name_lookup_at deal with both cases, and have __file_name_lookup simply wrap __file_name_lookup_at. This factorizes handling the empy name case. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230130125216.6254-2-bugaevc@gmail.com>
This commit is contained in:
parent
98f9435f33
commit
d011ab5708
@ -16,6 +16,7 @@
|
|||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <hurd.h>
|
#include <hurd.h>
|
||||||
|
#include <hurd/fd.h>
|
||||||
#include <hurd/lookup.h>
|
#include <hurd/lookup.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -220,14 +221,7 @@ weak_alias (__hurd_directory_name_split, hurd_directory_name_split)
|
|||||||
file_t
|
file_t
|
||||||
__file_name_lookup (const char *file_name, int flags, mode_t mode)
|
__file_name_lookup (const char *file_name, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
error_t err;
|
return __file_name_lookup_at (AT_FDCWD, 0, file_name, flags, mode);
|
||||||
file_t result;
|
|
||||||
|
|
||||||
err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0,
|
|
||||||
file_name, flags, mode & ~_hurd_umask,
|
|
||||||
&result);
|
|
||||||
|
|
||||||
return err ? (__hurd_fail (err), MACH_PORT_NULL) : result;
|
|
||||||
}
|
}
|
||||||
weak_alias (__file_name_lookup, file_name_lookup)
|
weak_alias (__file_name_lookup, file_name_lookup)
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ __file_name_lookup_at (int fd, int at_flags,
|
|||||||
if (err)
|
if (err)
|
||||||
return (__hurd_fail (err), MACH_PORT_NULL);
|
return (__hurd_fail (err), MACH_PORT_NULL);
|
||||||
|
|
||||||
if (fd == AT_FDCWD || file_name[0] == '/')
|
|
||||||
return __file_name_lookup (file_name, flags, mode);
|
|
||||||
|
|
||||||
if (empty != 0 && file_name[0] == '\0')
|
if (empty != 0 && file_name[0] == '\0')
|
||||||
{
|
{
|
||||||
enum retry_type doretry;
|
enum retry_type doretry;
|
||||||
@ -56,22 +53,44 @@ __file_name_lookup_at (int fd, int at_flags,
|
|||||||
return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
|
return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_t startdir;
|
if (fd == AT_FDCWD || file_name[0] == '/')
|
||||||
error_t use_init_port (int which, error_t (*operate) (mach_port_t))
|
|
||||||
{
|
{
|
||||||
return (which == INIT_PORT_CWDIR ? (*operate) (startdir)
|
err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0,
|
||||||
: _hurd_ports_use (which, operate));
|
file_name, flags, mode & ~_hurd_umask,
|
||||||
|
&result);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
__hurd_fail (err);
|
||||||
|
return MACH_PORT_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file_t startdir;
|
||||||
|
/* We need to look the file up relative to the given directory (and
|
||||||
|
not our cwd). For this to work, we supply our own wrapper for
|
||||||
|
_hurd_ports_use, which replaces cwd with our startdir. */
|
||||||
|
error_t use_init_port (int which, error_t (*operate) (mach_port_t))
|
||||||
|
{
|
||||||
|
return (which == INIT_PORT_CWDIR ? (*operate) (startdir)
|
||||||
|
: _hurd_ports_use (which, operate));
|
||||||
|
}
|
||||||
|
|
||||||
|
err = HURD_DPORT_USE (fd, (startdir = port,
|
||||||
|
__hurd_file_name_lookup (&use_init_port,
|
||||||
|
&__getdport, NULL,
|
||||||
|
file_name,
|
||||||
|
flags,
|
||||||
|
mode & ~_hurd_umask,
|
||||||
|
&result)));
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
__hurd_dfail (fd, err);
|
||||||
|
return MACH_PORT_NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = HURD_DPORT_USE (fd, (startdir = port,
|
return result;
|
||||||
__hurd_file_name_lookup (&use_init_port,
|
|
||||||
&__getdport, NULL,
|
|
||||||
file_name,
|
|
||||||
flags,
|
|
||||||
mode & ~_hurd_umask,
|
|
||||||
&result)));
|
|
||||||
|
|
||||||
return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file_t
|
file_t
|
||||||
|
Loading…
Reference in New Issue
Block a user