62 |
|
return 1; |
63 |
|
} |
64 |
|
#endif |
65 |
+ |
|
66 |
+ |
/* |
67 |
+ |
* strlcat and strlcpy were ripped from openssh 2.5.1p2 |
68 |
+ |
* They had the following Copyright info: |
69 |
+ |
* |
70 |
+ |
* |
71 |
+ |
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
72 |
+ |
* All rights reserved. |
73 |
+ |
* |
74 |
+ |
* Redistribution and use in source and binary forms, with or without |
75 |
+ |
* modification, are permitted provided that the following conditions |
76 |
+ |
* are met: |
77 |
+ |
* 1. Redistributions of source code must retain the above copyright |
78 |
+ |
* notice, this list of conditions and the following disclaimer. |
79 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
80 |
+ |
* notice, this list of conditions and the following disclaimer in the |
81 |
+ |
* documentation and/or other materials provided with the distribution. |
82 |
+ |
* 3. The name of the author may not be used to endorse or promote products |
83 |
+ |
* derived from this software without specific prior written permission. |
84 |
+ |
* |
85 |
+ |
* THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
86 |
+ |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
87 |
+ |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
88 |
+ |
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
89 |
+ |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
90 |
+ |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
91 |
+ |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
92 |
+ |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
93 |
+ |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
94 |
+ |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
95 |
+ |
*/ |
96 |
+ |
|
97 |
+ |
#ifndef HAVE_STRLCAT |
98 |
+ |
size_t |
99 |
+ |
strlcat(char *dst, const char *src, size_t siz) |
100 |
+ |
{ |
101 |
+ |
char *d = dst; |
102 |
+ |
const char *s = src; |
103 |
+ |
size_t n = siz, dlen; |
104 |
+ |
|
105 |
+ |
while (n-- != 0 && *d != '\0') |
106 |
+ |
d++; |
107 |
+ |
|
108 |
+ |
dlen = d - dst; |
109 |
+ |
n = siz - dlen; |
110 |
+ |
|
111 |
+ |
if (n == 0) |
112 |
+ |
return dlen + strlen(s); |
113 |
+ |
|
114 |
+ |
while (*s != '\0') |
115 |
+ |
{ |
116 |
+ |
if (n != 1) |
117 |
+ |
{ |
118 |
+ |
*d++ = *s; |
119 |
+ |
n--; |
120 |
+ |
} |
121 |
+ |
|
122 |
+ |
s++; |
123 |
+ |
} |
124 |
+ |
|
125 |
+ |
*d = '\0'; |
126 |
+ |
return dlen + (s - src); /* count does not include NUL */ |
127 |
+ |
} |
128 |
+ |
#endif |
129 |
+ |
|
130 |
+ |
#ifndef HAVE_STRLCPY |
131 |
+ |
size_t |
132 |
+ |
strlcpy(char *dst, const char *src, size_t siz) |
133 |
+ |
{ |
134 |
+ |
char *d = dst; |
135 |
+ |
const char *s = src; |
136 |
+ |
size_t n = siz; |
137 |
+ |
|
138 |
+ |
/* Copy as many bytes as will fit */ |
139 |
+ |
if (n != 0 && --n != 0) |
140 |
+ |
{ |
141 |
+ |
do |
142 |
+ |
{ |
143 |
+ |
if ((*d++ = *s++) == 0) |
144 |
+ |
break; |
145 |
+ |
} while (--n != 0); |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
/* Not enough room in dst, add NUL and traverse rest of src */ |
149 |
+ |
if (n == 0) |
150 |
+ |
{ |
151 |
+ |
if (siz != 0) |
152 |
+ |
*d = '\0'; /* NUL-terminate dst */ |
153 |
+ |
while (*s++) |
154 |
+ |
; |
155 |
+ |
} |
156 |
+ |
|
157 |
+ |
return s - src - 1; /* count does not include NUL */ |
158 |
+ |
} |
159 |
+ |
#endif |