fstat(): Fix to convert between the NaCl and glibc struct layouts
[glibc/nacl-glibc.git] / sysdeps / nacl / fxstat.c
blob4deabc6f497b55f0946b88a40095631381d9cb68
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 __fxstat(int vers, int fd, struct stat *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_STAT___PAD1
24 buf->__pad1 = 0;
25 #endif
26 buf->st_ino = nacl_buf.nacl_abi_st_ino;
27 buf->st_mode = nacl_buf.nacl_abi_st_mode;
28 buf->st_nlink = nacl_buf.nacl_abi_st_nlink;
29 buf->st_uid = nacl_buf.nacl_abi_st_uid;
30 buf->st_gid = nacl_buf.nacl_abi_st_gid;
31 buf->st_rdev = nacl_buf.nacl_abi_st_rdev;
32 #ifdef _HAVE_STAT___PAD2
33 buf->__pad2 = 0;
34 #endif
35 buf->st_size = nacl_buf.nacl_abi_st_size;
36 buf->st_blksize = nacl_buf.nacl_abi_st_blksize;
37 buf->st_blocks = nacl_buf.nacl_abi_st_blocks;
38 buf->st_atim.tv_sec = nacl_buf.nacl_abi_st_atime;
39 buf->st_atim.tv_nsec = 0;
40 buf->st_mtim.tv_sec = nacl_buf.nacl_abi_st_mtime;
41 buf->st_mtim.tv_nsec = 0;
42 buf->st_ctim.tv_sec = nacl_buf.nacl_abi_st_ctime;
43 buf->st_ctim.tv_nsec = 0;
44 #ifdef _HAVE_STAT___UNUSED4
45 buf->__unused4 = 0;
46 #endif
47 #ifdef _HAVE_STAT___UNUSED5
48 buf->__unused5 = 0;
49 #endif
50 return result;
52 hidden_def (__fxstat)
53 weak_alias (__fxstat, _fxstat)