]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/ThirdParty/c99_snprintf/c99-snprintf_1.1/m4/snprintf.m4
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / ThirdParty / c99_snprintf / c99-snprintf_1.1 / m4 / snprintf.m4
1 # $Id: snprintf.m4,v 1.1.1.1 2008/01/06 03:24:00 holger Exp $
2
3 # Copyright (c) 2008 Holger Weiss <holger@jhweiss.de>.
4 #
5 # This code may freely be used, modified and/or redistributed for any purpose.
6 # It would be nice if additions and fixes to this file (including trivial code
7 # cleanups) would be sent back in order to let me include them in the version
8 # available at <http://www.jhweiss.de/software/snprintf.html>.  However, this is
9 # not a requirement for using or redistributing (possibly modified) versions of
10 # this file, nor is leaving this notice intact mandatory.
11
12 # HW_HEADER_STDARG_H
13 # ------------------
14 # Define HAVE_STDARG_H to 1 if <stdarg.h> is available.
15 AC_DEFUN([HW_HEADER_STDARG_H],
16 [
17   AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used.
18   AC_CHECK_HEADERS_ONCE([stdarg.h])
19 ])# HW_HEADER_STDARG_H
20
21 # HW_HEADER_VARARGS_H
22 # -------------------
23 # Define HAVE_VARARGS_H to 1 if <varargs.h> is available.
24 AC_DEFUN([HW_HEADER_VARARGS_H],
25 [
26   AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used.
27   AC_CHECK_HEADERS_ONCE([varargs.h])
28 ])# HW_HEADER_VARARGS_H
29
30 # HW_FUNC_VA_COPY
31 # ---------------
32 # Set $hw_cv_func_va_copy to "yes" or "no".  Define HAVE_VA_COPY to 1 if
33 # $hw_cv_func_va_copy is set to "yes".  Note that it's "unspecified whether
34 # va_copy and va_end are macros or identifiers declared with external linkage."
35 # (C99: 7.15.1, 1)  Therefore, the presence of va_copy(3) cannot simply "be
36 # tested with #ifdef", as suggested by the Autoconf manual (5.5.1).
37 AC_DEFUN([HW_FUNC_VA_COPY],
38 [
39   AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
40   AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H.
41   AC_CACHE_CHECK([for va_copy],
42     [hw_cv_func_va_copy],
43     [AC_RUN_IFELSE(
44       [AC_LANG_PROGRAM(
45         [[#if HAVE_STDARG_H
46         #include <stdarg.h>
47         #elif HAVE_VARARGS_H
48         #include <varargs.h>
49         #endif]],
50         [[va_list ap, aq; va_copy(aq, ap);]])],
51       [hw_cv_func_va_copy=yes],
52       [hw_cv_func_va_copy=no],
53       [hw_cv_func_va_copy=no])])
54   AS_IF([test "$hw_cv_func_va_copy" = yes],
55     [AC_DEFINE([HAVE_VA_COPY], [1],
56       [Define to 1 if you have the `va_copy' function or macro.])])
57 ])# HW_FUNC_VA_COPY
58
59 # HW_FUNC___VA_COPY
60 # -----------------
61 # Set $hw_cv_func___va_copy to "yes" or "no".  Define HAVE___VA_COPY to 1 if
62 # $hw_cv_func___va_copy is set to "yes".
63 AC_DEFUN([HW_FUNC___VA_COPY],
64 [
65   AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
66   AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H.
67   AC_CACHE_CHECK([for __va_copy],
68     [hw_cv_func___va_copy],
69     [AC_RUN_IFELSE(
70       [AC_LANG_PROGRAM(
71         [[#if HAVE_STDARG_H
72         #include <stdarg.h>
73         #elif HAVE_VARARGS_H
74         #include <varargs.h>
75         #endif]],
76         [[va_list ap, aq; __va_copy(aq, ap);]])],
77       [hw_cv_func___va_copy=yes],
78       [hw_cv_func___va_copy=no],
79       [hw_cv_func___va_copy=no])])
80   AS_IF([test "$hw_cv_func___va_copy" = yes],
81     [AC_DEFINE([HAVE___VA_COPY], [1],
82       [Define to 1 if you have the `__va_copy' function or macro.])])
83 ])# HW_FUNC___VA_COPY
84
85 # HW_FUNC_VSNPRINTF
86 # -----------------
87 # Set $hw_cv_func_vsnprintf and $hw_cv_func_vsnprintf_c99 to "yes" or "no",
88 # respectively.  Define HAVE_VSNPRINTF to 1 only if $hw_cv_func_vsnprintf_c99
89 # is set to "yes".  Otherwise, define vsnprintf to rpl_vsnprintf and make sure
90 # the replacement function will be built.
91 AC_DEFUN([HW_FUNC_VSNPRINTF],
92 [
93   AC_PREREQ([2.60])dnl 2.59 should work if some AC_TYPE_* macros are replaced.
94   AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
95   AC_CHECK_FUNC([vsnprintf],
96     [hw_cv_func_vsnprintf=yes],
97     [hw_cv_func_vsnprintf=no])
98   AS_IF([test "$hw_cv_func_vsnprintf" = yes],
99     [AC_CACHE_CHECK([whether vsnprintf is C99 compliant],
100       [hw_cv_func_vsnprintf_c99],
101       [AC_RUN_IFELSE(
102         [AC_LANG_PROGRAM(
103           [[#if HAVE_STDARG_H
104           #include <stdarg.h>
105           #endif
106           #include <stdio.h>
107           static int testprintf(char *buf, size_t size, const char *format, ...)
108           {
109             int result;
110             va_list ap;
111             va_start(ap, format);
112             result = vsnprintf(buf, size, format, ap);
113             va_end(ap);
114             return result;
115           }]],
116           [[char buf[43];
117           if (testprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
118               testprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
119               buf[0] != 'T' || buf[3] != '\0')
120             return 1;]])],
121         [hw_cv_func_vsnprintf_c99=yes],
122         [hw_cv_func_vsnprintf_c99=no],
123         [hw_cv_func_vsnprintf_c99=no])])],
124     [hw_cv_func_snprintf_c99=no])
125   AS_IF([test "$hw_cv_func_vsnprintf_c99" = yes],
126     [AC_DEFINE([HAVE_VSNPRINTF], [1],
127       [Define to 1 if you have a C99 compliant `vsnprintf' function.])],
128     [AC_DEFINE([vsnprintf], [rpl_vsnprintf],
129       [Define to rpl_vsnprintf if the replacement function should be used.])
130     AC_CHECK_HEADERS([inttypes.h locale.h stddef.h stdint.h])
131     AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep],
132       [], [], [#include <locale.h>])
133     AC_TYPE_LONG_DOUBLE
134     AC_TYPE_LONG_LONG_INT
135     AC_TYPE_UNSIGNED_LONG_LONG_INT
136     AC_TYPE_SIZE_T
137     AC_TYPE_INTMAX_T
138     AC_TYPE_UINTMAX_T
139     AC_TYPE_UINTPTR_T
140     AC_CHECK_TYPES([ptrdiff_t])
141     AC_CHECK_FUNCS([localeconv])
142     _HW_FUNC_XPRINTF_REPLACE])
143 ])# HW_FUNC_VSNPRINTF
144
145 # HW_FUNC_SNPRINTF
146 # ----------------
147 # Set $hw_cv_func_snprintf and $hw_cv_func_snprintf_c99 to "yes" or "no",
148 # respectively.  Define HAVE_SNPRINTF to 1 only if $hw_cv_func_snprintf_c99
149 # is set to "yes".  Otherwise, define snprintf to rpl_snprintf and make sure
150 # the replacement function will be built.
151 AC_DEFUN([HW_FUNC_SNPRINTF],
152 [
153   AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our snprintf(3) calls vsnprintf(3).
154   AC_CHECK_FUNC([snprintf],
155     [hw_cv_func_snprintf=yes],
156     [hw_cv_func_snprintf=no])
157   AS_IF([test "$hw_cv_func_snprintf" = yes],
158     [AC_CACHE_CHECK([whether snprintf is C99 compliant],
159       [hw_cv_func_snprintf_c99],
160       [AC_RUN_IFELSE(
161         [AC_LANG_PROGRAM([[#include <stdio.h>]],
162           [[char buf[43];
163           if (snprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
164               snprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
165               buf[0] != 'T' || buf[3] != '\0')
166             return 1;]])],
167         [hw_cv_func_snprintf_c99=yes],
168         [hw_cv_func_snprintf_c99=no],
169         [hw_cv_func_snprintf_c99=no])])],
170     [hw_cv_func_snprintf_c99=no])
171   AS_IF([test "$hw_cv_func_snprintf_c99" = yes],
172     [AC_DEFINE([HAVE_SNPRINTF], [1],
173       [Define to 1 if you have a C99 compliant `snprintf' function.])],
174     [AC_DEFINE([snprintf], [rpl_snprintf],
175       [Define to rpl_snprintf if the replacement function should be used.])
176     _HW_FUNC_XPRINTF_REPLACE])
177 ])# HW_FUNC_SNPRINTF
178
179 # HW_FUNC_VASPRINTF
180 # -----------------
181 # Set $hw_cv_func_vasprintf to "yes" or "no".  Define HAVE_VASPRINTF to 1 if
182 # $hw_cv_func_vasprintf is set to "yes".  Otherwise, define vasprintf to
183 # rpl_vasprintf and make sure the replacement function will be built.
184 AC_DEFUN([HW_FUNC_VASPRINTF],
185 [
186   AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our vasprintf(3) calls vsnprintf(3).
187   AC_CHECK_FUNCS([vasprintf],
188     [hw_cv_func_vasprintf=yes],
189     [hw_cv_func_vasprintf=no])
190   AS_IF([test "$hw_cv_func_vasprintf" = no],
191     [AC_DEFINE([vasprintf], [rpl_vasprintf],
192       [Define to rpl_vasprintf if the replacement function should be used.])
193     AC_CHECK_HEADERS([stdlib.h])
194     HW_FUNC_VA_COPY
195     AS_IF([test "$hw_cv_func_va_copy" = no],
196       [HW_FUNC___VA_COPY])
197     _HW_FUNC_XPRINTF_REPLACE])
198 ])# HW_FUNC_VASPRINTF
199
200 # HW_FUNC_ASPRINTF
201 # ----------------
202 # Set $hw_cv_func_asprintf to "yes" or "no".  Define HAVE_ASPRINTF to 1 if
203 # $hw_cv_func_asprintf is set to "yes".  Otherwise, define asprintf to
204 # rpl_asprintf and make sure the replacement function will be built.
205 AC_DEFUN([HW_FUNC_ASPRINTF],
206 [
207   AC_REQUIRE([HW_FUNC_VASPRINTF])dnl Our asprintf(3) calls vasprintf(3).
208   AC_CHECK_FUNCS([asprintf],
209     [hw_cv_func_asprintf=yes],
210     [hw_cv_func_asprintf=no])
211   AS_IF([test "$hw_cv_func_asprintf" = no],
212     [AC_DEFINE([asprintf], [rpl_asprintf],
213       [Define to rpl_asprintf if the replacement function should be used.])
214     _HW_FUNC_XPRINTF_REPLACE])
215 ])# HW_FUNC_ASPRINTF
216
217 # _HW_FUNC_XPRINTF_REPLACE
218 # ------------------------
219 # Arrange for building snprintf.c.  Must be called if one or more of the
220 # functions provided by snprintf.c are needed.
221 AC_DEFUN([_HW_FUNC_XPRINTF_REPLACE],
222 [
223   AS_IF([test "x$_hw_cv_func_xprintf_replace_done" != xyes],
224     [AC_C_CONST
225     HW_HEADER_STDARG_H
226     AC_LIBOBJ([snprintf])
227     _hw_cv_func_xprintf_replace_done=yes])
228 ])# _HW_FUNC_XPRINTF_REPLACE
229
230 dnl vim: set joinspaces textwidth=80: