]>
sourceware.org Git - glibc.git/blob - hurd/lookup-at.c
01d2ecf7f78a806eef85feb6820f7ab9c31677f0
1 /* Lookup helper function for Hurd implementation of *at functions.
2 Copyright (C) 2006-2024 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 <https://www.gnu.org/licenses/>. */
20 #include <hurd/lookup.h>
26 __file_name_lookup_at (int fd
, int at_flags
,
27 const char *file_name
, int flags
, mode_t mode
)
31 int empty
= at_flags
& AT_EMPTY_PATH
;
34 at_flags
&= ~AT_EMPTY_PATH
;
36 err
= __hurd_at_flags (&at_flags
, &flags
);
38 return (__hurd_fail (err
), MACH_PORT_NULL
);
40 if (empty
!= 0 && file_name
[0] == '\0')
42 enum retry_type doretry
;
43 char retryname
[1024]; /* XXX string_t LOSES! */
45 err
= HURD_DPORT_USE (fd
, __dir_lookup (port
, "", flags
, mode
,
50 err
= __hurd_file_name_lookup_retry (&_hurd_ports_use
, &__getdport
,
51 NULL
, doretry
, retryname
,
52 flags
, mode
, &result
);
54 return err
? (__hurd_dfail (fd
, err
), MACH_PORT_NULL
) : result
;
58 if (flags
& O_TMPFILE
)
61 if (fd
== AT_FDCWD
|| file_name
[0] == '/')
63 err
= __hurd_file_name_lookup (&_hurd_ports_use
, &__getdport
, 0,
64 file_name
, flags
, mode
& ~_hurd_umask
,
69 return MACH_PORT_NULL
;
75 /* We need to look the file up relative to the given directory (and
76 not our cwd). For this to work, we supply our own wrapper for
77 _hurd_ports_use, which replaces cwd with our startdir. */
78 error_t
use_init_port (int which
, error_t (*operate
) (mach_port_t
))
80 return (which
== INIT_PORT_CWDIR
? (*operate
) (startdir
)
81 : _hurd_ports_use (which
, operate
));
84 err
= HURD_DPORT_USE (fd
, (startdir
= port
,
85 __hurd_file_name_lookup (&use_init_port
,
93 __hurd_dfail (fd
, err
);
94 return MACH_PORT_NULL
;
98 if (orig_flags
& O_TMPFILE
)
100 /* What we have looked up is not the file itself, but actually
101 the directory to create the file in. Do that now. */
104 err
= __dir_mkfile (dir
, orig_flags
& ~(O_TMPFILE
| O_DIRECTORY
),
106 __mach_port_deallocate (__mach_task_self (), dir
);
110 return MACH_PORT_NULL
;
118 __file_name_split_at (int fd
, const char *file_name
, char **name
)
123 if (fd
== AT_FDCWD
|| file_name
[0] == '/')
124 return __file_name_split (file_name
, name
);
126 err
= __hurd_file_name_split (&_hurd_ports_use
, &__getdport
, 0,
127 file_name
, &result
, name
);
130 error_t
use_init_port (int which
, error_t (*operate
) (mach_port_t
))
132 return (which
== INIT_PORT_CWDIR
? (*operate
) (startdir
)
133 : _hurd_ports_use (which
, operate
));
136 err
= HURD_DPORT_USE (fd
, (startdir
= port
,
137 __hurd_file_name_split (&use_init_port
,
142 return err
? (__hurd_dfail (fd
, err
), MACH_PORT_NULL
) : result
;
146 __directory_name_split_at (int fd
, const char *directory_name
, char **name
)
151 if (fd
== AT_FDCWD
|| directory_name
[0] == '/')
152 return __directory_name_split (directory_name
, name
);
155 error_t
use_init_port (int which
, error_t (*operate
) (mach_port_t
))
157 return (which
== INIT_PORT_CWDIR
? (*operate
) (startdir
)
158 : _hurd_ports_use (which
, operate
));
161 err
= HURD_DPORT_USE (fd
, (startdir
= port
,
162 __hurd_directory_name_split (&use_init_port
,
167 return err
? (__hurd_dfail (fd
, err
), MACH_PORT_NULL
) : result
;
This page took 0.053145 seconds and 6 git commands to generate.