You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

  1. From e9d5a3cbbb47eb0f785a409d836225b592b250f3 Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Tue, 30 Jul 2019 22:13:51 -0700
  4. Subject: [PATCH] util.h: Remove deprecated utime for non-Windows
  5. utime was deprecated in POSIX 2008.
  6. ---
  7. programs/platform.h | 2 +-
  8. programs/util.h | 17 ++++++++++++++++-
  9. 2 files changed, 17 insertions(+), 2 deletions(-)
  10. diff --git a/programs/platform.h b/programs/platform.h
  11. index c0b38402..7e2cb58f 100644
  12. --- a/programs/platform.h
  13. +++ b/programs/platform.h
  14. @@ -86,7 +86,7 @@ extern "C" {
  15. # else
  16. # if defined(__linux__) || defined(__linux)
  17. # ifndef _POSIX_C_SOURCE
  18. -# define _POSIX_C_SOURCE 200112L /* use feature test macro */
  19. +# define _POSIX_C_SOURCE 200809L /* use feature test macro */
  20. # endif
  21. # endif
  22. # include <unistd.h> /* declares _POSIX_VERSION */
  23. diff --git a/programs/util.h b/programs/util.h
  24. index 1dd515ce..112dddbf 100644
  25. --- a/programs/util.h
  26. +++ b/programs/util.h
  27. @@ -37,12 +37,17 @@ extern "C" {
  28. #include <assert.h>
  29. #include <sys/types.h> /* stat, utime */
  30. #include <sys/stat.h> /* stat */
  31. -#if defined(_MSC_VER)
  32. +#if defined(_WIN32)
  33. # include <sys/utime.h> /* utime */
  34. # include <io.h> /* _chmod */
  35. #else
  36. # include <unistd.h> /* chown, stat */
  37. +#if PLATFORM_POSIX_VERSION < 200809L
  38. # include <utime.h> /* utime */
  39. +#else
  40. +# include <fcntl.h> /* AT_FDCWD */
  41. +# include <sys/stat.h> /* for utimensat */
  42. +#endif
  43. #endif
  44. #include <time.h> /* time */
  45. #include <limits.h> /* INT_MAX */
  46. @@ -287,14 +292,24 @@ UTIL_STATIC int UTIL_isRegFile(const char* infilename);
  47. UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf)
  48. {
  49. int res = 0;
  50. +#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
  51. struct utimbuf timebuf;
  52. +#else
  53. + struct timespec timebuf[2] = {};
  54. +#endif
  55. if (!UTIL_isRegFile(filename))
  56. return -1;
  57. +#if defined(_WIN32) || (PLATFORM_POSIX_VERSION < 200809L)
  58. timebuf.actime = time(NULL);
  59. timebuf.modtime = statbuf->st_mtime;
  60. res += utime(filename, &timebuf); /* set access and modification times */
  61. +#else
  62. + timebuf[0].tv_nsec = UTIME_NOW;
  63. + timebuf[1].tv_sec = statbuf->st_mtime;
  64. + res += utimensat(AT_FDCWD, filename, timebuf, 0); /* set access and modification times */
  65. +#endif
  66. #if !defined(_WIN32)
  67. res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */