Well lets start with the return values section of Apple's man page:
RETURN VALUES
The strlcpy() and strlcat() functions return the total length of the string they tried to create.
Sun even documents this in better detail. The return value is:
min(sz, strlen(dest)) + strlen(src)
Well that seems simple enough, so what are the results of the tests. The dest in my tests is a 5 character array. I will represent the contents of this as a string literal.
0 == strlcat( "", "", 0 ) yes it does
3 == strlcat( "", "bbb", 0 ) no it returns 0
2 == strlcat( "aa", "", 5 ) yes it does
2 == strlcat( "", "bb", 5 ) yes it does
4 == strlcat( "aa", "bb", 5 ) yes it does
5 == strlcat( "", "abcde", 5 ) no this returns 4
9 == strlcat( "aaaa", "abcde", 5 ) no this returns 4
? == strlcat( "aa", "abcd", 1 )
Well what should the last one return. The case of dest not having a NULL within size characters is an error condition. I think that this should return 5 (size + strlen(src) ). But, no matter what I think, it actually returns 0.
So of course this means that the example that they give in the man page does not work.
if ( strlcpy( pname, dir, sizeof( pname ) ) >= sizeof( pname ) )
goto toolong;
As we can see from my example above, strlcat( "aaaa", "abcde", 5) only returns 4. And last I checked 4 is less than 5.
On Monday I'll have to try this out on Solaris to see what it says.
And don't get me started on the topic of the routines not validating their input. This is supposed to be a standard library, it should not cause a core dump when it receives bad input. Would it be so terribly difficult to return 0 and set errno if you got a NULL pointer?