return value of strlcat

Discussion in 'C Programming' started by Aleksandar Milivojevic, May 4, 2004.

  1. I had to write implementation of strlcat() (some source from Microsoft
    I got was using it, and strlcat/strlcpy doesn't exist in my libc).

    Two quick questions.

    If NULL is not encountered in first _size_ bytes of _dst_, should
    strlcat() return _size_ + strlen(_src_), or should it return _size_?
    Some manual pages I found were not exactly clear about this.

    If it should return just the _size_ as passed as third parameter to
    strlcat(), what it should return in special case where _size_ is zero?
    strlen(src)? Or zero (since terminating NULL was obviously never
    traversed)?
     
    Aleksandar Milivojevic, May 4, 2004
    #1
    1. Advertising

  2. (Aleksandar Milivojevic) writes:
    > I had to write implementation of strlcat() (some source from Microsoft
    > I got was using it, and strlcat/strlcpy doesn't exist in my libc).
    >
    > Two quick questions.
    >
    > If NULL is not encountered in first _size_ bytes of _dst_, should
    > strlcat() return _size_ + strlen(_src_), or should it return _size_?
    > Some manual pages I found were not exactly clear about this.
    >
    > If it should return just the _size_ as passed as third parameter to
    > strlcat(), what it should return in special case where _size_ is zero?
    > strlen(src)? Or zero (since terminating NULL was obviously never
    > traversed)?


    First, strlcat() is not a standard C function, so we can't really
    advise you about what it should do. <OT>A little Googling indicates
    that it's provided by OpenBSD. You can probably grab an
    implementation from the OpenBSD source tree, or you can ask about it
    in comp.unix.bsd.openbsd.misc (I suggest reading their FAQ
    first).</OT>

    Second, NULL is a macro that expands to a null pointer constant.
    Referring to a null charater as NULL is confusing and/or incorrect. A
    null character should be referred to as a null character, as '\0', or
    as NUL (the latter is a bit charset-specific, but the term is used by
    both ASCII and EBCDIC so it's ok in informal use).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, May 5, 2004
    #2
    1. Advertising

  3. Aleksandar Milivojevic

    CBFalconer Guest

    Aleksandar Milivojevic wrote:
    >
    > I had to write implementation of strlcat() (some source from
    > Microsoft I got was using it, and strlcat/strlcpy doesn't exist
    > in my libc).
    >
    > Two quick questions.
    >
    > If NULL is not encountered in first _size_ bytes of _dst_,
    > should strlcat() return _size_ + strlen(_src_), or should it
    > return _size_? Some manual pages I found were not exactly
    > clear about this.
    >
    > If it should return just the _size_ as passed as third parameter
    > to strlcat(), what it should return in special case where _size_
    > is zero? strlen(src)? Or zero (since terminating NULL was
    > obviously never traversed)?


    strlcat (and strlcpy) are not standard. However you can find
    portable source, and a reference to the original OPENBSD article,
    at:

    <http://cbfalconer.home.att.net/download/strlcpy.zip>

    Those will answer your questions.

    --
    fix (vb.): 1. to paper over, obscure, hide from public view; 2.
    to work around, in a way that produces unintended consequences
    that are worse than the original problem. Usage: "Windows ME
    fixes many of the shortcomings of Windows 98 SE". - Hutchison
     
    CBFalconer, May 5, 2004
    #3
  4. Keith Thompson wrote:
    > First, strlcat() is not a standard C function, so we can't really
    > advise you about what it should do. <OT>A little Googling indicates
    > that it's provided by OpenBSD. You can probably grab an
    > implementation from the OpenBSD source tree, or you can ask about it
    > in comp.unix.bsd.openbsd.misc (I suggest reading their FAQ
    > first).</OT>
    >
    > Second, NULL is a macro that expands to a null pointer constant.
    > Referring to a null charater as NULL is confusing and/or incorrect. A
    > null character should be referred to as a null character, as '\0', or
    > as NUL (the latter is a bit charset-specific, but the term is used by
    > both ASCII and EBCDIC so it's ok in informal use).


    Thanks to both you and CBF for rather quick and helpfull responses. I
    saw the mistake about NULL (as soon as I sent my question). What I ment
    was ASCII NUL character ('\0'), not the null pointer constant. Ah,
    shame on me...
     
    Aleksandar Milivojevic, May 5, 2004
    #4
  5. Aleksandar Milivojevic

    Richard Bos Guest

    Keith Thompson <> wrote:

    > (Aleksandar Milivojevic) writes:
    > > I had to write implementation of strlcat() (some source from Microsoft
    > > I got was using it, and strlcat/strlcpy doesn't exist in my libc).

    >
    > First, strlcat() is not a standard C function, so we can't really
    > advise you about what it should do. <OT>A little Googling indicates
    > that it's provided by OpenBSD.


    But note that _because_ it is not ISO C, you do not know a priori that
    the Microsoft strlcat() did exactly what the Open BSD one does. It might
    be wise to check that it does.

    Richard
     
    Richard Bos, May 5, 2004
    #5
  6. (Richard Bos) wrote in message news:<>...
    > But note that _because_ it is not ISO C, you do not know a priori that
    > the Microsoft strlcat() did exactly what the Open BSD one does. It might
    > be wise to check that it does.


    The strlcat() function is called from part of source that would be
    (normally) compilied only on AIX. However because of the changes I'm
    making, it will be included for other systems also. They also used
    strlcpy() in parts of source that compiles on AIX, Linux, Solaris and
    HP/UX, so there's Microsoft's implementation of strlcpy() provided
    that does (by looking at source) exactly as manual page from BSD-ish
    system says it should do (but no strlcat() implementation, since AIX
    has that function). So I guess it is safe to assume that Microsoft
    strlcat() does the same thing as BSD strlcat().
     
    Aleksandar Milivojevic, May 5, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    3,003
  2. Seong-Kook Shin
    Replies:
    1
    Views:
    523
    Richard Bos
    Jun 18, 2004
  3. RoSsIaCrIiLoIA

    Do you like my strlcpy strlcat etc?

    RoSsIaCrIiLoIA, Feb 4, 2005, in forum: C Programming
    Replies:
    13
    Views:
    575
    CBFalconer
    Feb 6, 2005
  4. Greenhorn
    Replies:
    15
    Views:
    885
    Keith Thompson
    Mar 6, 2005
  5. strlcpy and strlcat

    , Dec 6, 2007, in forum: C Programming
    Replies:
    15
    Views:
    1,567
    CBFalconer
    Dec 11, 2007
Loading...

Share This Page