powerpc: Update ulps
[glibc.git] / sysdeps / mach / hurd / openat.c
blob56ecbb3a25c6af1b17b4569c4526ba660d8f2a54
1 /* openat -- Open a file named relative to an open directory. Hurd version.
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/>. */
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <stdarg.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <sys/stat.h>
25 #include <hurd.h>
26 #include <hurd/fd.h>
27 #include <sysdep-cancel.h>
29 /* Open FILE with access OFLAG. Interpret relative paths relative to
30 the directory associated with FD. If O_CREAT or O_TMPFILE is in OFLAG, a
31 third argument is the file protection. */
32 int
33 __openat (int fd, const char *file, int oflag, ...)
35 mode_t mode;
36 io_t port;
37 int cancel_oldtype;
39 if (__OPEN_NEEDS_MODE (oflag))
41 va_list arg;
42 va_start (arg, oflag);
43 mode = va_arg (arg, mode_t);
44 va_end (arg);
46 else
47 mode = 0;
49 cancel_oldtype = LIBC_CANCEL_ASYNC();
50 port = __file_name_lookup_at (fd, 0, file, oflag, mode);
51 LIBC_CANCEL_RESET (cancel_oldtype);
53 if (port == MACH_PORT_NULL)
54 return -1;
56 return _hurd_intern_fd (port, oflag, 1);
58 libc_hidden_def (__openat)
59 weak_alias (__openat, openat)
61 /* openat64 is just the same as openat for us. */
62 weak_alias (__openat, __openat64)
63 libc_hidden_weak (__openat64)
64 weak_alias (__openat, openat64)