"Fossies" - the Fresh Open Source Software Archive

Member "dateutils-0.4.6/contrib/tzraw.h" (19 Mar 2019, 5278 Bytes) of package /linux/privat/dateutils-0.4.6.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "tzraw.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.4.5_vs_0.4.6.

    1 /*** tzraw.h -- reader for olson database zoneinfo files
    2  *
    3  * Copyright (C) 2009-2019 Sebastian Freundt
    4  *
    5  * Author:  Sebastian Freundt <freundt@ga-group.nl>
    6  *
    7  * This file is part of uterus and dateutils.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  *
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  *
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  *
   20  * 3. Neither the name of the author nor the names of any contributors
   21  *    may be used to endorse or promote products derived from this
   22  *    software without specific prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
   25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   27  * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
   31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
   33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   35  *
   36  ***/
   37 
   38 #if !defined INCLUDED_tzraw_h_
   39 #define INCLUDED_tzraw_h_
   40 
   41 #include <stdint.h>
   42 #include <limits.h>
   43 #include "leaps.h"
   44 
   45 #if defined __cplusplus
   46 extern "C" {
   47 #endif  /* __cplusplus */
   48 
   49 /*
   50 ** Each file begins with. . .
   51 */
   52 #define TZ_MAGIC    "TZif"
   53 
   54 #if 0
   55 struct tzhead {
   56     char    tzh_magic[4];       /* TZ_MAGIC */
   57     char    tzh_version[1];     /* '\0' or '2' as of 2005 */
   58     char    tzh_reserved[15];   /* reserved--must be zero */
   59     char    tzh_ttisgmtcnt[4];  /* coded number of trans. time flags */
   60     char    tzh_ttisstdcnt[4];  /* coded number of trans. time flags */
   61     char    tzh_leapcnt[4];     /* coded number of leap seconds */
   62     char    tzh_timecnt[4];     /* coded number of transition times */
   63     char    tzh_typecnt[4];     /* coded number of local time types */
   64     char    tzh_charcnt[4];     /* coded number of abbr. chars */
   65 };
   66 
   67 /*
   68 ** . . .followed by. . .
   69 **
   70 **  tzh_timecnt (char [4])s     coded transition times a la time(2)
   71 **  tzh_timecnt (unsigned char)s    types of local time starting at above
   72 **  tzh_typecnt repetitions of
   73 **      one (char [4])      coded UTC offset in seconds
   74 **      one (unsigned char) used to set tm_isdst
   75 **      one (unsigned char) that's an abbreviation list index
   76 **  tzh_charcnt (char)s     '\0'-terminated zone abbreviations
   77 **  tzh_leapcnt repetitions of
   78 **      one (char [4])      coded leap second transition times
   79 **      one (char [4])      total correction after above
   80 **  tzh_ttisstdcnt (char)s      indexed by type; if TRUE, transition
   81 **                  time is standard time, if FALSE,
   82 **                  transition time is wall clock time
   83 **                  if absent, transition times are
   84 **                  assumed to be wall clock time
   85 **  tzh_ttisgmtcnt (char)s      indexed by type; if TRUE, transition
   86 **                  time is UTC, if FALSE,
   87 **                  transition time is local time
   88 **                  if absent, transition times are
   89 **                  assumed to be local time
   90 */
   91 
   92 /*
   93 ** If tzh_version is '2' or greater, the above is followed by a second instance
   94 ** of tzhead and a second instance of the data in which each coded transition
   95 ** time uses 8 rather than 4 chars,
   96 ** then a POSIX-TZ-environment-variable-style string for use in handling
   97 ** instants after the last transition time stored in the file
   98 ** (with nothing between the newlines if there is no POSIX representation for
   99 ** such instants).
  100 */
  101 #endif  /* 0 */
  102 
  103 
  104 /* now our view on things */
  105 typedef const struct zif_s *zif_t;
  106 
  107 typedef enum {
  108     TZCZ_UNK,
  109     TZCZ_UTC,
  110     TZCZ_TAI,
  111     TZCZ_GPS,
  112     TZCZ_NZONE,
  113 } coord_zone_t;
  114 
  115 /* for the one tool that needs raw transitions */
  116 struct zrng_s {
  117     int32_t prev, next;
  118     signed int offs:24;
  119     unsigned int trno:8;
  120 } __attribute__((packed));
  121 
  122 
  123 /**
  124  * Open the zoneinfo file FILE.
  125  * FILE can be absolute or relative to the configured TZDIR path.
  126  * FILE can also name virtual zones such as GPS or TAI. */
  127 extern zif_t zif_open(const char *file);
  128 
  129 /**
  130  * Close the zoneinfo file reader and free associated resources. */
  131 extern void zif_close(zif_t);
  132 
  133 /**
  134  * Copy the zoneinfo structure. */
  135 extern zif_t zif_copy(zif_t);
  136 
  137 /**
  138  * Find the most recent transition in Z before T. */
  139 extern int zif_find_trans(zif_t z, int32_t t);
  140 
  141 /**
  142  * Find a range of transitions in Z that T belongs to. */
  143 extern struct zrng_s zif_find_zrng(zif_t z, int32_t t);
  144 
  145 /**
  146  * Given T in local time specified by Z, return a T in UTC. */
  147 extern int32_t zif_utc_time(zif_t z, int32_t t);
  148 
  149 /**
  150  * Given T in UTC, return a T in local time specified by Z. */
  151 extern int32_t zif_local_time(zif_t z, int32_t t);
  152 
  153 
  154 /* exposure for specific zif-inspecting tools (dzone(1) for one) */
  155 extern size_t zif_ntrans(zif_t z);
  156 
  157 extern struct ztrdtl_s zif_trdtl(zif_t z, int n);
  158 
  159 #if defined __cplusplus
  160 }
  161 #endif  /* __cplusplus */
  162 
  163 #endif  /* INCLUDED_tzraw_h_ */