Theres loads of snprintf implementations lurking in various libc but I believe the C9x standard differs from quite a few especially in the return value. snprintf should return the number of characters that would have been put into the string (excluding the NULL char in this count). And also allows snprintf to take 0 for its len so as to use snprintf as a predictor for the final length of the string (which implys that the buf can be NULL if the len is 0) current non fully complient implementations are... At least solaris & Mark Martinec's standalone snprintf 1.3 Does not take a NULL str and len 0, returns -1 for error in this case, otherwise is perfect At least Older glibc returns -1 to flag an overflow, not the predicted length At least Not quite as old glibc returns the predicted count, but including the NULL char in this count, i.e. returns correct+1 The sort of things Id expect knowing my fellow man a) returning the actual number of chars put into the string, with or without including terminating NULL's b) in the case of overflow either terminating or not terminating the string Propose attached AC_FUNC_SNPRINTF which defines HAVE_SNPRINTF in the case that the following test holds true exit (!(3 <= snprintf(NULL,0,"%d",100))); #if 0 /*I think this is unnecessarily punitive*/ exit (!(3 == snprintf(NULL,0,"%d",100))); #endif C. P.S. shouldn't there also be an AC_C_LONG_LONG ? (http://www.csn.ul.ie/~caolan/publink/autoconf/ac_c_long_long.m4) Real Life: Caolan McNamara * Doing: MSc in HCI Work: [EMAIL PROTECTED] * Phone: +353-86-8790257 URL: http://www.csn.ul.ie/~caolan * Sig: an oblique strategy Assemble some of the elements in a group and treat the group
dnl @synopsis AC_caolan_FUNC_SNPRINTF dnl dnl Provides a test for a fully C9x complient snprintf dnl function. dnl dnl defines HAVE_SNPRINTF if it is found, and dnl sets ac_cv_func_snprintf to yes, otherwise to no dnl dnl @version $Id$ dnl @author Caolan McNamara <[EMAIL PROTECTED]> dnl AC_DEFUN(AC_caolan_FUNC_SNPRINTF, [AC_CACHE_CHECK(for working snprintf, ac_cv_func_snprintf, [AC_TRY_RUN([#include <stdio.h> int main () { exit (!(3 <= snprintf(NULL,0,"%d",100))); } ], ac_cv_func_snprintf=yes, ac_cv_func_snprintf=no, ac_cv_func_snprintf=no)]) if test $ac_cv_func_snprintf = yes; then AC_DEFINE(HAVE_SNPRINTF) fi ])