1
0
forked from aniani/vim

patch 8.2.0256: time and timer related code is spread out

Problem:    Time and timer related code is spread out.
Solution:   Move time and timer related code to a new file. (Yegappan
            Lakshmanan, closes #5604)
This commit is contained in:
Bram Moolenaar
2020-02-14 13:22:17 +01:00
parent f2cecb6c10
commit 0a8fed6231
24 changed files with 1096 additions and 1058 deletions

View File

@@ -4126,26 +4126,6 @@ get4c(FILE *fd)
return (int)n;
}
/*
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
* Returns -1 when encountering EOF.
*/
time_T
get8ctime(FILE *fd)
{
int c;
time_T n = 0;
int i;
for (i = 0; i < 8; ++i)
{
c = getc(fd);
if (c == EOF) return -1;
n = (n << 8) + c;
}
return n;
}
/*
* Read a string of length "cnt" from "fd" into allocated memory.
* Returns NULL when out of memory or unable to read that many bytes.
@@ -4191,68 +4171,6 @@ put_bytes(FILE *fd, long_u nr, int len)
return OK;
}
#ifdef _MSC_VER
# if (_MSC_VER <= 1200)
// This line is required for VC6 without the service pack. Also see the
// matching #pragma below.
# pragma optimize("", off)
# endif
#endif
/*
* Write time_T to file "fd" in 8 bytes.
* Returns FAIL when the write failed.
*/
int
put_time(FILE *fd, time_T the_time)
{
char_u buf[8];
time_to_bytes(the_time, buf);
return fwrite(buf, (size_t)8, (size_t)1, fd) == 1 ? OK : FAIL;
}
/*
* Write time_T to "buf[8]".
*/
void
time_to_bytes(time_T the_time, char_u *buf)
{
int c;
int i;
int bi = 0;
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
buf[bi++] = 0;
else
{
#if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4
c = (int)(wtime >> (i * 8));
#else
c = (int)((long_u)wtime >> (i * 8));
#endif
buf[bi++] = c;
}
}
}
#ifdef _MSC_VER
# if (_MSC_VER <= 1200)
# pragma optimize("", on)
# endif
#endif
#endif
#if defined(FEAT_QUICKFIX) || defined(FEAT_SPELL) || defined(PROTO)