1 /*
2  * lstat() 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 <sys/syscall.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12 #include <bits/uClibc_arch_features.h>
13 
14 #if defined __NR_fstatat64 && !defined __NR_lstat && !defined(__UCLIBC_USE_TIME64__)
15 # include <fcntl.h>
16 
lstat(const char * file_name,struct stat * buf)17 int lstat(const char *file_name, struct stat *buf)
18 {
19 	return fstatat(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
20 }
21 libc_hidden_def(lstat)
22 
23 #elif __WORDSIZE == 64 && defined __NR_newfstatat
24 # include <fcntl.h>
25 
26 int lstat(const char *file_name, struct stat *buf)
27 {
28 	return fstatat(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
29 }
30 libc_hidden_def(lstat)
31 
32 #elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
33 # include <fcntl.h>
34 # include <statx_cp.h>
35 
36 int lstat(const char *file_name, struct stat *buf)
37 {
38       struct statx tmp;
39       int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name,
40                                AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW,
41                                STATX_BASIC_STATS, &tmp);
42       if (rc == 0)
43         __cp_stat_statx ((struct stat *)buf, &tmp);
44 
45       return rc;
46 }
47 libc_hidden_def(lstat)
48 
49 /* For systems which have both, prefer the old one */
50 #else
51 # include "xstatconv.h"
52 int lstat(const char *file_name, struct stat *buf)
53 {
54 	int result;
55 # ifdef __NR_lstat64
56 	/* normal stat call has limited values for various stat elements
57 	 * e.g. uid device major/minor etc.
58 	 * so we use 64 variant if available
59 	 * in order to get newer versions of stat elements
60 	 */
61 	struct kernel_stat64 kbuf;
62 	result = INLINE_SYSCALL(lstat64, 2, file_name, &kbuf);
63 	if (result == 0) {
64 		__xstat32_conv(&kbuf, buf);
65 	}
66 # else
67 	struct kernel_stat kbuf;
68 
69 	result = INLINE_SYSCALL(lstat, 2, file_name, &kbuf);
70 	if (result == 0) {
71 		__xstat_conv(&kbuf, buf);
72 	}
73 # endif /* __NR_lstat64 */
74 	return result;
75 }
76 libc_hidden_def(lstat)
77 
78 # if ! defined __NR_fstatat64 && ! defined __NR_lstat64 && ! defined __UCLIBC_HAS_STATX__
79 strong_alias_untyped(lstat,lstat64)
80 libc_hidden_def(lstat64)
81 # endif
82 
83 #endif /* __NR_fstatat64 */
84