2 * Various simple utilities for ffmpeg system
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #if !defined(CONFIG_NOCUTILS)
23 * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
24 * set to the next character in 'str' after the prefix.
26 * @param str input string
27 * @param val prefix to test
28 * @param ptr updated after the prefix in str in there is a match
29 * @return TRUE if there is a match
31 int strstart(const char *str, const char *val, const char **ptr)
48 * Return TRUE if val is a prefix of str (case independent). If it
49 * returns TRUE, ptr is set to the next character in 'str' after the
52 * @param str input string
53 * @param val prefix to test
54 * @param ptr updated after the prefix in str in there is a match
55 * @return TRUE if there is a match */
56 int stristart(const char *str, const char *val, const char **ptr)
62 if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
73 * Copy the string str to buf. If str length is bigger than buf_size -
74 * 1 then it is clamped to buf_size - 1.
75 * NOTE: this function does what strncpy should have done to be
76 * useful. NEVER use strncpy.
78 * @param buf destination buffer
79 * @param buf_size size of destination buffer
80 * @param str source string
82 void pstrcpy(char *buf, int buf_size, const char *str)
92 if (c == 0 || q >= buf + buf_size - 1)
99 /* strcat and truncate. */
100 char *pstrcat(char *buf, int buf_size, const char *s)
105 pstrcpy(buf + len, buf_size - len, s);
111 /* add one element to a dynamic array */
112 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
119 if ((nb & (nb - 1)) == 0) {
124 tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
131 time_t mktimegm(struct tm *tm)
135 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
143 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
145 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
150 /* get a positive number between n_min and n_max, for a maximum length
151 of len_max. Return -1 if error. */
152 static int date_get_num(const char **pp,
153 int n_min, int n_max, int len_max)
160 for(i = 0; i < len_max; i++) {
164 val = (val * 10) + c - '0';
167 /* no number read ? */
170 if (val < n_min || val > n_max)
176 /* small strptime for ffmpeg */
177 const char *small_strptime(const char *p, const char *fmt,
186 } else if (c == '%') {
190 val = date_get_num(&p, 0, 23, 2);
196 val = date_get_num(&p, 0, 59, 2);
202 val = date_get_num(&p, 0, 59, 2);
208 val = date_get_num(&p, 0, 9999, 4);
211 dt->tm_year = val - 1900;
214 val = date_get_num(&p, 1, 12, 2);
217 dt->tm_mon = val - 1;
220 val = date_get_num(&p, 1, 31, 2);