Skip to content

Commit

Permalink
sysdeps/linux: correctly set time fields in stat on x86
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorLap2006 committed Mar 8, 2024
1 parent 55ae8dd commit 08640d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions abis/linux/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ struct stat {
long tv_nsec;
} __st_atim32, __st_mtim32, __st_ctim32;
ino_t st_ino;

// These fields are not in the ABI. Their values are
// copied from __st_atim32, __st_mtim32, __st_ctim32
// accordingly.

struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
Expand Down
13 changes: 12 additions & 1 deletion sysdeps/linux/generic/sysdeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,19 @@ int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat
#else
auto ret = do_cp_syscall(SYS_fstatat64, fd, path, statbuf, flags);
#endif
if (int e = sc_error(ret); e)
if (int e = sc_error(ret); e) {
return e;
}

#if defined(__i386__)
statbuf->st_atim.tv_sec = statbuf->__st_atim32.tv_sec;
statbuf->st_atim.tv_nsec = statbuf->__st_atim32.tv_nsec;
statbuf->st_mtim.tv_sec = statbuf->__st_mtim32.tv_sec;
statbuf->st_mtim.tv_nsec = statbuf->__st_mtim32.tv_nsec;
statbuf->st_ctim.tv_sec = statbuf->__st_ctim32.tv_sec;
statbuf->st_ctim.tv_nsec = statbuf->__st_ctim32.tv_nsec;
#endif

return 0;
}

Expand Down

0 comments on commit 08640d2

Please sign in to comment.