Use utimensat() to set file modification date, if available.

This commit is contained in:
Riccardo Mottola 2020-05-01 02:03:25 +02:00
parent e23ab3b394
commit 21c79c3500
5 changed files with 29 additions and 7 deletions

View file

@ -1,3 +1,13 @@
2010-05-01 Riccardo Mottola <rm@gnu.org>
* configure
* configure.ac
* Headers/GNUstepBase/config.h.in
Check for utimensat()
* Source/NSFileManager.m: (changeFileAttributes:)
Use utimensat() to set file modification date, if available.
2020-04-26 Fred Kiefer <fredkiefer@gmx.de>
* Source/NSLocale.m: Respect NSLocaleCalendarIdentifier if

View file

@ -755,6 +755,9 @@
/* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP
/* Define to 1 if you have the `utimensat' function. */
#undef HAVE_UTIMENSAT
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H

View file

@ -569,8 +569,9 @@ static NSStringEncoding defaultEncoding;
{
BOOL ok = NO;
struct _STATB sb;
#if defined(_WIN32) || defined(_POSIX_VERSION)
#if defined (HAVE_UTIMENSAT)
struct timespec ub[2];
#elif defined(_WIN32) || defined(_POSIX_VERSION)
struct _UTIMB ub;
#else
time_t ub[2];
@ -588,13 +589,21 @@ static NSStringEncoding defaultEncoding;
#endif
else
{
#if defined(_WIN32) || defined(_POSIX_VERSION)
NSTimeInterval ti = [date timeIntervalSince1970];
#if defined (HAVE_UTIMENSAT)
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;
ok = (utimensat(0, lpath, ub, 0) == 0);
#elif defined(_WIN32) || defined(_POSIX_VERSION)
ub.actime = sb.st_atime;
ub.modtime = [date timeIntervalSince1970];
ub.modtime = ti;
ok = (_UTIME(lpath, &ub) == 0);
#else
ub[0] = sb.st_atime;
ub[1] = [date timeIntervalSince1970];
ub[1] = ti;
ok = (_UTIME(lpath, ub) == 0);
#endif
}

2
configure vendored
View file

@ -8692,7 +8692,7 @@ _ACEOF
fi
for ac_func in statvfs link symlink readlink geteuid getlogin getpwnam getpwnam_r getpwuid getpwuid_r getgrgid getgrgid_r getgrnam getgrnam_r rint getopt malloc_usable_size
for ac_func in utimensat statvfs link symlink readlink geteuid getlogin getpwnam getpwnam_r getpwuid getpwuid_r getgrgid getgrgid_r getgrnam getgrnam_r rint getopt malloc_usable_size
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View file

@ -2228,7 +2228,7 @@ AC_CHECK_HEADERS([sys/mount.h], [], [],
AC_CHECK_HEADERS(sys/types.h windows.h locale.h langinfo.h)
saved_LIBS="$LIBS"
AC_CHECK_LIB(m, main)
AC_CHECK_FUNCS(statvfs link symlink readlink geteuid getlogin getpwnam getpwnam_r getpwuid getpwuid_r getgrgid getgrgid_r getgrnam getgrnam_r rint getopt malloc_usable_size)
AC_CHECK_FUNCS(utimensat statvfs link symlink readlink geteuid getlogin getpwnam getpwnam_r getpwuid getpwuid_r getgrgid getgrgid_r getgrnam getgrnam_r rint getopt malloc_usable_size)
LIBS="$saved_LIBS"
AC_CACHE_CHECK([for pw_gecos field in struct passwd],