aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/misc2.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-12-24 16:07:49 -0500
committerJustin M. Keyes <justinkz@gmail.com>2014-12-24 16:07:49 -0500
commitf13b90c064e817664f48bb7f0ce3e69cd54943c7 (patch)
tree01ce692e8ee8c3a0e9dcf3b99c78f20f4320c658 /src/nvim/misc2.c
parent59985523b851fe61b62afcef69f4564f064cbc0a (diff)
parent516405b6012e0c99d8bc073a7dead3c3206a184e (diff)
downloadrneovim-f13b90c064e817664f48bb7f0ce3e69cd54943c7.tar.gz
rneovim-f13b90c064e817664f48bb7f0ce3e69cd54943c7.tar.bz2
rneovim-f13b90c064e817664f48bb7f0ce3e69cd54943c7.zip
Merge pull request #1715 from elmart/remove-long_u-3
Remove project-specific integer types: long_u. (3)
Diffstat (limited to 'src/nvim/misc2.c')
-rw-r--r--src/nvim/misc2.c47
1 files changed, 11 insertions, 36 deletions
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index e6531ee1b2..1407dcf04b 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -501,47 +501,22 @@ char *read_string(FILE *fd, size_t cnt)
return (char *)str;
}
-/*
- * Write a number to file "fd", MSB first, in "len" bytes.
- */
-int put_bytes(FILE *fd, long_u nr, int len)
+/// Write a number to file "fd", MSB first, in "len" bytes.
+/// @return OK/FAIL.
+int put_bytes(FILE *fd, uintmax_t number, unsigned int len)
{
- int i;
-
- for (i = len - 1; i >= 0; --i)
- if (putc((int)(nr >> (i * 8)), fd) == EOF)
+ for (unsigned int i = len - 1; i < len; --i)
+ if (putc((int)(number >> (i * 8)), fd) == EOF)
return FAIL;
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);
}
}