diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-04-21 05:13:42 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-04-21 05:13:42 +0000 |
commit | bd0115839307ddffc9d78447ec3ac888a653ee2c (patch) | |
tree | 542291c8e776fd49a3947621c20eff5ac8bd66ba /lib/libarchive/archive_platform.h | |
parent | c7a52361b07ca43e22873e66ca4b6451f274228f (diff) | |
download | FreeBSD-src-bd0115839307ddffc9d78447ec3ac888a653ee2c.zip FreeBSD-src-bd0115839307ddffc9d78447ec3ac888a653ee2c.tar.gz |
More portability improvements, thanks to Juergen Lock.
High-resolution mtime/ctime/atime is not POSIX-standard, so hide
set/get of high-resolution time fields behind easily-mutable macros.
That makes it easier to change how those fields are accessed.
Diffstat (limited to 'lib/libarchive/archive_platform.h')
-rw-r--r-- | lib/libarchive/archive_platform.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/lib/libarchive/archive_platform.h b/lib/libarchive/archive_platform.h index 8a5552b..e2642dc 100644 --- a/lib/libarchive/archive_platform.h +++ b/lib/libarchive/archive_platform.h @@ -29,7 +29,9 @@ /* * This header is the first thing included in any of the libarchive * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. + * be dealt with here and not within individual source files. I'm + * actively trying to minimize #if blocks within the main source, + * since they obfuscate the code. */ #ifndef ARCHIVE_PLATFORM_H_INCLUDED @@ -57,10 +59,19 @@ #define ARCHIVE_ERRNO_PROGRAMMER EINVAL #define ARCHIVE_ERRNO_MISC (-1) +/* Fetch/set high-resolution time data through a struct stat pointer. */ +#define ARCHIVE_STAT_ATIME_NANOS(st) (st)->st_atimespec.tv_nsec +#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec +#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec +#define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atimespec.tv_nsec = (n) +#define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctimespec.tv_nsec = (n) +#define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtimespec.tv_nsec = (n) + /* * Older versions of inttypes.h don't have INT64_MAX, etc. Since * SUSv3 requires them to be macros when they are defined, we can - * easily test for and define them here if necessary. + * easily test for and define them here if necessary. Someday, we + * won't have to worry about non-C99-compliant systems. */ #ifndef INT64_MAX /* XXX Is this really necessary? XXX */ @@ -82,16 +93,32 @@ /* Linux */ #ifdef LINUX -#define _FILE_OFFSET_BITS 64 +#define _FILE_OFFSET_BITS 64 /* Needed for 64-bit file size handling. */ #include <inttypes.h> #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ #define ARCHIVE_ERRNO_PROGRAMMER EINVAL #define ARCHIVE_ERRNO_MISC (-1) -#define st_atimespec st_atim -#define st_mtimespec st_mtim -#define st_ctimespec st_ctim #define HAVE_STRERROR_R 1 #define STRERROR_R_CHAR_P 1 + +#ifdef HAVE_STRUCT_STAT_TIMESPEC +/* Fetch the nanosecond portion of the timestamp from a struct stat pointer. */ +#define ARCHIVE_STAT_ATIME_NANOS(pstat) (pstat)->st_atim.tv_nsec +#define ARCHIVE_STAT_CTIME_NANOS(pstat) (pstat)->st_ctim.tv_nsec +#define ARCHIVE_STAT_MTIME_NANOS(pstat) (pstat)->st_mtim.tv_nsec +#define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atim.tv_nsec = (n) +#define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctim.tv_nsec = (n) +#define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtim.tv_nsec = (n) +#else +/* High-res timestamps aren't available, so just use stubs here. */ +#define ARCHIVE_STAT_ATIME_NANOS(pstat) 0 +#define ARCHIVE_STAT_CTIME_NANOS(pstat) 0 +#define ARCHIVE_STAT_MTIME_NANOS(pstat) 0 +#define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) +#define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) +#define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) +#endif + #endif /* |