From: Pierangelo Masarati Date: Sat, 12 Jan 2002 16:02:51 +0000 (+0000) Subject: slap_strncopy function X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~174 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=725e13dadea4d832ecf265484fa49c5a92abb98b;p=openldap slap_strncopy function --- diff --git a/servers/slapd/charray.c b/servers/slapd/charray.c index 2b628d7bbb..01057217a8 100644 --- a/servers/slapd/charray.c +++ b/servers/slapd/charray.c @@ -229,6 +229,24 @@ slap_strcopy( return a-1; } +/* strncopy is like strcpy except it returns a pointer to the trailing NUL of + * the result string. This allows fast construction of catenated strings + * without the overhead of strlen/strcat. + */ +char * +slap_strncopy( + char *a, + const char *b, + size_t n +) +{ + if (!a || !b || n == 0) + return a; + + while ((*a++ = *b++) && n-- > 0) ; + return a-1; +} + /* Unlike charray_add, bvarray_add does not make a new copy of the * source string. Typically it is used where ber_bvecadd was before, * and ber_bvecadd didn't duplicate its source either. diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5e23ef9830..595c4936c6 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -283,6 +283,8 @@ LDAP_SLAPD_F (void) bvarray_free LDAP_P(( struct berval *a )); LDAP_SLAPD_F (char *) slap_strcopy LDAP_P(( char *dst, const char *src )); +LDAP_SLAPD_F (char *) slap_strncopy LDAP_P(( + char *dst, const char *src, size_t n )); /* * controls.c