2 * Various simple utilities for ffmpeg system
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /* add one element to a dynamic array */
24 void ff_dynarray_add(unsigned long **tab_ptr
, int *nb_ptr
, unsigned long elem
)
31 if ((nb
& (nb
- 1)) == 0) {
36 tab
= av_realloc(tab
, nb_alloc
* sizeof(unsigned long));
43 time_t mktimegm(struct tm
*tm
)
47 int y
= tm
->tm_year
+ 1900, m
= tm
->tm_mon
+ 1, d
= tm
->tm_mday
;
55 (d
+ (153 * m
- 457) / 5 + 365 * y
+ y
/ 4 - y
/ 100 + y
/ 400 - 719469);
57 t
+= 3600 * tm
->tm_hour
+ 60 * tm
->tm_min
+ tm
->tm_sec
;
62 #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0))
63 #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400)
65 /* This is our own gmtime_r. It differs from its POSIX counterpart in a
66 couple of places, though. */
67 struct tm
*brktimegm(time_t secs
, struct tm
*tm
)
70 int md
[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
74 tm
->tm_hour
= secs
/ 3600;
75 tm
->tm_min
= (secs
% 3600) / 60;
76 tm
->tm_sec
= secs
% 60;
78 /* oh well, may be someone some day will invent a formula for this stuff */
79 y
= 1970; /* start "guessing" */
82 days
-= (ny
- y
) * 365 + LEAPS_COUNT(ny
- 1) - LEAPS_COUNT(y
- 1);
85 if (days
==365 && !ISLEAP(y
)) { days
=0; y
++; }
86 md
[1] = ISLEAP(y
)?29:28;
87 for (m
=0; days
>= md
[m
]; m
++)
90 tm
->tm_year
= y
; /* unlike gmtime_r we store complete year here */
91 tm
->tm_mon
= m
+1; /* unlike gmtime_r tm_mon is from 1 to 12 */
97 /* get a positive number between n_min and n_max, for a maximum length
98 of len_max. Return -1 if error. */
99 static int date_get_num(const char **pp
,
100 int n_min
, int n_max
, int len_max
)
107 for(i
= 0; i
< len_max
; i
++) {
111 val
= (val
* 10) + c
- '0';
114 /* no number read ? */
117 if (val
< n_min
|| val
> n_max
)
123 /* small strptime for ffmpeg */
124 const char *small_strptime(const char *p
, const char *fmt
,
133 } else if (c
== '%') {
137 val
= date_get_num(&p
, 0, 23, 2);
143 val
= date_get_num(&p
, 0, 59, 2);
149 val
= date_get_num(&p
, 0, 59, 2);
155 val
= date_get_num(&p
, 0, 9999, 4);
158 dt
->tm_year
= val
- 1900;
161 val
= date_get_num(&p
, 1, 12, 2);
164 dt
->tm_mon
= val
- 1;
167 val
= date_get_num(&p
, 1, 31, 2);