ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/strlcpy.c
Revision: 2.3
Committed: Thu Nov 7 23:19:12 2019 UTC (4 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 2.2: +4 -2 lines
Log Message:
Corrected count output in stdlib replacements

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.3 static const char RCSid[] = "$Id: strlcpy.c,v 2.2 2018/05/04 21:22:44 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * String copy routines similar to strncpy
6     */
7    
8     #include "copyright.h"
9 greg 2.2 #include "rtio.h"
10 greg 2.1
11 greg 2.2 size_t
12     strlcpy(char *dst, const char *src, size_t siz)
13 greg 2.1 {
14 greg 2.2 size_t n = siz;
15 greg 2.1
16     while (--n > 0)
17     if (!(*dst++ = *src++))
18     return(siz-1-n);
19     *dst = '\0';
20 greg 2.3 while (*src++)
21     ++siz;
22 greg 2.1 return(siz-1);
23     }
24    
25 greg 2.2 size_t
26     strlcat(char *dst, const char *src, size_t siz)
27 greg 2.1 {
28 greg 2.2 size_t n = siz;
29 greg 2.1
30     while (*dst && --n > 0)
31     ++dst;
32     if (n <= 0)
33 greg 2.3 return(siz+strlen(src));
34 greg 2.1 return(siz-n + strlcpy(dst, src, n));
35     }