repo: ngircd
action: commit
revision: 
path_from: 
revision_from: fbdf85b553448fac0e15f6553f9b408ca486c24f:
path_to: 
revision_to: 
git.thebackupbox.net
ngircd
git clone git://git.thebackupbox.net/ngircd
commit fbdf85b553448fac0e15f6553f9b408ca486c24f
Author: Alexander Barton 
Date:   Thu Dec 26 14:34:11 2002 +0000

    - strlcat() and strlcpy() replacement functions.

diff --git a/src/portab/strlcpy.c b/src/portab/strlcpy.c
index 40992c0826a2c9305278fe5846e28847992380fc..
index ..f77527a09f068788d34a97c0ec53ad3c63c39f28 100644
--- a/src/portab/strlcpy.c
+++ b/src/portab/strlcpy.c
@@ -8,17 +8,68 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * strlcpy() and strlcat() replacement functions
+ * 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 "portab.h"

-static char UNUSED id[] = "$Id: strlcpy.c,v 1.1 2002/12/26 13:18:46 alex Exp $";
+static char UNUSED id[] = "$Id: strlcpy.c,v 1.2 2002/12/26 14:34:11 alex Exp $";

 #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( len1 + len2 >= size ) len2 = size - ( len1 + 1 );
+	if( len2 > 0 )
+	{
+		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 );
+
+	if( size <= 0 ) return len;
+	if( len >= size ) len = size - 1;
+	memcpy( dst, src, len );
+	dst[len] = 0;
+	return len;
+} /* strlcpy */
+
+#endif
+
+
 /* -eof- */

-----END OF PAGE-----