1 /*
2  * fstatat() for uClibc
3  *
4  * Copyright (C) 2009 Analog Devices Inc.
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7  */
8 
9 #include <sys/syscall.h>
10 #include <sys/stat.h>
11 #include "xstatconv.h"
12 
13 /* 64bit ports tend to favor newfstatat() */
14 #if __WORDSIZE == 64 && defined __NR_newfstatat
15 # define __NR_fstatat64 __NR_newfstatat
16 #endif
17 
18 #ifdef __NR_fstatat64
fstatat(int fd,const char * file,struct stat * buf,int flag)19 int fstatat(int fd, const char *file, struct stat *buf, int flag)
20 {
21 	int ret;
22 # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
23 	struct kernel_stat64 kbuf;
24 	ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
25 	if (ret == 0)
26 		__xstat32_conv(&kbuf, buf);
27 # else
28 	ret = INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
29 	if (ret == 0) {
30 		/* Did we overflow */
31 		if (buf->__pad1 || buf->__pad2 || buf->__pad3
32 		    || buf->__pad4 || buf->__pad5 || buf->__pad6
33 		    || buf->__pad7) {
34 			__set_errno(EOVERFLOW);
35 			return -1;
36 		}
37 	}
38 # endif /* __ARCH_HAS_DEPRECATED_SYSCALLS__ */
39 	return ret;
40 }
41 libc_hidden_def(fstatat)
42 #else
43 /* should add emulation with fstat() and /proc/self/fd/ ... */
44 #endif
45