Annotation of 43BSDReno/contrib/isode-beta/psap/gtime.c, revision 1.1.1.1

1.1       root        1: /* gtime.c - inverse gmtime */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/psap/RCS/gtime.c,v 7.0 89/11/23 22:12:37 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/psap/RCS/gtime.c,v 7.0 89/11/23 22:12:37 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       gtime.c,v $
                     12:  * Revision 7.0  89/11/23  22:12:37  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: /* LINTLIBRARY */
                     29: 
                     30: #include <stdio.h>
                     31: #include "psap.h"
                     32: #ifdef OSX
                     33: #include <sys/time.h>
                     34: #endif
                     35: #ifdef notdef
                     36: #include <sys/timeb.h>
                     37: #endif
                     38: 
                     39: /*    DATA */
                     40: 
                     41: /* gtime(): the inverse of localtime().
                     42:        This routine was supplied by Mike Accetta at CMU many years ago.
                     43:  */
                     44: 
                     45: int    dmsize[] = {
                     46:     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
                     47: };
                     48: 
                     49: #define        dysize(y)       \
                     50:        (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366)))
                     51: 
                     52: #define        YEAR(y)         ((y) >= 100 ? (y) : (y) + 1900)
                     53: 
                     54: /*  */
                     55: 
                     56: long   gtime (tm)
                     57: register struct tm *tm;
                     58: {
                     59:     register int    i,
                     60:                     sec,
                     61:                     mins,
                     62:                     hour,
                     63:                     mday,
                     64:                     mon,
                     65:                     year;
                     66:     register long   result;
                     67: #ifdef notdef
                     68:     long    local;
                     69:     struct timeb    tb;
                     70: #endif
                     71: 
                     72:     if ((sec = tm -> tm_sec) < 0 || sec > 59
                     73:            || (mins = tm -> tm_min) < 0 || mins > 59
                     74:            || (hour = tm -> tm_hour) < 0 || hour > 24
                     75:            || (mday = tm -> tm_mday) < 1 || mday > 31
                     76:            || (mon = tm -> tm_mon + 1) < 1 || mon > 12)
                     77:        return ((long) NOTOK);
                     78:     if (hour == 24) {
                     79:        hour = 0;
                     80:        mday++;
                     81:     }
                     82:     year = YEAR (tm -> tm_year);
                     83: 
                     84:     result = 0L;
                     85:     for (i = 1970; i < year; i++)
                     86:        result += dysize (i);
                     87:     if (dysize (year) == 366 && mon >= 3)
                     88:        result++;
                     89:     while (--mon)
                     90:        result += dmsize[mon - 1];
                     91:     result += mday - 1;
                     92:     result = 24 * result + hour;
                     93:     result = 60 * result + mins;
                     94:     result = 60 * result + sec;
                     95: 
                     96: #ifdef notdef
                     97:     (void) ftime (&tb);
                     98:     result += 60 * tb.timezone;
                     99:     local = result;
                    100:     if ((tm = localtime (&local)) && tm -> tm_isdst)
                    101:        result -= 60 * 60;
                    102: #endif
                    103: 
                    104:     return result;
                    105: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.