1: /*
   2:  * Copyright (c) 1987 Regents of the University of California.
   3:  * This file may be freely redistributed provided that this
   4:  * notice remains attached.
   5:  */
   6: 
   7: #if defined(LIBC_SCCS) && !defined(lint)
   8: static char sccsid[] = "@(#)timezone.c	1.2 (2.11BSD) 1996/11/27";
   9: #endif LIBC_SCCS and not lint
  10: 
  11: #include <string.h>
  12: #include <stdlib.h>
  13: #include <sys/types.h>
  14: #include <sys/time.h>
  15: #include <stdio.h>
  16: #include <tzfile.h>
  17: 
  18: /*
  19:  * timezone --
  20:  *	The arguments are the number of minutes of time you are westward
  21:  *	from Greenwich and whether DST is in effect.  It returns a string
  22:  *	giving the name of the local timezone.  Should be replaced, in the
  23:  *	application code, by a call to localtime.
  24:  */
  25: 
  26: static char czone[TZ_MAX_CHARS];        /* space for zone name */
  27: 
  28: char *
  29: timezone(zone, dst)
  30:     int zone,
  31:         dst;
  32: {
  33:     register char   *beg,
  34:             *end;
  35:     char    *tztab();
  36: 
  37:     if (beg = getenv("TZNAME")) {       /* set in environment */
  38:         if (end = index(beg, ',')) {    /* "PST,PDT" */
  39:             if (dst)
  40:                 return(++end);
  41:             *end = '\0';
  42:             (void)strncpy(czone,beg,sizeof(czone) - 1);
  43:             czone[sizeof(czone) - 1] = '\0';
  44:             *end = ',';
  45:             return(czone);
  46:         }
  47:         return(beg);
  48:     }
  49:     return(tztab(zone,dst));    /* default: table or created zone */
  50: }
  51: 
  52: static struct zone {
  53:     int offset;
  54:     char    *stdzone;
  55:     char    *dlzone;
  56: } zonetab[] = {
  57:     -1*60,  "MET",  "MET DST",  /* Middle European */
  58:     -2*60,  "EET",  "EET DST",  /* Eastern European */
  59:     4*60,   "AST",  "ADT",      /* Atlantic */
  60:     5*60,   "EST",  "EDT",      /* Eastern */
  61:     6*60,   "CST",  "CDT",      /* Central */
  62:     7*60,   "MST",  "MDT",      /* Mountain */
  63:     8*60,   "PST",  "PDT",      /* Pacific */
  64: #ifdef notdef
  65:     /* there's no way to distinguish this from WET */
  66:     0,  "GMT",  0,      /* Greenwich */
  67: #endif
  68:     0*60,   "WET",  "WET DST",  /* Western European */
  69:     -10*60, "EST",  "EST",      /* Aust: Eastern */
  70:      -10*60+30, "CST",  "CST",      /* Aust: Central */
  71:     -8*60,  "WST",  0,      /* Aust: Western */
  72:     -1
  73: };
  74: 
  75: /*
  76:  * tztab --
  77:  *	check static tables or create a new zone name; broken out so that
  78:  *	we can make a guess as to what the zone is if the standard tables
  79:  *	aren't in place in /usr/share/misc.  DO NOT USE THIS ROUTINE OUTSIDE
  80:  *	OF THE STANDARD LIBRARY.
  81:  */
  82: char *
  83: tztab(zone,dst)
  84:     register int    zone;
  85:     int dst;
  86: {
  87:     register struct zone    *zp;
  88:     register char   sign;
  89: 
  90:     for (zp = zonetab; zp->offset != -1;++zp)   /* static tables */
  91:         if (zp->offset == zone) {
  92:             if (dst && zp->dlzone)
  93:                 return(zp->dlzone);
  94:             if (!dst && zp->stdzone)
  95:                 return(zp->stdzone);
  96:         }
  97: 
  98:     if (zone < 0) {                 /* create one */
  99:         zone = -zone;
 100:         sign = '+';
 101:     }
 102:     else
 103:         sign = '-';
 104:     (void)sprintf(czone,"GMT%c%d:%02d",sign,zone / 60,zone % 60);
 105:     return(czone);
 106: }

Defined functions

tztab defined in line 82; used 4 times

Defined variables

czone defined in line 26; used 7 times
sccsid defined in line 8; never used
zonetab defined in line 56; used 1 times
  • in line 90

Defined struct's

zone defined in line 52; used 2 times
  • in line 87(2)
Last modified: 1996-11-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2259
Valid CSS Valid XHTML 1.0 Strict