httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chuck Murcko <>
Subject Re: snprintf()
Date Tue, 07 Jan 1997 03:17:06 GMT
There's also a time-tested one in xinetd, and a varargs version of same:
(excerpted from the man page for the str lib functions)

       int strx_nprint( buf, len, format, ... )
       char *buf ;
       int len ;
       char *format ;

       int strx_nprintv( buf, len, format, ap )
       char *buf ;
       int len ;
       char *format ;
       va_list ap ;

       All functions are similar in functionality  to  sprintf().
       Their  only  difference  is  in  their  return values. For
       information about  their  conversion  capabilities,  check

       The  difference between the str_* and the strx_* functions
       is that the latter take an extra argument, the size of the
       buffer,  so  that  they will never write beyond the end of
       the buffer. Writing beyond the end of the buffer is possi-
       ble  with the str_* functions.  Invoking any of the strx_*
       functions with the len argument set to 0 is  the  same  as
       calling the equivalent str_* function.

       All  functions  will  append  a NUL at the end of buf (the
       strx_* functions will not do this  if  it  would  cause  a
       buffer overrun).

       str_print(), str_printv(), strx_print(), and strx_printv()
       will put in *countp the number of characters placed in buf
       excluding  the ending NUL (this happens only if *countp is
       not NULL ).

       The functions that have a name ending in 'v'  are  similar
       to  those  without the 'v' at the end of their name except
       that instead of accepting a variable number of  arguments,
       they expect a varargs(3) argument list.

       str_sprint(),     str_sprintv(),     strx_sprint(),    and
       strx_sprintv() return buf.

sameer liltingly intones:
> > 
> > Not a good idea... It basically _ignores_ the max-length parameter.
> 	oh. I was unaware of that. (I didn't look at the code, I just
> saw "oh, look snprintf.c.. we need that for Apache")
> > 
> > I had posted a pretty portable version awhile ago. I can repost
> > if need be.
> 	Let's use that, then.
> -- 
> Sameer Parekh					Voice:   510-986-8770
> President					FAX:     510-986-8777
> C2Net 		    C2Net is having a party:

Chuck Murcko	N2K Inc.	Wayne PA
And now, on a lighter note:
Bumper sticker:

"All the parts falling off this car are of the very finest British

View raw message