Improving name-truncation detection

jw schultz jw at pegasys.ws
Tue Jan 20 02:50:46 GMT 2004


On Mon, Jan 19, 2004 at 06:00:32PM -0800, Wayne Davison wrote:
> On Mon, Jan 19, 2004 at 05:44:20PM -0800, Wayne Davison wrote:
> > I'll append my util.c patch to this email.
> 
> Or perhaps to this one...

If you're going to do the strlen(src) and whatnot you might
as well just snag the strlcpy source and tweak it so you
only have to scan the data once.  It isn't very long.
ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/strlcpy.c

If you are going to plug in this low level function, why not
do a version that does path joining so users don't have to
provide the "/".  Do we really have such a variety of
callers that need the overhead of varargs?

> 
> ..wayne..

> --- util.c	2 Jan 2004 07:31:02 -0000	1.123
> +++ util.c	20 Jan 2004 01:14:34 -0000
> @@ -553,6 +553,36 @@ void strlower(char *s)
>  	}
>  }
>  
> +/* Join any number of strings together, putting them in "dest".  The return
> + * value is the length of all the strings, regardless of whether they fit in
> + * destsize or not.  Just NULL-terminate the list of strings.  This function
> + * is _much_ faster than a comparable snprintf() call. */
> +size_t stringjoin(char *dest, size_t destsize, ...)
> +{
> +	va_list ap;  
> +	size_t len, ret = 0;
> +	const char *src;
> +
> +	va_start(ap, destsize);
> +	while (1) {
> +		if (!(src = va_arg(ap, const char *)))
> +			break;
> +		len = strlen(src);
> +		ret += len;
> +		if (destsize > 1) {
> +			if (len >= destsize)
> +				len = destsize - 1;
> +			memcpy(dest, src, len);
> +			destsize -= len;
> +			dest += len;
> +		}
> +	}
> +	*dest = '\0';
> +	va_end(ap);
> +
> +	return ret;
> +}
> +
>  void clean_fname(char *name)
>  {
>  	char *p;

> -- 
> To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync
> Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html

-- 
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		jw at pegasys.ws

		Remember Cernan and Schmitt


More information about the rsync mailing list