1 /* @(#)fstatat.c	1.2 13/10/30 Copyright 2013 J. Schilling */
2 /*
3  *	Emulate the behavior of fstatat(int fd, const char *name,
4  *					struct stat *sbuf, 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 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/stat.h>
35 #include <schily/maxpath.h>
36 #include <schily/errno.h>
37 #include <schily/standard.h>
38 #include <schily/schily.h>
39 #include "at-defs.h"
40 
41 #ifndef	HAVE_FSTATAT
42 
43 #ifndef	HAVE_LSTAT
44 #define	lstat	stat
45 #endif
46 
47 /* CSTYLED */
48 #define	PROTO_DECL	, struct stat *sbuf, int flag
49 #define	KR_DECL		struct stat *sbuf; int flag;
50 /* CSTYLED */
51 #define	KR_ARGS		, sbuf, flag
52 #define	FUNC_CALL(n)	(flag & AT_SYMLINK_NOFOLLOW ? \
53 				lstat(n, sbuf) : stat(n, sbuf))
54 #define	FLAG_CHECK()	if (flag & ~(AT_SYMLINK_NOFOLLOW|_AT_TRIGGER)) { \
55 				seterrno(EINVAL);			 \
56 				return (-1);				 \
57 			}
58 #define	FUNC_NAME	fstatat
59 #define	FUNC_RESULT	int
60 
61 #include "at-base.c"
62 
63 #endif	/* HAVE_FSTATAT */
64