Annotation of 43BSDReno/contrib/isode-beta/psap/time2str.c, revision 1.1

1.1     ! root        1: /* time2str.c - time string to string */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/time2str.c,v 7.0 89/11/23 22:13:53 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/time2str.c,v 7.0 89/11/23 22:13:53 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       time2str.c,v $
        !            12:  * Revision 7.0  89/11/23  22:13:53  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: 
        !            33: 
        !            34: #define        YEAR(y)         ((y) >= 100 ? (y) : (y) + 1900)
        !            35: #define        UNYEAR(y)       ((y) < 1900 || (y) > 1999 ? (y) : (y) - 1900)
        !            36: 
        !            37: /*  */
        !            38: 
        !            39: char   *time2str (u, generalized)
        !            40: register UTC   u;
        !            41: int    generalized;
        !            42: {
        !            43:     register int    hours,
        !            44:                     mins,
        !            45:                     zone;
        !            46:     register char  *bp;
        !            47:     static char buffer[BUFSIZ];
        !            48: 
        !            49:     if (u == NULLUTC)
        !            50:        return NULLCP;
        !            51: 
        !            52:     bp = buffer;
        !            53: 
        !            54:     if (generalized)
        !            55:        (void) sprintf (bp, "%04d", YEAR (u -> ut_year));
        !            56:     else
        !            57:        (void) sprintf (bp, "%02d", UNYEAR (u -> ut_year));
        !            58:     bp += strlen (bp);
        !            59: 
        !            60:     (void) sprintf (bp, "%02d%02d%02d%02d", u -> ut_mon, u -> ut_mday,
        !            61:                u -> ut_hour, u -> ut_min);
        !            62:     bp += strlen (bp);
        !            63: 
        !            64:     if (u -> ut_flags & UT_SEC
        !            65:            || (generalized && (u -> ut_flags & UT_USEC))) {
        !            66:        (void) sprintf (bp, "%02d", u -> ut_sec);
        !            67:        bp += strlen (bp);
        !            68:     }
        !            69:     if (generalized && (u -> ut_flags & UT_USEC)) {
        !            70:        (void) sprintf (bp, ".%06d", u -> ut_usec);
        !            71:        bp += strlen (bp);
        !            72:     }
        !            73: 
        !            74:     if (u -> ut_flags & UT_ZONE)
        !            75:        if ((zone = u -> ut_zone) == 0)
        !            76:            *bp++ = 'Z';
        !            77:        else {
        !            78:            if (zone < 0)
        !            79:                mins = (-zone) % 60, hours = (-zone) / 60;
        !            80:            else
        !            81:                mins = zone % 60, hours = zone / 60;
        !            82:            (void) sprintf (bp, "%c%02d%02d", zone < 0 ? '-' : '+',
        !            83:                    hours, mins);
        !            84:            bp += strlen (bp);
        !            85:        }
        !            86: 
        !            87:     *bp = NULL;
        !            88: 
        !            89:     return buffer;
        !            90: }

unix.superglobalmegacorp.com

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