aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/CMakeLists.txt1
-rw-r--r--config/config.h.in1
-rw-r--r--src/nvim/misc2.c34
3 files changed, 6 insertions, 30 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
index 0f5dd7d984..aab4b5c23d 100644
--- a/config/CMakeLists.txt
+++ b/config/CMakeLists.txt
@@ -5,7 +5,6 @@ include(CheckIncludeFiles)
check_type_size("int" SIZEOF_INT)
check_type_size("long" SIZEOF_LONG)
-check_type_size("time_t" SIZEOF_TIME_T)
check_type_size("off_t" SIZEOF_OFF_T)
check_type_size("void *" SIZEOF_VOID_PTR)
diff --git a/config/config.h.in b/config/config.h.in
index 79dabc61e4..005eb1ccb0 100644
--- a/config/config.h.in
+++ b/config/config.h.in
@@ -11,7 +11,6 @@
#define SIZEOF_INT @SIZEOF_INT@
#define SIZEOF_LONG @SIZEOF_LONG@
-#define SIZEOF_TIME_T @SIZEOF_TIME_T@
#define SIZEOF_OFF_T @SIZEOF_OFF_T@
#if @SIZEOF_VOID_PTR@ == 8
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index d624f52879..1407dcf04b 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -511,34 +511,12 @@ int put_bytes(FILE *fd, uintmax_t number, unsigned int len)
return OK;
}
-
-/*
- * Write time_t to file "fd" in 8 bytes.
- */
-void put_time(FILE *fd, time_t the_time)
+/// Write time_t to file "fd" in 8 bytes.
+void put_time(FILE *fd, time_t time_)
{
- int c;
- int i;
- time_t wtime = the_time;
-
- /* time_t can be up to 8 bytes in size, more than long_u, thus we
- * can't use put_bytes() here.
- * Another problem is that ">>" may do an arithmetic shift that keeps the
- * sign. This happens for large values of wtime. A cast to long_u may
- * truncate if time_t is 8 bytes. So only use a cast when it is 4 bytes,
- * it's safe to assume that long_u is 4 bytes or more and when using 8
- * bytes the top bit won't be set. */
- for (i = 7; i >= 0; --i) {
- if (i + 1 > (int)sizeof(time_t))
- /* ">>" doesn't work well when shifting more bits than avail */
- putc(0, fd);
- else {
-#if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4
- c = (int)(wtime >> (i * 8));
-#else
- c = (int)((long_u)wtime >> (i * 8));
-#endif
- putc(c, fd);
- }
+ // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
+ // systems, thus we can't use put_bytes() here.
+ for (unsigned int i = 7; i < 8; --i) {
+ putc((int)((uint64_t)time_ >> (i * 8)), fd);
}
}