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.

118 lines
3.6 KiB

  1. Return-Path: <rosenp@gmail.com>
  2. Received: from localhost.localdomain (76-14-106-55.rk.wavecable.com. [76.14.106.55])
  3. by smtp.gmail.com with ESMTPSA id f19sm148509170pfk.180.2019.08.09.13.01.06
  4. for <flac-dev@xiph.org>
  5. (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);
  6. Fri, 09 Aug 2019 13:01:06 -0700 (PDT)
  7. From: Rosen Penev <rosenp@gmail.com>
  8. To: flac-dev@xiph.org
  9. Subject: [PATCH] Switch to utimensat for newer POSIX versions
  10. Date: Fri, 9 Aug 2019 13:01:05 -0700
  11. Message-Id: <20190809200105.1443-1-rosenp@gmail.com>
  12. X-Mailer: git-send-email 2.17.1
  13. Some libcs like uClibc-ng can optionally disable deprecated functions.
  14. utime is one of them. When done so, both the header and the function go
  15. missing.
  16. This fixes flac_utime to work in such a situation.
  17. ---
  18. include/share/compat.h | 10 +++++++++-
  19. src/libFLAC/metadata_iterators.c | 9 +++++++--
  20. src/share/grabbag/file.c | 9 +++++++--
  21. 3 files changed, 23 insertions(+), 5 deletions(-)
  22. diff --git a/include/share/compat.h b/include/share/compat.h
  23. index f3041655..a063c083 100644
  24. --- a/include/share/compat.h
  25. +++ b/include/share/compat.h
  26. @@ -112,9 +112,13 @@
  27. #include <sys/utime.h> /* for utime() */
  28. #endif
  29. #else
  30. +#if _POSIX_C_SOURCE >= 200809L
  31. +#include <fcntl.h>
  32. +#else
  33. #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
  34. #include <utime.h> /* for utime() */
  35. #endif
  36. +#endif
  37. #if defined _MSC_VER
  38. # if _MSC_VER >= 1800
  39. @@ -160,11 +164,15 @@
  40. #define flac_fopen fopen
  41. #define flac_chmod chmod
  42. -#define flac_utime utime
  43. #define flac_unlink unlink
  44. #define flac_rename rename
  45. #define flac_stat stat
  46. +#if _POSIX_C_SOURCE >= 200809L
  47. +#define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0)
  48. +#else
  49. +#define flac_utime utime
  50. +#endif
  51. #endif
  52. #ifdef _WIN32
  53. diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c
  54. index 352a6c7a..d5255eb9 100644
  55. --- a/src/libFLAC/metadata_iterators.c
  56. +++ b/src/libFLAC/metadata_iterators.c
  57. @@ -3422,13 +3422,18 @@ FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
  58. void set_file_stats_(const char *filename, struct flac_stat_s *stats)
  59. {
  60. - struct utimbuf srctime;
  61. -
  62. FLAC__ASSERT(0 != filename);
  63. FLAC__ASSERT(0 != stats);
  64. +#if _POSIX_C_SOURCE >= 200809L
  65. + struct timespec srctime[2] = {};
  66. + srctime[0].tv_sec = stats->st_atime;
  67. + srctime[1].tv_sec = stats->st_mtime;
  68. +#else
  69. + struct utimbuf srctime;
  70. srctime.actime = stats->st_atime;
  71. srctime.modtime = stats->st_mtime;
  72. +#endif
  73. (void)flac_chmod(filename, stats->st_mode);
  74. (void)flac_utime(filename, &srctime);
  75. #if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__
  76. diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c
  77. index 2c67bebf..edd835a6 100644
  78. --- a/src/share/grabbag/file.c
  79. +++ b/src/share/grabbag/file.c
  80. @@ -27,7 +27,6 @@
  81. #include <fcntl.h> /* for _O_BINARY */
  82. #else
  83. #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
  84. -#include <utime.h> /* for utime() */
  85. #endif
  86. #if defined __EMX__
  87. #include <io.h> /* for setmode(), O_BINARY */
  88. @@ -53,11 +52,17 @@
  89. void grabbag__file_copy_metadata(const char *srcpath, const char *destpath)
  90. {
  91. struct flac_stat_s srcstat;
  92. - struct utimbuf srctime;
  93. if(0 == flac_stat(srcpath, &srcstat)) {
  94. +#if _POSIX_C_SOURCE >= 200809L
  95. + struct timespec srctime[2] = {};
  96. + srctime[0].tv_sec = srcstat.st_atime;
  97. + srctime[1].tv_sec = srcstat.st_mtime;
  98. +#else
  99. + struct utimbuf srctime;
  100. srctime.actime = srcstat.st_atime;
  101. srctime.modtime = srcstat.st_mtime;
  102. +#endif
  103. (void)flac_chmod(destpath, srcstat.st_mode);
  104. (void)flac_utime(destpath, &srctime);
  105. }
  106. --
  107. 2.17.1