Remove unneeded setting of errno after malloc failure
[glibc.git] / hurd / lookup-at.c
blobdeddc2264c5616667e40d026d53ed41ec8bc4f66
1 /* Lookup helper function for Hurd implementation of *at functions.
2 Copyright (C) 2006-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <hurd.h>
20 #include <hurd/lookup.h>
21 #include <hurd/fd.h>
22 #include <string.h>
23 #include <fcntl.h>
25 file_t
26 __file_name_lookup_at (int fd, int at_flags,
27 const char *file_name, int flags, mode_t mode)
29 error_t err;
30 file_t result;
32 err = __hurd_at_flags (&at_flags, &flags);
33 if (err)
34 return (__hurd_fail (err), MACH_PORT_NULL);
36 if (fd == AT_FDCWD || file_name[0] == '/')
37 return __file_name_lookup (file_name, flags, mode);
39 file_t startdir;
40 error_t use_init_port (int which, error_t (*operate) (mach_port_t))
42 return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
43 _hurd_ports_use (which, operate));
46 err = HURD_DPORT_USE (fd, (startdir = port,
47 __hurd_file_name_lookup (&use_init_port,
48 &__getdport, NULL,
49 file_name,
50 flags,
51 mode & ~_hurd_umask,
52 &result)));
54 return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
57 file_t
58 __file_name_split_at (int fd, const char *file_name, char **name)
60 error_t err;
61 file_t result;
63 if (fd == AT_FDCWD || file_name[0] == '/')
64 return __file_name_split (file_name, name);
66 err = __hurd_file_name_split (&_hurd_ports_use, &__getdport, 0,
67 file_name, &result, name);
69 file_t startdir;
70 error_t use_init_port (int which, error_t (*operate) (mach_port_t))
72 return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
73 _hurd_ports_use (which, operate));
76 err = HURD_DPORT_USE (fd, (startdir = port,
77 __hurd_file_name_split (&use_init_port,
78 &__getdport, 0,
79 file_name,
80 &result, name)));
82 return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;
85 file_t
86 __directory_name_split_at (int fd, const char *directory_name, char **name)
88 error_t err;
89 file_t result;
91 if (fd == AT_FDCWD || directory_name[0] == '/')
92 return __directory_name_split (directory_name, name);
94 file_t startdir;
95 error_t use_init_port (int which, error_t (*operate) (mach_port_t))
97 return (which == INIT_PORT_CWDIR ? (*operate) (startdir) :
98 _hurd_ports_use (which, operate));
101 err = HURD_DPORT_USE (fd, (startdir = port,
102 __hurd_directory_name_split (&use_init_port,
103 &__getdport, 0,
104 directory_name,
105 &result, name)));
107 return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result;