Mercurial > mplayer.hg
comparison osdep/strl.c @ 12646:9a495bdc3a1e
string handling security fixes
patch by Nicholas Kain, Alexander Strasser <eclipse7@gmx.net>
reviewed by Pontscho, Alex, Rich
author | diego |
---|---|
date | Fri, 25 Jun 2004 16:49:53 +0000 |
parents | |
children | f48dc20c9185 |
comparison
equal
deleted
inserted
replaced
12645:3841ef14a481 | 12646:9a495bdc3a1e |
---|---|
1 /* strl(cat|cpy) implementation for systems that do not have it in libc */ | |
2 /* strl.c - strlcpy/strlcat implementation | |
3 * Time-stamp: <2004-03-14 njk> | |
4 * (C) 2003-2004 Nicholas J. Kain <njk@aerifal.cx> | |
5 */ | |
6 | |
7 #include "../config.h" | |
8 | |
9 #ifndef HAVE_STRLCPY | |
10 unsigned int strlcpy (char *dest, char *src, unsigned int size) | |
11 { | |
12 register unsigned int i; | |
13 | |
14 for (i=0; size > 0 && src[i] != '\0'; ++i, size--) | |
15 dest[i] = src[i]; | |
16 | |
17 dest[i] = '\0'; | |
18 | |
19 return i; | |
20 } | |
21 #endif | |
22 | |
23 #ifndef HAVE_STRLCAT | |
24 unsigned int strlcat (char *dest, char *src, unsigned int size) | |
25 { | |
26 #if 0 | |
27 register unsigned int i, j; | |
28 | |
29 for(i=0; size > 0 && dest[i] != '\0'; size--, i++); | |
30 for(j=0; size > 0 && src[j] != '\0'; size--, i++, j++) | |
31 dest[i] = src[j]; | |
32 | |
33 dest[i] = '\0'; | |
34 return i; | |
35 #else | |
36 register char *d = dest, *s = src; | |
37 | |
38 for (; size > 0 && *d != '\0'; size--, d++); | |
39 for (; size > 0 && *s != '\0'; size--, d++, s++) | |
40 *d = *s; | |
41 | |
42 *d = '\0'; | |
43 return (d - dest) + (s - src); | |
44 #endif | |
45 } | |
46 #endif | |
47 |