]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/openat.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / openat.c
CommitLineData
f7a9f785 1/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
4973cbe5
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
4973cbe5
UD
17
18#include <errno.h>
19#include <fcntl.h>
20#include <stdarg.h>
21#include <stddef.h>
22#include <stdio.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sysdep-cancel.h>
d369ad76 26#include <not-cancel.h>
4973cbe5
UD
27
28
3997b7c4 29#ifndef OPENAT
4973cbe5 30# define OPENAT openat
4973cbe5
UD
31#endif
32
e2c7e1de
RM
33#define UNDERIZE(name) UNDERIZE_1 (name)
34#define UNDERIZE_1(name) __##name
35#define __OPENAT UNDERIZE (OPENAT)
36
d369ad76
UD
37
38/* Open FILE with access OFLAG. Interpret relative paths relative to
65f6f938
ER
39 the directory associated with FD. If OFLAG includes O_CREAT or
40 O_TMPFILE, a fourth argument is the file protection. */
d369ad76 41int
14bb4e57 42__OPENAT (int fd, const char *file, int oflag, ...)
d369ad76
UD
43{
44 mode_t mode = 0;
65f6f938 45 if (__OPEN_NEEDS_MODE (oflag))
d369ad76
UD
46 {
47 va_list arg;
48 va_start (arg, oflag);
49 mode = va_arg (arg, mode_t);
50 va_end (arg);
51 }
52
eb32b0d4
AS
53 /* We have to add the O_LARGEFILE flag for openat64. */
54#ifdef MORE_OFLAGS
55 oflag |= MORE_OFLAGS;
56#endif
57
c6bb095e 58 return SYSCALL_CANCEL (openat, fd, file, oflag, mode);
d369ad76 59}
e2c7e1de
RM
60libc_hidden_def (__OPENAT)
61weak_alias (__OPENAT, OPENAT)