Subject: Query about return value of snprintf
To: None <tech-userlevel@netbsd.org>
From: None <mcr@solidum.com>
List: tech-userlevel
Date: 06/17/1999 17:02:11
-----BEGIN PGP SIGNED MESSAGE-----


  The NetBSD man page says that we do:

     These functions return the number of characters printed (not including
     the trailing `\0' used to end output to strings).

  Which is what I expected.
  The GNU glibc man page (on RedHat 6.0 Linux from man-pages-1.17-1, but
also for the 6.0 release of man-pages-1.23-3) for snprintf says: 
	
RETURN VALUE
       If  the output was truncated, the return value is -1, oth-
       erwise it is the number of characters stored, not  includ-
       ing the terminating null.

  and the one for printf(3) (don't ask me why there are two pages)
says:
       These  functions  return  the number of characters printed
       (not including the trailing `\0' used  to  end  output  to
       strings).   snprintf  and vsnprintf do not write more than
       size bytes (including the trailing '\0'), and return -1 if
       the output was truncated due to this limit.

  I do have any code that cares one way or another. I also have a portable
snprintf() that I use on NT and Slowlaris and it makes some of my regression
tests a pain in the butt since I prefer to use the OS resident one. 

  I realize that this isn't POSIX, but are there any opinions as what is
reasonable? I see reasons why the GNU version is useful, but I also see that
it may break existing code.

   :!mcr!:            |  Network and security consulting/contract programming
   Michael Richardson |   ...working from my front lawn with a long cord...
 Personal: http://www.sandelman.ottawa.on.ca/People/Michael_Richardson/Bio.html
 Corporate: http://www.sandelman.ottawa.on.ca/SSW/
	ON HUMILITY: To err is human, to moo bovine.







-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: latin1
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface

iQDVAwUBN2liRHMJp3VWzPepAQGyRwYAs9M2SNHRmMwycIqQnDYSqYe/YImjOag0
maX7XlNIyZGHgyej2IQXZ0DOuMhm6+/5rNWcGR8lkC9ybYb9f4Rp59temM46MHaP
Is+b3ZCaUcemSDjwwtFXG6h1Er/hFIu64cUvlKHnpo/DSKh8f22cfyErcLA7WHN2
tyxgTve4z8OraY5uuf8m8LTP2YxPeHbt7f6oErbf6KFNT0m8bjpUxxgDA92w1Zpk
GXDQxJ5pi/n9S2y9gFUyY++rWzZmp11n
=m3jY
-----END PGP SIGNATURE-----