1 # FUNC_VSNPRINTF_EXISTS
3 # Checks if vsnprintf exists. x_cv_func_vsnprintf_exists is set.
4 AC_DEFUN([FUNC_VSNPRINTF_EXISTS],
5 [AC_REQUIRE([AC_FUNC_VPRINTF])
6 if test $ac_cv_func_vprintf != yes; then x_cv_func_vsnprintf_exists=no; else
7 AC_CHECK_FUNC(vsnprintf, [x_cv_func_vsnprintf_exists=yes], [x_cv_func_vsnprintf_exists=no])
9 ])# FUNC_VSNPRINTF_EXISTS
13 # Checks if vsnprintf honors its size argument. VSNPRINTF_IS_VSPRINTF is defined
14 # if not. x_cv_func_vsnprintf_size is set to yes or no.
16 # Note that this depends on FUNC_VSNPRINTF_EXISTS, so if that fails this will
17 # also fail (and define VSNPRINTF_IS_VSPRINTF).
18 AC_DEFUN([FUNC_VSNPRINTF_SIZE],
19 [AC_REQUIRE([FUNC_VSNPRINTF_EXISTS])
20 if test $x_cv_func_vsnprintf_exists != yes; then x_cv_func_vsnprintf_size=no; else
21 AC_CACHE_CHECK([if vsnprintf honors the size argument], x_cv_func_vsnprintf_size,
25 #if STDC_HEADERS || HAVE_STDIO_H
28 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
30 int doit(char *str, size_t size, const char *format, ...){
34 r=vsnprintf(str, size, format, ap);
39 [[char foo[]="ABC"; doit(foo, 2, "%d", 12);
40 exit((foo[0]=='1' && foo[1]=='\0' && foo[2]=='C')?0:1);]])],
41 [x_cv_func_vsnprintf_size=yes],
42 [x_cv_func_vsnprintf_size=no],
43 [x_cv_func_vsnprintf_size=no])])
45 test $x_cv_func_vsnprintf_size != yes && AC_DEFINE(VSNPRINTF_IS_VSPRINTF, 1, [Define if vsnprintf ignores the size argument])
46 ])# FUNC_VSNPRINTF_SIZE
48 # FUNC_VSNPRINTF_RETVAL
50 # Checks if vsnprintf returns the number of bytes that would have been written,
51 # as specified by C99. VSNPRINTF_BOGUS_RETVAL is defined if not.
52 # x_cv_func_vsnprintf_retval is set to yes or no.
54 # Note that this depends on FUNC_VSNPRINTF_SIZE, so if that fails this will fail
55 # too and VSNPRINTF_BOGUS_RETVAL will be set.
56 AC_DEFUN([FUNC_VSNPRINTF_RETVAL],
57 [AC_REQUIRE([FUNC_VSNPRINTF_SIZE])
58 if test $x_cv_func_vsnprintf_size != yes; then x_cv_func_vsnprintf_retval=no; else
59 AC_CACHE_CHECK([if vsnprintf return value is sane], x_cv_func_vsnprintf_retval,
63 #if STDC_HEADERS || HAVE_STDIO_H
66 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
68 int doit(char *str, size_t size, const char *format, ...){
72 r=vsnprintf(str, size, format, ap);
77 [[char foo[10]; exit((doit(foo, 1, "%d", 9876)==4)?0:1);]])],
78 [x_cv_func_vsnprintf_retval=yes],
79 [x_cv_func_vsnprintf_retval=no],
80 [x_cv_func_vsnprintf_retval=no])])
82 test $x_cv_func_vsnprintf_retval != yes && AC_DEFINE(VSNPRINTF_BOGUS_RETVAL, 1, [Define if vsnprintf's return value isn't as specified by C99])
83 ])# FUNC_VSNPRINTF_RETVAL
85 # FUNC_VSNPRINTF_NULL_OK
86 # ---------------------
87 # Checks whether vsnprintf acceps a NULL string if size is zero. Sets
88 # x_cv_func_vsnprintf_null_ok. If so, define VSNPRINTF_NULL_OK.
90 # Note that this depends on FUNC_VSNPRINTF_SIZE, so if that fails this will
91 # fail too and VSNPRINTF_NULL_OK will not be set.
92 AC_DEFUN([FUNC_VSNPRINTF_NULL_OK],
93 [AC_REQUIRE([FUNC_VSNPRINTF_SIZE])
94 if test $x_cv_func_vsnprintf_size != yes; then x_cv_func_vsnprintf_null_ok=no; else
95 AC_CACHE_CHECK([if vsnprintf(NULL, 0, ...) works], x_cv_func_vsnprintf_null_ok,
99 #if STDC_HEADERS || HAVE_STDIO_H
102 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
104 int doit(char *str, size_t size, const char *format, ...){
107 va_start(ap, format);
108 r=vsnprintf(str, size, format, ap);
113 [int r=doit(NULL, 0, "%d", 100); exit((r==3 || r==-1)?0:1);])],
114 [x_cv_func_vsnprintf_null_ok=yes],
115 [x_cv_func_vsnprintf_null_ok=no],
116 [x_cv_func_vsnprintf_null_ok=no])])
118 test $x_cv_func_vsnprintf_null_ok = yes && AC_DEFINE(VSNPRINTF_NULL_OK, 1, [Define if vsnprintf(NULL, 0, ...) works properly])
119 ])# FUNC_VSNPRINTF_NULL_OK
121 # FUNC_VSNPRINTF([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
123 # Checks various aspects of vsnprintf. In particular:
125 # * Is the size honored?
126 # * Is the return value correct?
127 # * Is NULL with length 0 ok?
128 # If all the above pass, HAVE_WORKING_VSNPRINTF is defined and
129 # x_cv_func_vsnprintf_working is set to yes. Otherwise, it's set to no.
130 AC_DEFUN([FUNC_VSNPRINTF],
131 [AC_REQUIRE([FUNC_VSNPRINTF_RETVAL])
132 AC_REQUIRE([FUNC_VSNPRINTF_NULL_OK])
133 if test $x_cv_func_vsnprintf_retval = yes -a $x_cv_func_vsnprintf_null_ok = yes; then
134 AC_DEFINE(HAVE_WORKING_VSNPRINTF, 1, [Define if vsnprintf works properly])
135 x_cv_func_snprintf_working=yes
138 x_cv_func_snprintf_working=no
143 # FUNC_VSNPRINTF_LIBOBJ
144 # --------------------
145 # If FUNC_VSNPRINTF fails, does AC_LIBOBJ.
146 AC_DEFUN([FUNC_VSNPRINTF_LIBOBJ],
147 [FUNC_VSNPRINTF(, [AC_LIBOBJ([vsnprintf])
148 AC_DEFINE([vsnprintf], [rpl_vsnprintf], [Define to rpl_vsnprintf if the replacement function should be used.])])])
149 ])#FUNC_VSNPRINTF_LIBOBJ