Alan Coopersmith <[EMAIL PROTECTED]> wrote:

> Roland Mainz wrote:
> > char *s;
> > ...
> > strcat(s, "foo");
> > strcat(s, "/");
> > strcat(s, "bar");
>
> Also, as I noted on IRC, strlcat() is close to this, and much safer.
> You could write the above as:
>
> char *s;
> int len; /* size of buffer s */
> int used = 0;
>
> used = strlcpy(s, "foo", len);
> if (used < len)
>      used += strlcat(s + used, "/", len - used);
> if (used < len)
>      used += strlcat(s + used, "bar", len - used);

This is an interface that also use since some time and that
seems to be the best way to deal with buffer size problems in case you 
e.g. cannot predict how many strings you need or how long they are.

In case you deal with allocated space, you may use this interface
also to grow a buffer in case it is needed.

Jörg

-- 
 EMail:[EMAIL PROTECTED] (home) Jörg Schilling D-13353 Berlin
       [EMAIL PROTECTED]                (uni)  
       [EMAIL PROTECTED]     (work) Blog: http://schily.blogspot.com/
 URL:  http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to