strcat+strcat+strcat == baaad

Michal Janusz Miroslaw M.Miroslaw at elka.pw.edu.pl
Mon Dec 2 21:01:34 CST 2002


On Mon, 2 Dec 2002, Francois Gouget wrote:
> Other observations:
>  * my naive strcpy/strcat implementation seems more efficient than the
> one in the glibc! That's pretty weird.

If you have glibc from binary package compiled with optimizations for
other processor that you have, it is possible.

>  * cpycat is much more efficient in this type of scenario. That's not
> very surprising of course. Why does the C library have such braindead
> functions as strcpy and strcat?

Since we are talking about catenating strings only (no %d and family),
then I would suggest combining speed of cpycat (in glibc there's stpcpy)
and ease of use of sprintf and use something like that:

#include <stdarg.h>
char *strpcpymore(char *buf, ...)
{
        const char *p;
        va_list ap;

        va_start(ap, buf);
        while ((p = va_arg(ap, const char *)))
                buf = stpcpy(buf, p);
        va_end(ap);
        return buf;
}

Then we could write:

strpcpymore(buffer, "path", "/", "file", ".", "ext", NULL);

And make everybody happy.

  Michal Miroslaw




More information about the wine-devel mailing list