2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / openat.c
blobf0a3404cd842603edb106699799b4d14377c47d8
1 /* openat -- Open a file named relative to an open directory. Hurd version.
2 Copyright (C) 2006 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <stdarg.h>
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <sys/stat.h>
26 #include <hurd.h>
27 #include <hurd/fd.h>
29 /* Open FILE with access OFLAG. Interpret relative paths relative to
30 the directory associated with FD. If OFLAG includes O_CREAT, a
31 third argument is the file protection. */
32 int
33 __openat (fd, file, oflag)
34 int fd;
35 const char *file;
36 int oflag;
38 int mode;
39 io_t port;
41 if (oflag & O_CREAT)
43 va_list arg;
44 va_start (arg, oflag);
45 mode = va_arg (arg, int);
46 va_end (arg);
48 else
49 mode = 0;
51 port = __file_name_lookup_at (fd, 0, file, oflag, mode);
52 if (port == MACH_PORT_NULL)
53 return -1;
55 return _hurd_intern_fd (port, oflag, 1);
57 libc_hidden_def (__openat)
58 weak_alias (__openat, openat)
60 int
61 __openat_2 (fd, file, oflag)
62 int fd;
63 const char *file;
64 int oflag;
66 if (oflag & O_CREAT)
67 __fortify_fail ("invalid openat call: O_CREAT without mode");
69 return __openat (fd, file, oflag);
72 /* openat64 is just the same as openat for us. */
73 weak_alias (__openat, __openat64)
74 libc_hidden_weak (__openat64)
75 weak_alias (__openat, openat64)
76 strong_alias (__openat_2, __openat64_2)