1 /*
2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
3 * Copyright (c) 2007 Mans Rullgard
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
21
23 #include <stdarg.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "config.h"
35
36 int av_strstart(
const char *str,
const char *pfx,
const char **ptr)
37 {
38 while (*pfx && *pfx == *str) {
39 pfx++;
40 str++;
41 }
42 if (!*pfx && ptr)
43 *ptr = str;
44 return !*pfx;
45 }
46
47 int av_stristart(
const char *str,
const char *pfx,
const char **ptr)
48 {
50 pfx++;
51 str++;
52 }
53 if (!*pfx && ptr)
54 *ptr = str;
55 return !*pfx;
56 }
57
59 {
60 if (!*s2)
61 return (char*)(intptr_t)s1;
62
63 do
65 return (char*)(intptr_t)s1;
66 while (*s1++);
67
69 }
70
71 char *
av_strnstr(
const char *haystack,
const char *needle,
size_t hay_length)
72 {
73 size_t needle_len = strlen(needle);
74 if (!needle_len)
75 return (char*)haystack;
76 while (hay_length >= needle_len) {
77 hay_length--;
78 if (!memcmp(haystack, needle, needle_len))
79 return (char*)haystack;
80 haystack++;
81 }
83 }
84
86 {
92 return len + strlen(
src) - 1;
93 }
94
96 {
101 }
102
104 {
106 va_list vl;
107
108 va_start(vl, fmt);
110 va_end(vl);
111
113 }
114
116 {
118 va_list va;
120
121 va_start(va, fmt);
123 va_end(va);
125 goto end;
126
129 goto end;
130
131 va_start(va, fmt);
133 va_end(va);
136
137 end:
139 }
140
141 #define WHITESPACES " \n\t\r"
142
144 {
147 const char *
p = *
buf;
151
152 while (*
p && !strspn(
p, term)) {
154 if (
c ==
'\\' && *
p) {
157 }
else if (
c ==
'\'') {
158 while (*
p && *
p !=
'\'')
163 }
164 } else {
166 }
167 }
168
169 do
172
174
176 return small_ret ? small_ret :
ret;
177 }
178
180 {
181 char *tok;
182
183 if (!
s && !(
s = *saveptr))
185
186 /* skip leading delimiters */
187 s += strspn(
s, delim);
188
189 /* s now points to the first non delimiter char, or to the end of the string */
193 }
195
196 /* skip non delimiters */
197 s += strcspn(
s, delim);
201 } else {
203 }
204
205 return tok;
206 }
207
209 {
211 do {
216 }
217
219 {
221 if (n <= 0)
222 return 0;
223 do {
226 }
while (--n &&
c1 &&
c1 ==
c2);
228 }
229
231 {
233 const char *pstr2, *pstr = str;
234 size_t tolen = strlen(
to), fromlen = strlen(
from);
235 AVBPrint pbuf;
236
240 pstr = pstr2 + fromlen;
242 }
246 } else {
248 }
249
251 }
252
254 {
256 #if HAVE_DOS_PATHS
257 char *q, *d;
258 #endif
259
260 if (!path || *path == '0円')
261 return ".";
262
263 p = strrchr(path,
'/');
264 #if HAVE_DOS_PATHS
265 q = strrchr(path, '\\');
266 d = strchr(path, ':');
268 #endif
269
271 return path;
272
274 }
275
277 {
278 char *
p = path ? strrchr(path,
'/') :
NULL;
279
280 #if HAVE_DOS_PATHS
281 char *q = path ? strrchr(path,
'\\') :
NULL;
282 char *d = path ? strchr(path,
':') :
NULL;
283
284 d = d ? d + 1 : d;
285
287 #endif
288
290 return ".";
291
293
294 return path;
295 }
296
298 {
299 size_t p_len, c_len;
300 char *fullpath;
301
302 if (!path)
304 if (!component)
306
307 p_len = strlen(path);
308 c_len = strlen(component);
309 if (p_len > SIZE_MAX - c_len || p_len + c_len > SIZE_MAX - 2)
312 if (fullpath) {
313 if (p_len) {
315 if (c_len) {
316 if (fullpath[p_len - 1] != '/' && component[0] != '/')
317 fullpath[p_len++] = '/';
318 else if (fullpath[p_len - 1] == '/' && component[0] == '/')
319 p_len--;
320 }
321 }
322 av_strlcpy(&fullpath[p_len], component, c_len + 1);
323 fullpath[p_len + c_len] = 0;
324 }
325 return fullpath;
326 }
327
330 {
331 AVBPrint dstbuf;
333
334 av_bprint_init(&dstbuf, 1, INT_MAX);
/* (int)dstbuf.len must be >= 0 */
336
340 }
343 return dstbuf.len;
344 }
345
347 {
350
352 return 0;
353
354 namelen = strlen(
name);
355 while (*names) {
356 int negate = '-' == *names;
357 p = strchr(names,
',');
359 p = names + strlen(names);
360 names += negate;
363 return !negate;
364 names =
p + (*
p ==
',');
365 }
366 return 0;
367 }
368
371 {
372 const uint8_t *
p = *bufp;
373 uint32_t top;
375 int ret = 0, tail_len;
376 uint32_t overlong_encoding_mins[6] = {
377 0x00000000, 0x00000080, 0x00000800, 0x00010000, 0x00200000, 0x04000000,
378 };
379
381 return 0;
382
384
385 /* first sequence byte starts with 10, or is 1111-1110 or 1111-1111,
386 which is not admitted */
387 if ((
code & 0xc0) == 0x80 ||
code >= 0xFE) {
389 goto end;
390 }
391 top = (
code & 128) >> 1;
392
393 tail_len = 0;
396 tail_len++;
398 (*bufp) ++;
399 return AVERROR(EILSEQ);
/* incomplete sequence */
400 }
401
402 /* we assume the byte to be in the form 10xx-xxxx */
403 tmp = *
p++ - 128;
/* strip leading 1 */
405 (*bufp) ++;
407 }
409 top <<= 5;
410 }
411 code &= (top << 1) - 1;
412
413 /* check for overlong encodings */
415 if (
code < overlong_encoding_mins[tail_len]) {
417 goto end;
418 }
419
420 if (
code >= 1
U<<31) {
421 ret =
AVERROR(EILSEQ);
/* out-of-range value */
422 goto end;
423 }
424
426
427 if (
code > 0x10FFFF &&
433 if (
code >= 0xD800 &&
code <= 0xDFFF &&
436 if ((
code == 0xFFFE ||
code == 0xFFFF) &&
439
440 end:
443 }
444
446 {
448
450 for (q =
list; q && *q; ) {
451 int k;
452 for (k = 0;
p[k] == q[k] || (
p[k]*q[k] == 0 &&
p[k]+q[k] == separator); k++)
453 if (k && (!
p[k] ||
p[k] == separator))
454 return 1;
455 q = strchr(q, separator);
456 if(q)
457 q++;
458 }
459 p = strchr(
p, separator);
462 }
463
464 return 0;
465 }