]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/fstat.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / fstat.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * fstat() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11 #include <unistd.h>
12 #include <sys/stat.h>
13 #include "xstatconv.h"
14
15 #if defined __NR_fstat64 && !defined __NR_fstat
16 int fstat(int fd, struct stat *buf)
17 {
18         int result = INLINE_SYSCALL(fstat64, 2, fd, buf);
19         if (result == 0) {
20                 /* Did we overflow? */
21                 if (buf->__pad1 || buf->__pad2 || buf->__pad3
22                     || buf->__pad4 || buf->__pad5
23                     || buf->__pad6 || buf->__pad7) {
24                         __set_errno(EOVERFLOW);
25                         return -1;
26                 }
27         }
28         return result;
29 }
30 libc_hidden_def(fstat)
31
32 #elif defined __NR_fstat
33 int fstat(int fd, struct stat *buf)
34 {
35         int result;
36 # ifdef __NR_fstat64
37         /* normal stat call has limited values for various stat elements
38          * e.g. uid device major/minor etc.
39          * so we use 64 variant if available
40          * in order to get newer versions of stat elements
41          */
42         struct kernel_stat64 kbuf;
43         result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
44         if (result == 0) {
45                 __xstat32_conv(&kbuf, buf);
46         }
47 # else
48         struct kernel_stat kbuf;
49
50         result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
51         if (result == 0) {
52                 __xstat_conv(&kbuf, buf);
53         }
54 # endif
55         return result;
56 }
57 libc_hidden_def(fstat)
58
59 # if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
60 strong_alias_untyped(fstat,fstat64)
61 libc_hidden_def(fstat64)
62 # endif
63
64 #endif