OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [time/] [tzset_r.c] - Blame information for rev 258

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#include <_ansi.h>
2
#include <reent.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
#include <sys/types.h>
7
#include <sys/time.h>
8
#include "local.h"
9
 
10
static char __tzname_std[11];
11
static char __tzname_dst[11];
12
static char *prev_tzenv = NULL;
13
 
14
_VOID
15
_DEFUN (_tzset_r, (reent_ptr),
16
        struct _reent *reent_ptr)
17
{
18
  char *tzenv;
19
  unsigned short hh, mm, ss, m, w, d;
20
  int sign, n;
21
  int i, ch;
22
  __tzinfo_type *tz = __gettzinfo ();
23
 
24
  if ((tzenv = _getenv_r (reent_ptr, "TZ")) == NULL)
25
      {
26
        TZ_LOCK;
27
        _timezone = 0;
28
        _daylight = 0;
29
        _tzname[0] = "GMT";
30
        _tzname[1] = "GMT";
31
        TZ_UNLOCK;
32
        return;
33
      }
34
 
35
  TZ_LOCK;
36
 
37
  if (prev_tzenv != NULL && strcmp(tzenv, prev_tzenv) == 0)
38
    {
39
      TZ_UNLOCK;
40
      return;
41
    }
42
 
43
  free(prev_tzenv);
44
  prev_tzenv = _malloc_r (reent_ptr, strlen(tzenv) + 1);
45
  if (prev_tzenv != NULL)
46
    strcpy (prev_tzenv, tzenv);
47
 
48
  /* ignore implementation-specific format specifier */
49
  if (*tzenv == ':')
50
    ++tzenv;
51
 
52
  if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0)
53
    {
54
      TZ_UNLOCK;
55
      return;
56
    }
57
 
58
  tzenv += n;
59
 
60
  sign = 1;
61
  if (*tzenv == '-')
62
    {
63
      sign = -1;
64
      ++tzenv;
65
    }
66
  else if (*tzenv == '+')
67
    ++tzenv;
68
 
69
  mm = 0;
70
  ss = 0;
71
 
72
  if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) < 1)
73
    {
74
      TZ_UNLOCK;
75
      return;
76
    }
77
 
78
  tz->__tzrule[0].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh);
79
  _tzname[0] = __tzname_std;
80
  tzenv += n;
81
 
82
  if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0)
83
    {
84
      _tzname[1] = _tzname[0];
85
      TZ_UNLOCK;
86
      return;
87
    }
88
  else
89
    _tzname[1] = __tzname_dst;
90
 
91
  tzenv += n;
92
 
93
  /* otherwise we have a dst name, look for the offset */
94
  sign = 1;
95
  if (*tzenv == '-')
96
    {
97
      sign = -1;
98
      ++tzenv;
99
    }
100
  else if (*tzenv == '+')
101
    ++tzenv;
102
 
103
  hh = 0;
104
  mm = 0;
105
  ss = 0;
106
 
107
  n  = 0;
108
  if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) <= 0)
109
    tz->__tzrule[1].offset = tz->__tzrule[0].offset - 3600;
110
  else
111
    tz->__tzrule[1].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh);
112
 
113
  tzenv += n;
114
 
115
  for (i = 0; i < 2; ++i)
116
    {
117
      if (*tzenv == ',')
118
        ++tzenv;
119
 
120
      if (*tzenv == 'M')
121
        {
122
          if (sscanf (tzenv, "M%hu%n.%hu%n.%hu%n", &m, &n, &w, &n, &d, &n) != 3 ||
123
              m < 1 || m > 12 || w < 1 || w > 5 || d > 6)
124
            {
125
              TZ_UNLOCK;
126
              return;
127
            }
128
 
129
          tz->__tzrule[i].ch = 'M';
130
          tz->__tzrule[i].m = m;
131
          tz->__tzrule[i].n = w;
132
          tz->__tzrule[i].d = d;
133
 
134
          tzenv += n;
135
        }
136
      else
137
        {
138
          char *end;
139
          if (*tzenv == 'J')
140
            {
141
              ch = 'J';
142
              ++tzenv;
143
            }
144
          else
145
            ch = 'D';
146
 
147
          d = strtoul (tzenv, &end, 10);
148
 
149
          /* if unspecified, default to US settings */
150
          /* From 1987-2006, US was M4.1.0,M10.5.0, but starting in 2007 is
151
           * M3.2.0,M11.1.0 (2nd Sunday March through 1st Sunday November)  */
152
          if (end == tzenv)
153
            {
154
              if (i == 0)
155
                {
156
                  tz->__tzrule[0].ch = 'M';
157
                  tz->__tzrule[0].m = 3;
158
                  tz->__tzrule[0].n = 2;
159
                  tz->__tzrule[0].d = 0;
160
                }
161
              else
162
                {
163
                  tz->__tzrule[1].ch = 'M';
164
                  tz->__tzrule[1].m = 11;
165
                  tz->__tzrule[1].n = 1;
166
                  tz->__tzrule[1].d = 0;
167
                }
168
            }
169
          else
170
            {
171
              tz->__tzrule[i].ch = ch;
172
              tz->__tzrule[i].d = d;
173
            }
174
 
175
          tzenv = end;
176
        }
177
 
178
      /* default time is 02:00:00 am */
179
      hh = 2;
180
      mm = 0;
181
      ss = 0;
182
      n = 0;
183
 
184
      if (*tzenv == '/')
185
        sscanf (tzenv, "/%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n);
186
 
187
      tz->__tzrule[i].s = ss + SECSPERMIN * mm + SECSPERHOUR  * hh;
188
 
189
      tzenv += n;
190
    }
191
 
192
  __tzcalc_limits (tz->__tzyear);
193
  _timezone = tz->__tzrule[0].offset;
194
  _daylight = tz->__tzrule[0].offset != tz->__tzrule[1].offset;
195
 
196
  TZ_UNLOCK;
197
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.