mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
Switch to utimensat for newer POSIX versions
Some libcs like uClibc-ng can optionally disable deprecated functions. utime is one of them. When done so, both the header and the function go missing. This fixes flac_utime to work in such a situation.
This commit is contained in:
committed by
Erik de Castro Lopo
parent
5db5820932
commit
66dd7f05d7
@@ -112,9 +112,13 @@
|
|||||||
#include <sys/utime.h> /* for utime() */
|
#include <sys/utime.h> /* for utime() */
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
#include <fcntl.h>
|
||||||
|
#else
|
||||||
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
||||||
#include <utime.h> /* for utime() */
|
#include <utime.h> /* for utime() */
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined _MSC_VER
|
#if defined _MSC_VER
|
||||||
# if _MSC_VER >= 1800
|
# if _MSC_VER >= 1800
|
||||||
@@ -160,11 +164,15 @@
|
|||||||
|
|
||||||
#define flac_fopen fopen
|
#define flac_fopen fopen
|
||||||
#define flac_chmod chmod
|
#define flac_chmod chmod
|
||||||
#define flac_utime utime
|
|
||||||
#define flac_unlink unlink
|
#define flac_unlink unlink
|
||||||
#define flac_rename rename
|
#define flac_rename rename
|
||||||
#define flac_stat stat
|
#define flac_stat stat
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
#define flac_utime(a, b) utimensat (AT_FDCWD, a, *b, 0)
|
||||||
|
#else
|
||||||
|
#define flac_utime utime
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|||||||
@@ -3422,13 +3422,18 @@ FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
|
|||||||
|
|
||||||
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
||||||
{
|
{
|
||||||
struct utimbuf srctime;
|
|
||||||
|
|
||||||
FLAC__ASSERT(0 != filename);
|
FLAC__ASSERT(0 != filename);
|
||||||
FLAC__ASSERT(0 != stats);
|
FLAC__ASSERT(0 != stats);
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
struct timespec srctime[2] = {};
|
||||||
|
srctime[0].tv_sec = stats->st_atime;
|
||||||
|
srctime[1].tv_sec = stats->st_mtime;
|
||||||
|
#else
|
||||||
|
struct utimbuf srctime;
|
||||||
srctime.actime = stats->st_atime;
|
srctime.actime = stats->st_atime;
|
||||||
srctime.modtime = stats->st_mtime;
|
srctime.modtime = stats->st_mtime;
|
||||||
|
#endif
|
||||||
(void)flac_chmod(filename, stats->st_mode);
|
(void)flac_chmod(filename, stats->st_mode);
|
||||||
(void)flac_utime(filename, &srctime);
|
(void)flac_utime(filename, &srctime);
|
||||||
#if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__
|
#if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
#include <fcntl.h> /* for _O_BINARY */
|
#include <fcntl.h> /* for _O_BINARY */
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
||||||
#include <utime.h> /* for utime() */
|
|
||||||
#endif
|
#endif
|
||||||
#if defined __EMX__
|
#if defined __EMX__
|
||||||
#include <io.h> /* for setmode(), O_BINARY */
|
#include <io.h> /* for setmode(), O_BINARY */
|
||||||
@@ -53,11 +52,17 @@
|
|||||||
void grabbag__file_copy_metadata(const char *srcpath, const char *destpath)
|
void grabbag__file_copy_metadata(const char *srcpath, const char *destpath)
|
||||||
{
|
{
|
||||||
struct flac_stat_s srcstat;
|
struct flac_stat_s srcstat;
|
||||||
struct utimbuf srctime;
|
|
||||||
|
|
||||||
if(0 == flac_stat(srcpath, &srcstat)) {
|
if(0 == flac_stat(srcpath, &srcstat)) {
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
struct timespec srctime[2] = {};
|
||||||
|
srctime[0].tv_sec = srcstat.st_atime;
|
||||||
|
srctime[1].tv_sec = srcstat.st_mtime;
|
||||||
|
#else
|
||||||
|
struct utimbuf srctime;
|
||||||
srctime.actime = srcstat.st_atime;
|
srctime.actime = srcstat.st_atime;
|
||||||
srctime.modtime = srcstat.st_mtime;
|
srctime.modtime = srcstat.st_mtime;
|
||||||
|
#endif
|
||||||
(void)flac_chmod(destpath, srcstat.st_mode);
|
(void)flac_chmod(destpath, srcstat.st_mode);
|
||||||
(void)flac_utime(destpath, &srctime);
|
(void)flac_utime(destpath, &srctime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@
|
|||||||
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <sys/utime.h>
|
#include <sys/utime.h>
|
||||||
#else
|
|
||||||
#include <utime.h> /* for utime() */
|
|
||||||
#endif
|
#endif
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
|
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
|
||||||
#include <unistd.h> /* for chown(), unlink() */
|
#include <unistd.h> /* for chown(), unlink() */
|
||||||
@@ -271,13 +269,18 @@ bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
|
|||||||
|
|
||||||
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
||||||
{
|
{
|
||||||
struct utimbuf srctime;
|
|
||||||
|
|
||||||
FLAC__ASSERT(0 != filename);
|
FLAC__ASSERT(0 != filename);
|
||||||
FLAC__ASSERT(0 != stats);
|
FLAC__ASSERT(0 != stats);
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
struct timespec srctime[2] = {};
|
||||||
|
srctime[0].tv_sec = stats->st_atime;
|
||||||
|
srctime[1].tv_sec = stats->st_mtime;
|
||||||
|
#else
|
||||||
|
struct utimbuf srctime;
|
||||||
srctime.actime = stats->st_atime;
|
srctime.actime = stats->st_atime;
|
||||||
srctime.modtime = stats->st_mtime;
|
srctime.modtime = stats->st_mtime;
|
||||||
|
#endif
|
||||||
(void)flac_chmod(filename, stats->st_mode);
|
(void)flac_chmod(filename, stats->st_mode);
|
||||||
(void)flac_utime(filename, &srctime);
|
(void)flac_utime(filename, &srctime);
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
|
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
#include <io.h> /* for chmod() */
|
#include <io.h> /* for chmod() */
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
|
||||||
#include <utime.h> /* for utime() */
|
|
||||||
#include <unistd.h> /* for chown(), unlink() */
|
#include <unistd.h> /* for chown(), unlink() */
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h> /* for stat(), maybe chmod() */
|
#include <sys/stat.h> /* for stat(), maybe chmod() */
|
||||||
@@ -256,13 +255,18 @@ static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stat
|
|||||||
|
|
||||||
static void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
static void set_file_stats_(const char *filename, struct flac_stat_s *stats)
|
||||||
{
|
{
|
||||||
struct utimbuf srctime;
|
|
||||||
|
|
||||||
FLAC__ASSERT(0 != filename);
|
FLAC__ASSERT(0 != filename);
|
||||||
FLAC__ASSERT(0 != stats);
|
FLAC__ASSERT(0 != stats);
|
||||||
|
|
||||||
|
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
|
||||||
|
struct timespec srctime[2] = {};
|
||||||
|
srctime[0].tv_sec = stats->st_atime;
|
||||||
|
srctime[1].tv_sec = stats->st_mtime;
|
||||||
|
#else
|
||||||
|
struct utimbuf srctime;
|
||||||
srctime.actime = stats->st_atime;
|
srctime.actime = stats->st_atime;
|
||||||
srctime.modtime = stats->st_mtime;
|
srctime.modtime = stats->st_mtime;
|
||||||
|
#endif
|
||||||
(void)flac_chmod(filename, stats->st_mode);
|
(void)flac_chmod(filename, stats->st_mode);
|
||||||
(void)flac_utime(filename, &srctime);
|
(void)flac_utime(filename, &srctime);
|
||||||
#if !defined _MSC_VER && !defined __MINGW32__
|
#if !defined _MSC_VER && !defined __MINGW32__
|
||||||
|
|||||||
Reference in New Issue
Block a user