Hi Theo,

On 2/13/22 23:45, Theo de Raadt wrote:
> Your proposal isn't an improvement over the current situation with strl*
> functions, and I don't think this is helpful.
>
> Alejandro Colomar (man-pages) <[email protected]> wrote:
>>    Compared to other string copy and concatenation functions
>>        strlcat(3BSD)
>>               *cat()  functions  have  an  inherent  performance
>>               problem:  each  *cat()  call has to find again the
>>               teminating null byte in  the  dest  string.   Read
>>               about    Shlemiel    the    painter’s    algorithm
>>               ⟨https://www.joelonsoftware.com/2001/12/11/back-
>>               to-basics/⟩.

I agree that the improvement is tiny, and more theoretical than
practical (I have never seen strlcat(3) in a loop).  Also, strlcat(3)
requires testing for truncation after every call, but it's also a minor
thing.

An equivalent usage of the example shown in strlcat(3):

Ignore truncation:
    strlcat(3):

           char *s, *p, buf[BUFSIZ];

           ...

           (void)strlcpy(buf, s, sizeof(buf));
           (void)strlcat(buf, p, sizeof(buf));

    stpecpy():

           char *s, *p, buf[BUFSIZ];
           char *end = &buf[sizeof(buf) - 1];

           ...

           (void)stpecpy(stpecpy(buf, s, end), p, end);

Detect truncation:
    strlcat(3):

           char *dir, *file, pname[MAXPATHLEN];

           ...

           if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname))
                   goto toolong;
           if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname))
                   goto toolong;

    stpecpy():

           char *dir, *file, pname[MAXPATHLEN];
           char *end = &pname[sizeof(pname) - 1];

           ...

           if (stpecpy(stpecpy(pname, dir, end), file, end) > end)
                   goto toolong;


I agree that they're quite similar, and for a system already providing
strl* functions, there's probably not enough improvement to add it.
However, considering some systems don't have strl* functions, and
explicitly don't want to add them (glibc rejected strl* functions),
there it might be useful to add this function.


Thanks for your opinion.

Regards,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Reply via email to