Strip off version numbers from dir name
[dockapps.git] / wmweather+ / m4 / vsnprintf.m4
bloba5de274cfc000e1b27f7dace38dcedb150eb4c5e
1 # FUNC_VSNPRINTF_EXISTS
2 # --------------------
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])
8 fi
9 ])# FUNC_VSNPRINTF_EXISTS
11 # FUNC_VSNPRINTF_SIZE
12 # ------------------
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,
22 [AC_RUN_IFELSE(
23 [AC_LANG_PROGRAM(
24 [[#include <stdarg.h>
25 #if STDC_HEADERS || HAVE_STDIO_H
26 # include <stdio.h>
27 #else
28 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
29 #endif
30 int doit(char *str, size_t size, const char *format, ...){
31     va_list ap;
32     int r;
33     va_start(ap, format);
34     r=vsnprintf(str, size, format, ap);
35     va_end(ap);
36     return r;
38 ]],
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
49 # ------------------
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,
60 [AC_RUN_IFELSE(
61 [AC_LANG_PROGRAM(
62 [[#include <stdarg.h>
63 #if STDC_HEADERS || HAVE_STDIO_H
64 # include <stdio.h>
65 #else
66 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
67 #endif
68 int doit(char *str, size_t size, const char *format, ...){
69     va_list ap;
70     int r;
71     va_start(ap, format);
72     r=vsnprintf(str, size, format, ap);
73     va_end(ap);
74     return r;
76 ]],
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,
96 [AC_RUN_IFELSE(
97 [AC_LANG_PROGRAM(
98 [[#include <stdarg.h>
99 #if STDC_HEADERS || HAVE_STDIO_H
100 # include <stdio.h>
101 #else
102 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
103 #endif
104 int doit(char *str, size_t size, const char *format, ...){
105     va_list ap;
106     int r;
107     va_start(ap, format);
108     r=vsnprintf(str, size, format, ap);
109     va_end(ap);
110     return r;
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])
122 # -------------
123 # Checks various aspects of vsnprintf. In particular:
124 #  * Does it exist?
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
136     $1
137 else
138     x_cv_func_snprintf_working=no
139     $2
141 ])# FUNC_VSNPRINTF
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