annotate osdep/strl.c @ 14592:3b815ee6d7be

small updates by <plazmus at gmail dot com>
author diego
date Tue, 25 Jan 2005 13:04:10 +0000
parents 9a495bdc3a1e
children f48dc20c9185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12646
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
1 /* strl(cat|cpy) implementation for systems that do not have it in libc */
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
2 /* strl.c - strlcpy/strlcat implementation
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
3 * Time-stamp: <2004-03-14 njk>
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
4 * (C) 2003-2004 Nicholas J. Kain <njk@aerifal.cx>
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
5 */
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
6
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
7 #include "../config.h"
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
8
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
9 #ifndef HAVE_STRLCPY
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
10 unsigned int strlcpy (char *dest, char *src, unsigned int size)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
11 {
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
12 register unsigned int i;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
13
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
14 for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
15 dest[i] = src[i];
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
16
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
17 dest[i] = '\0';
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
18
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
19 return i;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
20 }
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
21 #endif
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
22
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
23 #ifndef HAVE_STRLCAT
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
24 unsigned int strlcat (char *dest, char *src, unsigned int size)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
25 {
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
26 #if 0
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
27 register unsigned int i, j;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
28
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
29 for(i=0; size > 0 && dest[i] != '\0'; size--, i++);
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
30 for(j=0; size > 0 && src[j] != '\0'; size--, i++, j++)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
31 dest[i] = src[j];
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
32
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
33 dest[i] = '\0';
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
34 return i;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
35 #else
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
36 register char *d = dest, *s = src;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
37
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
38 for (; size > 0 && *d != '\0'; size--, d++);
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
39 for (; size > 0 && *s != '\0'; size--, d++, s++)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
40 *d = *s;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
41
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
42 *d = '\0';
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
43 return (d - dest) + (s - src);
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
44 #endif
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
45 }
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
46 #endif
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
47