[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: strlcpy and strlcat in linux libc ?



On Sun, Mar 10, 2002 at 03:21:33AM +0100, Manfred Wassmann wrote:
> That's wrong.  The strlc* functions return the length of the string
> that was created (even though the manpage [1] uses the mistakable
> wording ``tried to create'' in the return values section it's obvious
> from the rest of the document).  So you can use the return value of
> strlc* instead of calling strlen afterwards.

Maybe it's just me but the examples seems to show that they're indeed
returning the length of the full src string.

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

And the wording in Return Value is also very clear.
    The strlcpy() and strlcat() functions return the total length of the
    string they tried to create.  For strlcpy() that means the length
    of src.

Notice the "that means the length of src".

-- 
Peter Mathiasson                   | GPG Fingerprint:
E-Mail: peter(at)mathiasson(dot)nu |  A9A7 F8F6 9821 F415 B066
Web   : http://www.mathiasson.nu   |  77F1 7FF5 C2E6 7BF2 F228

Attachment: pgpamynIqRPTk.pgp
Description: PGP signature


Reply to: