aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-08-14 12:52:56 +0100
committerRon Yorston <rmy@pobox.com>2024-08-14 13:10:19 +0100
commit6481bb22b5e6d60909d09cf6179412c4f34b9b3c (patch)
tree63265600738004f99ad1afcae54d209405bc604d
parent6e82b6c6a0b55fdc156f7065d177e530e417520c (diff)
downloadbusybox-w32-6481bb22b5e6d60909d09cf6179412c4f34b9b3c.tar.gz
busybox-w32-6481bb22b5e6d60909d09cf6179412c4f34b9b3c.tar.bz2
busybox-w32-6481bb22b5e6d60909d09cf6179412c4f34b9b3c.zip
win32: use 64-bit time on 32-bit platforms
To avoid problems with dates in 2038 and beyond use 64-bit time values on 32-bit platforms. - Mostly this just requires a few preprocessor macros to choose the appropriate functions, structs and typedefs. - We have our own implementations of nanosleep(), clock_gettime() and clock_settime(). Omit the Windows include file that declares them. - Apply the hack for struct timeval in the 'ts' applet on 32-bit. Adds 1624 bytes on 32-bit, none on 64-bit. (GitHub issue #446)
-rw-r--r--include/libbb.h6
-rw-r--r--include/mingw.h14
-rw-r--r--miscutils/ts.c4
3 files changed, 22 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h
index e5000831f..17fb6fae6 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -10,6 +10,12 @@
10#ifndef LIBBB_H 10#ifndef LIBBB_H
11#define LIBBB_H 1 11#define LIBBB_H 1
12 12
13#if ENABLE_PLATFORM_MINGW32
14/* We have our own nanosleep(), clock_gettime() and clock_settime(). */
15/* Skip the Windows include file that declares them. */
16# define WIN_PTHREADS_TIME_H
17#endif
18
13#include "platform.h" 19#include "platform.h"
14 20
15#include <ctype.h> 21#include <ctype.h>
diff --git a/include/mingw.h b/include/mingw.h
index 7a07de619..104ca3b2e 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -2,6 +2,17 @@
2#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; } 2#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; }
3#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; } 3#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; }
4 4
5/* Use 64-bit time on 32-bit platforms. */
6#if !defined(_WIN64)
7# define time_t __time64_t
8# define ctime(t) _ctime64(t)
9# define localtime(t) _localtime64(t)
10# define time(t) _time64(t)
11# define gmtime(t) _gmtime64(t)
12# define mktime(t) _mktime64(t)
13# define timespec _timespec64
14#endif
15
5/* 16/*
6 * sys/types.h 17 * sys/types.h
7 */ 18 */
@@ -297,6 +308,9 @@ struct timespec {
297}; 308};
298#endif 309#endif
299 310
311typedef int clockid_t;
312#define CLOCK_REALTIME 0
313
300time_t timegm(struct tm *tm); 314time_t timegm(struct tm *tm);
301 315
302int nanosleep(const struct timespec *req, struct timespec *rem); 316int nanosleep(const struct timespec *req, struct timespec *rem);
diff --git a/miscutils/ts.c b/miscutils/ts.c
index f5e727eb5..fb669b858 100644
--- a/miscutils/ts.c
+++ b/miscutils/ts.c
@@ -25,7 +25,7 @@ int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
25int ts_main(int argc UNUSED_PARAM, char **argv) 25int ts_main(int argc UNUSED_PARAM, char **argv)
26{ 26{
27 struct timeval base; 27 struct timeval base;
28#if ENABLE_PLATFORM_MINGW32 && !defined(_USE_32BIT_TIME_T) 28#if ENABLE_PLATFORM_MINGW32
29 time_t t; 29 time_t t;
30#endif 30#endif
31 unsigned opt; 31 unsigned opt;
@@ -76,7 +76,7 @@ int ts_main(int argc UNUSED_PARAM, char **argv)
76 if (opt & 1) /* -i */ 76 if (opt & 1) /* -i */
77 base = ts1; 77 base = ts1;
78 } 78 }
79#if ENABLE_PLATFORM_MINGW32 && !defined(_USE_32BIT_TIME_T) 79#if ENABLE_PLATFORM_MINGW32
80 t = ts.tv_sec; 80 t = ts.tv_sec;
81 localtime_r(&t, &tm_time); 81 localtime_r(&t, &tm_time);
82#else 82#else