xref: /freebsd/lib/libc/sys/openat.c (revision 6e83504c603157e9fc1660d2a1556036492662fc)
1d7847a8dSBrooks Davis /*
2d7847a8dSBrooks Davis  * Copyright (c) 2014 The FreeBSD Foundation.
3d7847a8dSBrooks Davis  *
4d7847a8dSBrooks Davis  * Portions of this software were developed by Konstantin Belousov
5d7847a8dSBrooks Davis  * under sponsorship from the FreeBSD Foundation.
6d7847a8dSBrooks Davis  *
7d7847a8dSBrooks Davis  * Redistribution and use in source and binary forms, with or without
8d7847a8dSBrooks Davis  * modification, are permitted provided that the following conditions
9d7847a8dSBrooks Davis  * are met:
10d7847a8dSBrooks Davis  * 1. Redistributions of source code must retain the above copyright
11d7847a8dSBrooks Davis  *    notice(s), this list of conditions and the following disclaimer as
12d7847a8dSBrooks Davis  *    the first lines of this file unmodified other than the possible
13d7847a8dSBrooks Davis  *    addition of one or more copyright notices.
14d7847a8dSBrooks Davis  * 2. Redistributions in binary form must reproduce the above copyright
15d7847a8dSBrooks Davis  *    notice(s), this list of conditions and the following disclaimer in
16d7847a8dSBrooks Davis  *    the documentation and/or other materials provided with the
17d7847a8dSBrooks Davis  *    distribution.
18d7847a8dSBrooks Davis  *
19d7847a8dSBrooks Davis  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
20d7847a8dSBrooks Davis  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21d7847a8dSBrooks Davis  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d7847a8dSBrooks Davis  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
23d7847a8dSBrooks Davis  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d7847a8dSBrooks Davis  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d7847a8dSBrooks Davis  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26d7847a8dSBrooks Davis  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27d7847a8dSBrooks Davis  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28d7847a8dSBrooks Davis  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29d7847a8dSBrooks Davis  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30d7847a8dSBrooks Davis  */
31d7847a8dSBrooks Davis 
32d7847a8dSBrooks Davis #include <sys/types.h>
33d7847a8dSBrooks Davis #include <sys/fcntl.h>
34d7847a8dSBrooks Davis #include <stdarg.h>
35d7847a8dSBrooks Davis #include "libc_private.h"
36d7847a8dSBrooks Davis 
37d7847a8dSBrooks Davis __weak_reference(__sys_openat, __openat);
38d7847a8dSBrooks Davis __sym_compat(openat, __impl_openat, FBSD_1.1);
39d7847a8dSBrooks Davis __weak_reference(openat, __impl_openat);
40*6e83504cSBrooks Davis __sym_default(openat, openat, FBSD_1.2);
41d7847a8dSBrooks Davis 
42d7847a8dSBrooks Davis #pragma weak openat
43d7847a8dSBrooks Davis int
44d7847a8dSBrooks Davis openat(int fd, const char *path, int flags, ...)
45d7847a8dSBrooks Davis {
46d7847a8dSBrooks Davis 	va_list ap;
47d7847a8dSBrooks Davis 	int mode;
48d7847a8dSBrooks Davis 
49d7847a8dSBrooks Davis 	if ((flags & O_CREAT) != 0) {
50d7847a8dSBrooks Davis 		va_start(ap, flags);
51d7847a8dSBrooks Davis 		mode = va_arg(ap, int);
52d7847a8dSBrooks Davis 		va_end(ap);
53d7847a8dSBrooks Davis 	} else {
54d7847a8dSBrooks Davis 		mode = 0;
55d7847a8dSBrooks Davis 	}
567dd9070eSBrooks Davis 	return (INTERPOS_SYS(openat, fd, path, flags, mode));
57d7847a8dSBrooks Davis }
58