@@ -23,16 +23,27 @@ extern "C" {
23
23
#include <errno.h>
24
24
#include <assert.h>
25
25
26
+ #if defined(__FreeBSD__ )
27
+ #include <sys/param.h> /* __FreeBSD_version */
28
+ #endif /* #ifdef __FreeBSD__ */
29
+
26
30
#if defined(_WIN32 )
27
31
# include <sys/utime.h> /* utime */
28
32
# include <io.h> /* _chmod */
33
+ # define ZSTD_USE_UTIMENSAT 0
29
34
#else
30
35
# include <unistd.h> /* chown, stat */
31
- # if PLATFORM_POSIX_VERSION < 200809L || !defined(st_mtime )
32
- # include <utime.h> /* utime */
36
+ # include <sys/stat.h> /* utimensat, st_mtime */
37
+ # if (PLATFORM_POSIX_VERSION >= 200809L && defined(st_mtime )) \
38
+ || (defined(__FreeBSD__ ) && __FreeBSD_version >= 1100056 )
39
+ # define ZSTD_USE_UTIMENSAT 1
33
40
# else
41
+ # define ZSTD_USE_UTIMENSAT 0
42
+ # endif
43
+ # if ZSTD_USE_UTIMENSAT
34
44
# include <fcntl.h> /* AT_FDCWD */
35
- # include <sys/stat.h> /* utimensat */
45
+ # else
46
+ # include <utime.h> /* utime */
36
47
# endif
37
48
#endif
38
49
@@ -259,7 +270,12 @@ int UTIL_utime(const char* filename, const stat_t *statbuf)
259
270
* that struct stat has a struct timespec st_mtim member. We need this
260
271
* check because there are some platforms that claim to be POSIX 2008
261
272
* compliant but which do not have st_mtim... */
262
- #if (PLATFORM_POSIX_VERSION >= 200809L ) && defined(st_mtime )
273
+ /* FreeBSD has implemented POSIX 2008 for a long time but still only
274
+ * advertises support for POSIX 2001. They have a version macro that
275
+ * lets us safely gate them in.
276
+ * See https://docs.freebsd.org/en/books/porters-handbook/versions/.
277
+ */
278
+ #if ZSTD_USE_UTIMENSAT
263
279
{
264
280
/* (atime, mtime) */
265
281
struct timespec timebuf [2 ] = { {0 , UTIME_NOW } };
@@ -1546,7 +1562,6 @@ int UTIL_countCores(int logical)
1546
1562
1547
1563
#elif defined(__FreeBSD__ )
1548
1564
1549
- #include <sys/param.h>
1550
1565
#include <sys/sysctl.h>
1551
1566
1552
1567
/* Use physical core sysctl when available
0 commit comments