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.

109 lines
3.3 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. --- a/include/share/compat.h
  23. +++ b/include/share/compat.h
  24. @@ -112,9 +112,13 @@
  25. #include <sys/utime.h> /* for utime() */
  26. #endif
  27. #else
  28. +#if _POSIX_C_SOURCE >= 200809L
  29. +#include <fcntl.h>
  30. +#else
  31. #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
  32. #include <utime.h> /* for utime() */
  33. #endif
  34. +#endif
  35. #if defined _MSC_VER
  36. # if _MSC_VER >= 1800
  37. @@ -160,11 +164,15 @@
  38. #define flac_fopen fopen
  39. #define flac_chmod chmod
  40. -#define flac_utime utime
  41. #define flac_unlink unlink
  42. #define flac_rename rename
  43. #define flac_stat stat
  44. +#if _POSIX_C_SOURCE >= 200809L
  45. +#define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0)
  46. +#else
  47. +#define flac_utime utime
  48. +#endif
  49. #endif
  50. #ifdef _WIN32
  51. --- a/src/libFLAC/metadata_iterators.c
  52. +++ b/src/libFLAC/metadata_iterators.c
  53. @@ -3422,13 +3422,18 @@ FLAC__bool get_file_stats_(const char *f
  54. void set_file_stats_(const char *filename, struct flac_stat_s *stats)
  55. {
  56. - struct utimbuf srctime;
  57. -
  58. FLAC__ASSERT(0 != filename);
  59. FLAC__ASSERT(0 != stats);
  60. +#if _POSIX_C_SOURCE >= 200809L
  61. + struct timespec srctime[2] = {};
  62. + srctime[0].tv_sec = stats->st_atime;
  63. + srctime[1].tv_sec = stats->st_mtime;
  64. +#else
  65. + struct utimbuf srctime;
  66. srctime.actime = stats->st_atime;
  67. srctime.modtime = stats->st_mtime;
  68. +#endif
  69. (void)flac_chmod(filename, stats->st_mode);
  70. (void)flac_utime(filename, &srctime);
  71. #if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__
  72. --- a/src/share/grabbag/file.c
  73. +++ b/src/share/grabbag/file.c
  74. @@ -27,7 +27,6 @@
  75. #include <fcntl.h> /* for _O_BINARY */
  76. #else
  77. #include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
  78. -#include <utime.h> /* for utime() */
  79. #endif
  80. #if defined __EMX__
  81. #include <io.h> /* for setmode(), O_BINARY */
  82. @@ -53,11 +52,17 @@
  83. void grabbag__file_copy_metadata(const char *srcpath, const char *destpath)
  84. {
  85. struct flac_stat_s srcstat;
  86. - struct utimbuf srctime;
  87. if(0 == flac_stat(srcpath, &srcstat)) {
  88. +#if _POSIX_C_SOURCE >= 200809L
  89. + struct timespec srctime[2] = {};
  90. + srctime[0].tv_sec = srcstat.st_atime;
  91. + srctime[1].tv_sec = srcstat.st_mtime;
  92. +#else
  93. + struct utimbuf srctime;
  94. srctime.actime = srcstat.st_atime;
  95. srctime.modtime = srcstat.st_mtime;
  96. +#endif
  97. (void)flac_chmod(destpath, srcstat.st_mode);
  98. (void)flac_utime(destpath, &srctime);
  99. }