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.

97 lines
3.2 KiB

  1. From 245a69c0f5784ba89c28301263bcfd5785ebe0ea Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Tue, 30 Jul 2019 17:17:07 -0700
  4. Subject: [PATCH] zstd: Don't use utime on Linux
  5. utime is deprecated by POSIX 2008 and optionally not available with
  6. uClibc-ng.
  7. Got rid of a few useless headers in timefn.h.
  8. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  9. ---
  10. programs/platform.h | 2 +-
  11. programs/timefn.h | 6 ------
  12. programs/util.c | 10 ++++++++++
  13. programs/util.h | 5 +++--
  14. 4 files changed, 14 insertions(+), 9 deletions(-)
  15. diff --git a/programs/platform.h b/programs/platform.h
  16. index 38ded8727..5934e59cf 100644
  17. --- a/programs/platform.h
  18. +++ b/programs/platform.h
  19. @@ -92,7 +92,7 @@ extern "C" {
  20. # if defined(__linux__) || defined(__linux)
  21. # ifndef _POSIX_C_SOURCE
  22. -# define _POSIX_C_SOURCE 200112L /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */
  23. +# define _POSIX_C_SOURCE 200809L /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */
  24. # endif
  25. # endif
  26. # include <unistd.h> /* declares _POSIX_VERSION */
  27. diff --git a/programs/timefn.h b/programs/timefn.h
  28. index d1ddd31b1..2db3765b9 100644
  29. --- a/programs/timefn.h
  30. +++ b/programs/timefn.h
  31. @@ -19,12 +19,6 @@ extern "C" {
  32. /*-****************************************
  33. * Dependencies
  34. ******************************************/
  35. -#include <sys/types.h> /* utime */
  36. -#if defined(_MSC_VER)
  37. -# include <sys/utime.h> /* utime */
  38. -#else
  39. -# include <utime.h> /* utime */
  40. -#endif
  41. #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
  42. diff --git a/programs/util.c b/programs/util.c
  43. index fb77d1783..3a2e9e28f 100644
  44. --- a/programs/util.c
  45. +++ b/programs/util.c
  46. @@ -54,14 +54,24 @@ int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
  47. int UTIL_setFileStat(const char *filename, stat_t *statbuf)
  48. {
  49. int res = 0;
  50. +#if defined(_WIN32)
  51. struct utimbuf timebuf;
  52. +#else
  53. + struct timespec timebuf[2];
  54. +#endif
  55. if (!UTIL_isRegularFile(filename))
  56. return -1;
  57. +#if defined(_WIN32)
  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_sec = time(NULL);
  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 */
  68. diff --git a/programs/util.h b/programs/util.h
  69. index d6e5bb550..71d4c7c77 100644
  70. --- a/programs/util.h
  71. +++ b/programs/util.h
  72. @@ -25,12 +25,13 @@ extern "C" {
  73. #include <stdio.h> /* fprintf */
  74. #include <sys/types.h> /* stat, utime */
  75. #include <sys/stat.h> /* stat, chmod */
  76. -#if defined(_MSC_VER)
  77. +#if defined(_WIN32)
  78. # include <sys/utime.h> /* utime */
  79. # include <io.h> /* _chmod */
  80. #else
  81. +# include <fcntl.h> /* AT_FDCWD */
  82. +# include <sys/stat.h> /* utimensat */
  83. # include <unistd.h> /* chown, stat */
  84. -# include <utime.h> /* utime */
  85. #endif
  86. #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
  87. #include "mem.h" /* U32, U64 */