annotate cutils.c @ 5219:583eb737b1c4 libavformat

fix pes overhead computation, patch by Niobos, niobos at dest-unreach dot be
author bcoudurier
date Thu, 17 Sep 2009 19:07:09 +0000
parents ecc817a37849
children 28ca2d77f997
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Various simple utilities for ffmpeg system
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 896
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
23 /* add one element to a dynamic array */
4375
ecc817a37849 Do not misuse unsigned long to store pointers.
ramiro
parents: 3306
diff changeset
24 void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
25 {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
26 int nb, nb_alloc;
4375
ecc817a37849 Do not misuse unsigned long to store pointers.
ramiro
parents: 3306
diff changeset
27 intptr_t *tab;
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
28
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
29 nb = *nb_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
30 tab = *tab_ptr;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
31 if ((nb & (nb - 1)) == 0) {
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
32 if (nb == 0)
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
33 nb_alloc = 1;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
34 else
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
35 nb_alloc = nb * 2;
4375
ecc817a37849 Do not misuse unsigned long to store pointers.
ramiro
parents: 3306
diff changeset
36 tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
151
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
37 *tab_ptr = tab;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
38 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
39 tab[nb++] = elem;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
40 *nb_ptr = nb;
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
41 }
ec4d9190d3b1 dynamic array functions
bellard
parents: 64
diff changeset
42
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
43 time_t mktimegm(struct tm *tm)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
44 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
45 time_t t;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
46
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
47 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
48
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
49 if (m < 3) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
50 m += 12;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
51 y--;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
52 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
53
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 515
diff changeset
54 t = 86400 *
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
55 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
56
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
57 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
58
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
59 return t;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
60 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
61
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
62 #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
63 #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400)
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
64
2213
835de8466c39 spelling cosmetics
diego
parents: 2190
diff changeset
65 /* This is our own gmtime_r. It differs from its POSIX counterpart in a
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
66 couple of places, though. */
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
67 struct tm *brktimegm(time_t secs, struct tm *tm)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 515
diff changeset
68 {
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
69 int days, y, ny, m;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
70 int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
71
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
72 days = secs / 86400;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
73 secs %= 86400;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
74 tm->tm_hour = secs / 3600;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
75 tm->tm_min = (secs % 3600) / 60;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
76 tm->tm_sec = secs % 60;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
77
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
78 /* oh well, may be someone some day will invent a formula for this stuff */
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
79 y = 1970; /* start "guessing" */
3306
4d73d137f64e Do not loop endlessly if converting into dv with timestamps Jan 1st not
cehoyos
parents: 3249
diff changeset
80 while (days > 365) {
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
81 ny = (y + days/366);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
82 days -= (ny - y) * 365 + LEAPS_COUNT(ny - 1) - LEAPS_COUNT(y - 1);
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
83 y = ny;
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
84 }
3306
4d73d137f64e Do not loop endlessly if converting into dv with timestamps Jan 1st not
cehoyos
parents: 3249
diff changeset
85 if (days==365 && !ISLEAP(y)) { days=0; y++; }
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
86 md[1] = ISLEAP(y)?29:28;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
87 for (m=0; days >= md[m]; m++)
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
88 days -= md[m];
515
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
89
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
90 tm->tm_year = y; /* unlike gmtime_r we store complete year here */
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
91 tm->tm_mon = m+1; /* unlike gmtime_r tm_mon is from 1 to 12 */
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
92 tm->tm_mday = days+1;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
93
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
94 return tm;
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
95 }
ad72189eec07 * replacing calls to not-always-available gmtime_r with our own code.
romansh
parents: 230
diff changeset
96
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
97 /* get a positive number between n_min and n_max, for a maximum length
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
98 of len_max. Return -1 if error. */
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
99 static int date_get_num(const char **pp,
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
100 int n_min, int n_max, int len_max)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
101 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
102 int i, val, c;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
103 const char *p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
104
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
105 p = *pp;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
106 val = 0;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
107 for(i = 0; i < len_max; i++) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
108 c = *p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
109 if (!isdigit(c))
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
110 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
111 val = (val * 10) + c - '0';
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
112 p++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
113 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
114 /* no number read ? */
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
115 if (p == *pp)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
116 return -1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
117 if (val < n_min || val > n_max)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
118 return -1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
119 *pp = p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
120 return val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
121 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
122
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
123 /* small strptime for ffmpeg */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 515
diff changeset
124 const char *small_strptime(const char *p, const char *fmt,
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
125 struct tm *dt)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
126 {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
127 int c, val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
128
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
129 for(;;) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
130 c = *fmt++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
131 if (c == '\0') {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
132 return p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
133 } else if (c == '%') {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
134 c = *fmt++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
135 switch(c) {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
136 case 'H':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
137 val = date_get_num(&p, 0, 23, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
138 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
139 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
140 dt->tm_hour = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
141 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
142 case 'M':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
143 val = date_get_num(&p, 0, 59, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
144 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
145 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
146 dt->tm_min = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
147 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
148 case 'S':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
149 val = date_get_num(&p, 0, 59, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
150 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
151 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
152 dt->tm_sec = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
153 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
154 case 'Y':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
155 val = date_get_num(&p, 0, 9999, 4);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
156 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
157 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
158 dt->tm_year = val - 1900;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
159 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
160 case 'm':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
161 val = date_get_num(&p, 1, 12, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
162 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
163 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
164 dt->tm_mon = val - 1;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
165 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
166 case 'd':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
167 val = date_get_num(&p, 1, 31, 2);
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
168 if (val == -1)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
169 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
170 dt->tm_mday = val;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
171 break;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
172 case '%':
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
173 goto match;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
174 default:
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
175 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
176 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
177 } else {
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
178 match:
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
179 if (c != *p)
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
180 return NULL;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
181 p++;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
182 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
183 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
184 return p;
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
185 }
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
186