2 Copy from samba lib/replace.c
4 Unix SMB/CIFS implementation.
5 replacement routines for broken systems
6 Copyright (C) Andrew Tridgell 1992-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 strlcpy strlcat functions.
29 #include <atalk/util.h>
33 /* like strncpy but does not 0 fill the buffer and always null
34 terminates. bufsize is the size of the destination buffer */
35 size_t strlcpy(char *d, const char *s, size_t bufsize)
37 size_t len = strlen(s);
53 /* like strncat but does not 0 fill the buffer and always null
54 terminates. bufsize is the length of the buffer, which should
55 be one more than the maximum resulting string length */
56 size_t strlcat(char *d, const char *s, size_t bufsize)
58 size_t len1 = strlen(d);
59 size_t len2 = strlen(s);
60 size_t ret = len1 + len2;
62 if (len1 >= bufsize) {
65 if (len1+len2 >= bufsize) {
66 len2 = bufsize - (len1+1);
69 memcpy(d+len1, s, len2);