Skip to content

Commit

Permalink
Populate millitm in ftime()
Browse files Browse the repository at this point in the history
Previously it was always set to zero.

Note that ftime() is a deprectaed interface.

Also follows glibc's version (https://github.com/bminor/glibc/blob/f44f3aed31a2d18dc1aa70fce8d466cf6e56b93c/time/ftime.c#L23)
and always set timezone & dstflag to zero.
  • Loading branch information
th-otto committed Mar 19, 2024
1 parent 72667bf commit 3ab6d73
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions time/ftime.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */

#include <errno.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/time.h>

int
ftime (struct timeb *timebuf)
{
int save = errno;
struct tm tp;
struct timeval now;

__set_errno (0);
if (time (&timebuf->time) == (time_t) -1 && errno != 0)
return -1;
timebuf->millitm = 0;
if (__gettimeofday (&now, NULL) != 0)
return -1;
timebuf->time = now.tv_sec;
timebuf->millitm = now.tv_usec / 1000;

if (localtime_r (&timebuf->time, &tp) == NULL)
return -1;
timebuf->timezone = 0;
timebuf->dstflag = 0;

timebuf->timezone = tp.tm_gmtoff / 60;
timebuf->dstflag = tp.tm_isdst;

__set_errno (save);
return 0;
return 0;
}

0 comments on commit 3ab6d73

Please sign in to comment.