fstat(): Fix to convert between the NaCl and glibc struct layouts
[glibc/nacl-glibc.git] / sysdeps / nacl / fxstat64.c
blob5405231e7cd1f2088b2b14ce5642798799af6378
2 #include <errno.h>
3 #include <stddef.h>
4 #include <sys/stat.h>
6 #include <kernel_stat.h>
7 #include <nacl_stat.h>
8 #include <nacl_syscalls.h>
11 int __fxstat64(int vers, int fd, struct stat64 *buf)
13 int (*nacl_fstat)(int fd, struct nacl_abi_stat *buf) =
14 NACL_SYSCALL_ADDR(NACL_sys_fstat);
16 struct nacl_abi_stat nacl_buf;
17 int result = nacl_fstat(fd, &nacl_buf);
18 if (result < 0) {
19 errno = -result;
20 return -1;
22 buf->st_dev = nacl_buf.nacl_abi_st_dev;
23 #ifdef _HAVE_STAT64___PAD1
24 buf->__pad1 = 0;
25 #endif
26 #ifdef _HAVE_STAT64___ST_INO
27 buf->__st_ino = nacl_buf.nacl_abi_st_ino;
28 #endif
29 buf->st_mode = nacl_buf.nacl_abi_st_mode;
30 buf->st_nlink = nacl_buf.nacl_abi_st_nlink;
31 buf->st_uid = nacl_buf.nacl_abi_st_uid;
32 buf->st_gid = nacl_buf.nacl_abi_st_gid;
33 buf->st_rdev = nacl_buf.nacl_abi_st_rdev;
34 #ifdef _HAVE_STAT64___PAD2
35 buf->__pad2 = 0;
36 #endif
37 buf->st_size = nacl_buf.nacl_abi_st_size;
38 buf->st_blksize = nacl_buf.nacl_abi_st_blksize;
39 buf->st_blocks = nacl_buf.nacl_abi_st_blocks;
40 buf->st_atim.tv_sec = nacl_buf.nacl_abi_st_atime;
41 buf->st_atim.tv_nsec = 0;
42 buf->st_mtim.tv_sec = nacl_buf.nacl_abi_st_mtime;
43 buf->st_mtim.tv_nsec = 0;
44 buf->st_ctim.tv_sec = nacl_buf.nacl_abi_st_ctime;
45 buf->st_ctim.tv_nsec = 0;
46 buf->st_ino = nacl_buf.nacl_abi_st_ino;
47 return result;
49 hidden_def (__fxstat64)