Re: Samba problems - errata

From: David LeBlanc (dleblancat_private)
Date: Sun May 10 1998 - 18:40:00 PDT

  • Next message: der Mouse: "Re: 3Com switches - undocumented access level.)"

    I goofed somewhat - correction below:
    
    At 05:54 PM 5/10/98 -0400, David LeBlanc wrote:
    
    >At least snprintf returns an error if it can't fill fit everything -
    >strncpy won't.  Probably the best case would be to have it look like so:
    
    >if(snprintf(blah, blah...) < 0)
    >{
    >        wail;
    >        complain;
    >}
    
    As has been pointed out to me by Theo, snprintf() isn't ANSI, and depends
    on implementation.  The one I use on NT does return a negative number if
    the buffer is completely filled.  Theo's (and presumably other UNIX's as
    well, but then again it could be another sys V vs. BSD sort of thing - I
    dunno - I'm an NT guy, so...) will return the number of bytes it _would_
    have stuck in the buffer, which means you need to check the error a little
    differently.  Same idea, and something to look out for whilst porting.
    
    which would give you:
    
    if(snprintf(buf, bufsize, args) + 1 > bufsize)
    {
            wail;
            complain;
    }
    
    Still a safer way of dealing with things than strncpy.  BTW, I did check
    and strncpy is ANSI - so it should behave the same.
    
    
    David LeBlanc
    dleblancat_private
    



    This archive was generated by hypermail 2b30 : Fri Apr 13 2001 - 13:53:10 PDT