Skip to content

Commit

Permalink
fs: fix uv__to_stat on BSD platforms
Browse files Browse the repository at this point in the history
Fix the #ifdef logic to make sure all the available fields filled in the
`stat` struct are correcly copied into the `uv_stat_t` struct. Before
this change, the `n_sec` were being set to 0.

PR-URL: libuv#1152
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
santigimeno committed Dec 6, 2016
1 parent 357b9a7 commit c02176a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_flags = 0;
dst->st_gen = 0;
#elif !defined(_AIX) && ( \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__) || \
defined(_GNU_SOURCE) || \
defined(_BSD_SOURCE) || \
defined(_SVID_SOURCE) || \
Expand All @@ -824,9 +828,7 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
# if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
# if defined(__FreeBSD__) || \
defined(__NetBSD__)
dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
Expand Down
20 changes: 11 additions & 9 deletions test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,22 +1141,24 @@ TEST_IMPL(fs_fstat) {
ASSERT(s->st_mtim.tv_nsec == t.st_mtimensec);
ASSERT(s->st_ctim.tv_sec == t.st_ctime);
ASSERT(s->st_ctim.tv_nsec == t.st_ctimensec);
#elif defined(__sun) || \
defined(_GNU_SOURCE) || \
defined(_BSD_SOURCE) || \
defined(_SVID_SOURCE) || \
defined(_XOPEN_SOURCE) || \
#elif defined(__sun) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__) || \
defined(_GNU_SOURCE) || \
defined(_BSD_SOURCE) || \
defined(_SVID_SOURCE) || \
defined(_XOPEN_SOURCE) || \
defined(_DEFAULT_SOURCE)
ASSERT(s->st_atim.tv_sec == t.st_atim.tv_sec);
ASSERT(s->st_atim.tv_nsec == t.st_atim.tv_nsec);
ASSERT(s->st_mtim.tv_sec == t.st_mtim.tv_sec);
ASSERT(s->st_mtim.tv_nsec == t.st_mtim.tv_nsec);
ASSERT(s->st_ctim.tv_sec == t.st_ctim.tv_sec);
ASSERT(s->st_ctim.tv_nsec == t.st_ctim.tv_nsec);
# if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# if defined(__FreeBSD__) || \
defined(__NetBSD__)
ASSERT(s->st_birthtim.tv_sec == t.st_birthtim.tv_sec);
ASSERT(s->st_birthtim.tv_nsec == t.st_birthtim.tv_nsec);
ASSERT(s->st_flags == t.st_flags);
Expand Down

0 comments on commit c02176a

Please sign in to comment.