X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fportab%2Fstrlcpy.c;h=ae2018bcf940a3c47a1cc265740c58fbff70dce8;hp=40992c0826a2c9305278fe5846e28847992380fc;hb=03628dbeaf40a9de34b3eb6d5bf6dd34eed8248c;hpb=60cf07c8754c9291527fde2791e6353da7674d8c diff --git a/src/portab/strlcpy.c b/src/portab/strlcpy.c index 40992c08..ae2018bc 100644 --- a/src/portab/strlcpy.c +++ b/src/portab/strlcpy.c @@ -1,24 +1,78 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) + * Copyright (c)2001-2005 Alexander Barton (alex@barton.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. - * - * strlcpy() and strlcat() replacement functions */ - #include "portab.h" -static char UNUSED id[] = "$Id: strlcpy.c,v 1.1 2002/12/26 13:18:46 alex Exp $"; +/** + * @file + * strlcpy() and strlcat() replacement functions. + * + * See for details. + * + * Code partially borrowed from compat.c of rsync, written by Andrew + * Tridgell (1998) and Martin Pool (2002): + * + */ #include "imp.h" +#include +#include #include "exp.h" +#ifndef HAVE_STRLCAT + +GLOBAL size_t +strlcat( char *dst, const char *src, size_t size ) +{ + /* Like strncat() but does not 0 fill the buffer and + * always null terminates. */ + + size_t len1 = strlen( dst ); + size_t len2 = strlen( src ); + size_t ret = len1 + len2; + + if( size && ( len1 < size - 1 )) { + if( len2 >= size - len1 ) + len2 = size - len1 - 1; + memcpy( dst + len1, src, len2 ); + dst[len1 + len2] = 0; + } + return ret; +} /* strlcat */ + +#endif + + +#ifndef HAVE_STRLCPY + +GLOBAL size_t +strlcpy( char *dst, const char *src, size_t size ) +{ + /* Like strncpy but does not 0 fill the buffer and + * always null terminates. */ + + size_t len = strlen( src ); + size_t ret = len; + + if( size > 0 ) { + if( len >= size ) len = size - 1; + memcpy( dst, src, len ); + dst[len] = 0; + } + return ret; +} /* strlcpy */ + +#endif + + /* -eof- */