source: trunk/minix/lib/ansi/gmtime.c@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.0 KB
Line 
1/*
2 * gmtime - convert the calendar time into broken down time
3 */
4/* $Header: /cvsup/minix/src/lib/ansi/gmtime.c,v 1.1.1.1 2005/04/21 14:56:05 beng Exp $ */
5
6#include <time.h>
7#include <limits.h>
8#include "loc_time.h"
9
10struct tm *
11gmtime(register const time_t *timer)
12{
13 static struct tm br_time;
14 register struct tm *timep = &br_time;
15 time_t time = *timer;
16 register unsigned long dayclock, dayno;
17 int year = EPOCH_YR;
18
19 dayclock = (unsigned long)time % SECS_DAY;
20 dayno = (unsigned long)time / SECS_DAY;
21
22 timep->tm_sec = dayclock % 60;
23 timep->tm_min = (dayclock % 3600) / 60;
24 timep->tm_hour = dayclock / 3600;
25 timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
26 while (dayno >= YEARSIZE(year)) {
27 dayno -= YEARSIZE(year);
28 year++;
29 }
30 timep->tm_year = year - YEAR0;
31 timep->tm_yday = dayno;
32 timep->tm_mon = 0;
33 while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
34 dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
35 timep->tm_mon++;
36 }
37 timep->tm_mday = dayno + 1;
38 timep->tm_isdst = 0;
39
40 return timep;
41}
Note: See TracBrowser for help on using the repository browser.