1 /* @(#)faccessat.c	1.1 14/05/11 Copyright 2013-2014 J. Schilling */
2 /*
3  *	Emulate the behavior of faccessat(int fd, const char *name,
4  *					int amode, int flag)
5  *
6  *	Note that emulation methods that do not use the /proc filesystem are
7  *	not MT safe. In the non-MT-safe case, we do:
8  *
9  *		savewd()/fchdir()/open(name)/restorewd()
10  *
11  *	Errors may force us to abort the program as our caller is not expected
12  *	to know that we do more than a simple open() here and that the
13  *	working directory may be changed by us.
14  *
15  *	Copyright (c) 2013-2014 J. Schilling
16  */
17 /*
18  * The contents of this file are subject to the terms of the
19  * Common Development and Distribution License, Version 1.0 only
20  * (the "License").  You may not use this file except in compliance
21  * with the License.
22  *
23  * See the file CDDL.Schily.txt in this distribution for details.
24  * A copy of the CDDL is also available via the Internet at
25  * http://www.opensource.org/licenses/cddl1.txt
26  *
27  * When distributing Covered Code, include this CDDL HEADER in each
28  * file and include the License file CDDL.Schily.txt from this distribution.
29  */
30 
31 #include <schily/unistd.h>
32 #include <schily/types.h>
33 #include <schily/fcntl.h>
34 #include <schily/maxpath.h>
35 #include <schily/errno.h>
36 #include <schily/standard.h>
37 #include <schily/schily.h>
38 #include "at-defs.h"
39 
40 #ifndef	HAVE_FACCESSAT
41 
42 /* CSTYLED */
43 #define	PROTO_DECL	, int amode, int flag
44 #define	KR_DECL		int amode; int flag;
45 /* CSTYLED */
46 #define	KR_ARGS		, amode, flag
47 #define	FUNC_CALL(n)	(flag & AT_EACCESS ? \
48 				eaccess(n, amode) : access(n, amode))
49 #define	FLAG_CHECK()	if (flag & ~(AT_EACCESS)) { \
50 				seterrno(EINVAL);			 \
51 				return (-1);				 \
52 			}
53 #define	FUNC_NAME	faccessat
54 #define	FUNC_RESULT	int
55 
56 #include "at-base.c"
57 
58 #endif	/* HAVE_FCHOWNAT */
59