2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
16 * strlcpy() and strlcat() replacement functions.
18 * See <http://www.openbsd.org/papers/strlcpy-paper.ps> for details.
20 * Code partially borrowed from compat.c of rsync, written by Andrew
21 * Tridgell (1998) and Martin Pool (2002):
22 * <http://cvs.samba.org/cgi-bin/cvsweb/rsync/lib/compat.c>
27 #include <sys/types.h>
35 strlcat( char *dst, const char *src, size_t size )
37 /* Like strncat() but does not 0 fill the buffer and
38 * always null terminates. */
40 size_t len1 = strlen( dst );
41 size_t len2 = strlen( src );
42 size_t ret = len1 + len2;
44 if( size && ( len1 < size - 1 )) {
45 if( len2 >= size - len1 )
46 len2 = size - len1 - 1;
47 memcpy( dst + len1, src, len2 );
59 strlcpy( char *dst, const char *src, size_t size )
61 /* Like strncpy but does not 0 fill the buffer and
62 * always null terminates. */
64 size_t len = strlen( src );
68 if( len >= size ) len = size - 1;
69 memcpy( dst, src, len );