Skip to content

Commit

Permalink
Merge branch 'master' into clang-msvc-support
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Feb 3, 2021
2 parents dfbce15 + ece6fc9 commit 916d410
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2021-02-02 Riccardo Mottola <[email protected]>

* configure
* configure.ac
Add check for statbuf.st_mtim if available

* Source/NSFileManager.m
Use statbuf.st_mtim to get nanosecond precision in modification
date, also fix conversion of nanoseconds in creation date.

2021-01-29 Frederik Seiffert <[email protected]>

* Headers/Foundation/NSAffineTransform.h:
Expand Down
3 changes: 3 additions & 0 deletions Headers/GNUstepBase/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@
/* Define to 1 if `st_birthtimespec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC

/* Define to 1 if `st_mtim' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_MTIM

/* Define to 1 if you have the `symlink' function. */
#undef HAVE_SYMLINK

Expand Down
18 changes: 13 additions & 5 deletions Source/NSFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ - (BOOL) changeFileAttributes: (NSDictionary*)attributes atPath: (NSString*)path
struct timespec ub[2];
ub[0].tv_sec = 0;
ub[0].tv_nsec = UTIME_OMIT; // we don't touch access time
ub[1].tv_sec = truncl(ti);
ub[1].tv_nsec = (ti - (double)ub[1].tv_sec) * 1.0e6;
ub[1].tv_sec = (time_t)trunc(ti);
ub[1].tv_nsec = (long)trunc((ti - trunc(ti)) * 1.0e9);

ok = (utimensat(AT_FDCWD, lpath, ub, 0) == 0);
#elif defined(_POSIX_VERSION)
Expand Down Expand Up @@ -682,8 +682,8 @@ - (BOOL) changeFileAttributes: (NSDictionary*)attributes atPath: (NSString*)path
struct timespec ub[2];
ub[0].tv_sec = 0;
ub[0].tv_nsec = UTIME_OMIT; // we don't touch access time
ub[1].tv_sec = truncl(ti);
ub[1].tv_nsec = (ti - (double)ub[1].tv_sec) * 1.0e6;
ub[1].tv_sec = (time_t)trunc(ti);
ub[1].tv_nsec = (long)trunc((ti - trunc(ti)) * 1.0e9);

ok = (utimensat(AT_FDCWD, lpath, ub, 0) == 0);
#elif defined(_WIN32) || defined(_POSIX_VERSION)
Expand Down Expand Up @@ -3895,7 +3895,15 @@ - (BOOL) fileIsImmutable

- (NSDate*) fileModificationDate
{
return [NSDate dateWithTimeIntervalSince1970: statbuf.st_mtime];
NSTimeInterval ti;

#if defined (HAVE_STRUCT_STAT_ST_MTIM)
ti = statbuf.st_mtim.tv_sec + (double)statbuf.st_mtim.tv_nsec / 1.0e9;
#else
ti = (double)statbuf.st_mtime;
#endif

return [NSDate dateWithTimeIntervalSince1970: ti];
}

- (NSUInteger) filePosixPermissions
Expand Down
12 changes: 11 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -9543,7 +9543,17 @@ fi
fi
# Look for file creation date on NetBSD, FreeBSD, Darwin
# Look for file creation and modification date on NetBSD, FreeBSD, Darwin
ac_fn_c_check_member "$LINENO" "struct stat" "st_mtim" "ac_cv_member_struct_stat_st_mtim" "#include <sys/stat.h>
"
if test "x$ac_cv_member_struct_stat_st_mtim" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRUCT_STAT_ST_MTIM 1
_ACEOF
fi
ac_fn_c_check_member "$LINENO" "struct stat" "st_birthtime" "ac_cv_member_struct_stat_st_birthtime" "#include <sys/stat.h>
"
if test "x$ac_cv_member_struct_stat_st_birthtime" = xyes; then :
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2444,8 +2444,8 @@ fi
AC_CHECK_FUNCS(getcwd)
AC_HEADER_DIRENT

# Look for file creation date on NetBSD, FreeBSD, Darwin
AC_CHECK_MEMBERS([struct stat.st_birthtime, struct stat.st_birthtimespec, struct stat.st_birthtim, struct stat64.st_birthtimespec],
# Look for file creation and modification date on NetBSD, FreeBSD, Darwin
AC_CHECK_MEMBERS([struct stat.st_mtim, struct stat.st_birthtime, struct stat.st_birthtimespec, struct stat.st_birthtim, struct stat64.st_birthtimespec],
,,[#include <sys/stat.h>])

#--------------------------------------------------------------------
Expand Down

0 comments on commit 916d410

Please sign in to comment.