1 /*
2  * stat64() for uClibc
3  *
4  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7  */
8 
9 #include <_lfs_64.h>
10 #include <sys/syscall.h>
11 #include <sys/stat.h>
12 
13 #if defined __NR_fstatat64 && !defined __NR_stat64 && !defined(__UCLIBC_USE_TIME64__)
14 #include <fcntl.h>
15 #include <unistd.h>
16 
stat64(const char * file_name,struct stat64 * buf)17 int stat64(const char *file_name, struct stat64 *buf)
18 {
19 	return fstatat64(AT_FDCWD, file_name, buf, 0);
20 }
21 libc_hidden_def(stat64)
22 
23 #elif __NR_statx && defined __UCLIBC_HAVE_STATX__
24 # include <fcntl.h>
25 # include <statx_cp.h>
26 
27 int stat64(const char *file_name, struct stat64 *buf)
28 {
29 	struct statx tmp;
30 	int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name, AT_NO_AUTOMOUNT,
31                                 STATX_BASIC_STATS, &tmp);
32 	if (rc == 0)
33 		__cp_stat64_statx ((struct stat64 *)buf, &tmp);
34 
35 	return rc;
36 }
37 libc_hidden_def(stat64)
38 
39 /* For systems which have both, prefer the old one */
40 # elif defined __NR_stat64
41 # define __NR___syscall_stat64 __NR_stat64
42 # include "xstatconv.h"
43 static __always_inline _syscall2(int, __syscall_stat64,
44 				 const char *, file_name, struct kernel_stat64 *, buf)
45 
46 int stat64(const char *file_name, struct stat64 *buf)
47 {
48 	int result;
49 	struct kernel_stat64 kbuf;
50 
51 	result = __syscall_stat64(file_name, &kbuf);
52 	if (result == 0) {
53 		__xstat64_conv(&kbuf, buf);
54 	}
55 	return result;
56 }
57 libc_hidden_def(stat64)
58 #endif
59