[libav-devel] [PATCH 2/2] time_internal: Prefix fallback versions of gmtime_r/localtime_r with ff_

Martin Storsjö martin at martin.st
Wed Apr 10 10:48:37 CEST 2019


Use a macro to redirect calling code from the official name to the
ff_ prefixed one.

Detecting these functions in configure can be tricky (on mingw, they
are conditionally available depending on posix feature defines).
If configure didn't detect them, but they still are visible at
compile time (due to an unrelated header defining the posix feature
defines), providing the local fallback versions with a prefixed
name is safer.
---
This fix is another alternative to improving the configure checks.
Making configure use check_func_header probably is safe, but
always forcing posix defines on mingw feels slightly more dubious.
---
 libavutil/time_internal.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavutil/time_internal.h b/libavutil/time_internal.h
index d0597db050..8e647fdc16 100644
--- a/libavutil/time_internal.h
+++ b/libavutil/time_internal.h
@@ -23,7 +23,7 @@
 #include "config.h"
 
 #if !HAVE_GMTIME_R && !defined(gmtime_r)
-static inline struct tm *gmtime_r(const time_t* clock, struct tm *result)
+static inline struct tm *ff_gmtime_r(const time_t* clock, struct tm *result)
 {
     struct tm *ptr = gmtime(clock);
     if (!ptr)
@@ -31,10 +31,11 @@ static inline struct tm *gmtime_r(const time_t* clock, struct tm *result)
     *result = *ptr;
     return result;
 }
+#define gmtime_r ff_gmtime_r
 #endif
 
 #if !HAVE_LOCALTIME_R && !defined(localtime_r)
-static inline struct tm *localtime_r(const time_t* clock, struct tm *result)
+static inline struct tm *ff_localtime_r(const time_t* clock, struct tm *result)
 {
     struct tm *ptr = localtime(clock);
     if (!ptr)
@@ -42,6 +43,7 @@ static inline struct tm *localtime_r(const time_t* clock, struct tm *result)
     *result = *ptr;
     return result;
 }
+#define localtime_r ff_localtime_r
 #endif
 
 #endif /* AVUTIL_TIME_INTERNAL_H */
-- 
2.17.1



More information about the libav-devel mailing list