2.5-18.1
[jlayton/glibc.git] / sysdeps / mach / hurd / openat.c
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.
4
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.
9
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.
14
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.  */
19
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <stdarg.h>
23 #include <stddef.h>
24 #include <sys/stat.h>
25 #include <hurd.h>
26 #include <hurd/fd.h>
27
28 /* Open FILE with access OFLAG.  Interpret relative paths relative to
29    the directory associated with FD.  If OFLAG includes O_CREAT, a
30    third argument is the file protection.  */
31 int
32 __openat (fd, file, oflag)
33      int fd;
34      const char *file;
35      int oflag;
36 {
37   int mode;
38   io_t port;
39
40   if (oflag & O_CREAT)
41     {
42       va_list arg;
43       va_start (arg, oflag);
44       mode = va_arg (arg, int);
45       va_end (arg);
46     }
47   else
48     mode = 0;
49
50   port = __file_name_lookup_at (fd, 0, file, oflag, mode);
51   if (port == MACH_PORT_NULL)
52     return -1;
53
54   return _hurd_intern_fd (port, oflag, 1);
55 }
56 libc_hidden_def (__openat)
57 weak_alias (__openat, openat)
58
59 /* openat64 is just the same as openat for us.  */
60 weak_alias (__openat, __openat64)
61 libc_hidden_weak (__openat64)
62 weak_alias (__openat, openat64)