mirror of https://github.com/vitalif/e2fsprogs
util: allow subst to build on systems that do not have utimes()
Make subst more portable so it can deal with such oler systems that do not have utimes(). Note that it is important that subst build correctly without an autoconf-generated config.h (since that is what happens on a cross-compile), as well as using whatever features are available as determined by autoconf when doing a native build. We currently assume the presence of utime(), but not utimes() or futimes(). Signed-off-by: Theodore Ts'o <tytso@mit.edu>test-maint
parent
0745e78741
commit
441eb337a8
|
@ -13003,7 +13003,7 @@ if test "$ac_res" != no; then :
|
|||
fi
|
||||
|
||||
fi
|
||||
for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime valloc
|
||||
for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime utimes valloc
|
||||
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"
|
||||
|
|
|
@ -1087,6 +1087,7 @@ AC_CHECK_FUNCS(m4_flatten([
|
|||
sysconf
|
||||
usleep
|
||||
utime
|
||||
utimes
|
||||
valloc
|
||||
]))
|
||||
dnl
|
||||
|
|
|
@ -536,6 +536,9 @@
|
|||
/* Define to 1 if you have the `utime' function. */
|
||||
#undef HAVE_UTIME
|
||||
|
||||
/* Define to 1 if you have the `utimes' function. */
|
||||
#undef HAVE_UTIMES
|
||||
|
||||
/* Define to 1 if you have the <utime.h> header file. */
|
||||
#undef HAVE_UTIME_H
|
||||
|
||||
|
|
27
util/subst.c
27
util/subst.c
|
@ -7,6 +7,8 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#else
|
||||
#define HAVE_SYS_TIME_H
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
@ -291,6 +293,23 @@ static int compare_file(FILE *old_f, FILE *new_f)
|
|||
return retval;
|
||||
}
|
||||
|
||||
void set_utimes(const char *filename, int fd, const struct timeval times[2])
|
||||
{
|
||||
#ifdef HAVE_FUTIMES
|
||||
if (futimes(fd, times) < 0)
|
||||
perror("futimes");
|
||||
#elif HAVE_UTIMES
|
||||
if (utimes(filename, times) < 0)
|
||||
perror("utimes");
|
||||
#else
|
||||
struct utimbuf ut;
|
||||
|
||||
ut.actime = times[0].tv_sec;
|
||||
ut.modtime = times[1].tv_sec;
|
||||
if (utime(filename, &ut) < 0)
|
||||
perror("utime");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -405,13 +424,7 @@ int main(int argc, char **argv)
|
|||
tv[0] = tv[1];
|
||||
else if (verbose)
|
||||
printf("Using original atime\n");
|
||||
#ifdef HAVE_FUTIMES
|
||||
if (futimes(fileno(old), tv) < 0)
|
||||
perror("futimes");
|
||||
#else
|
||||
if (utimes(outfn, tv) < 0)
|
||||
perror("utimes");
|
||||
#endif
|
||||
set_utimes(outfn, fileno(old), tv);
|
||||
}
|
||||
fclose(out);
|
||||
if (unlink(newfn) < 0)
|
||||
|
|
Loading…
Reference in New Issue