annotate osdep/strl.c @ 16286:044bc40e6ff5

typo, grammar
author diego
date Mon, 22 Aug 2005 00:01:02 +0000
parents f48dc20c9185
children da29ac12242d
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
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 12646
diff changeset
10 unsigned int strlcpy (char *dest, const char *src, unsigned int size)
12646
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
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 12646
diff changeset
24 unsigned int strlcat (char *dest, const char *src, unsigned int size)
12646
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
15058
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 12646
diff changeset
36 register char *d = dest;
f48dc20c9185 - fix gcc warnings, strlcat/strlcpy prototypes
rathann
parents: 12646
diff changeset
37 register const char *s = src;
12646
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
38
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
39 for (; size > 0 && *d != '\0'; size--, d++);
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
40 for (; size > 0 && *s != '\0'; size--, d++, s++)
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
41 *d = *s;
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
42
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
43 *d = '\0';
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
44 return (d - dest) + (s - src);
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
45 #endif
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
46 }
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
47 #endif
9a495bdc3a1e string handling security fixes
diego
parents:
diff changeset
48