Fix two bugs related to command execution:
[dockapps.git] / wmweather+ / m4 / snprintf.m4
blob03567bc5931ecf3327306fc3eb775aa540d22544
1 # FUNC_SNPRINTF_EXISTS
2 # --------------------
3 # Checks if snprintf exists. x_cv_func_snprintf_exists is set.
4 AC_DEFUN([FUNC_SNPRINTF_EXISTS],
5 [AC_CHECK_FUNC(snprintf, [x_cv_func_snprintf_exists=yes], [x_cv_func_snprintf_exists=no])])# FUNC_SNPRINTF_EXISTS
7 # FUNC_SNPRINTF_SIZE
8 # ------------------
9 # Checks if snprintf honors its size argument. SNPRINTF_IS_SPRINTF is defined
10 # if not. x_cv_func_snprintf_size is set to yes or no.
12 # Note that this depends on FUNC_SNPRINTF_EXISTS, so if that fails this will
13 # also fail (and define SNPRINTF_IS_SPRINTF).
14 AC_DEFUN([FUNC_SNPRINTF_SIZE],
15 [AC_REQUIRE([FUNC_SNPRINTF_EXISTS])
16 if test $x_cv_func_snprintf_exists != yes; then x_cv_func_snprintf_size=no; else
17 AC_CACHE_CHECK([if snprintf honors the size argument], x_cv_func_snprintf_size,
18 [AC_RUN_IFELSE(
19 [AC_LANG_PROGRAM(
20 [[#if STDC_HEADERS || HAVE_STDIO_H
21 # include <stdio.h>
22 #else
23 int snprintf(char *str, size_t size, const char *format, ...);
24 #endif
25 ]],
26 [[char foo[]="ABC"; snprintf(foo, 2, "%d", 12);
27 exit((foo[0]=='1' && foo[1]=='\0' && foo[2]=='C')?0:1);]])],
28 [x_cv_func_snprintf_size=yes],
29 [x_cv_func_snprintf_size=no],
30 [x_cv_func_snprintf_size=no])])
32 test $x_cv_func_snprintf_size != yes && AC_DEFINE(SNPRINTF_IS_SPRINTF, 1, [Define if snprintf ignores the size argument])
33 ])# FUNC_SNPRINTF_SIZE
35 # FUNC_SNPRINTF_RETVAL
36 # ------------------
37 # Checks if snprintf returns the number of bytes that would have been written,
38 # as specified by C99. SNPRINTF_BOGUS_RETVAL is defined if not.
39 # x_cv_func_snprintf_retval is set to yes or no.
41 # Note that this depends on FUNC_SNPRINTF_SIZE, so if that fails this will fail
42 # too and SNPRINTF_BOGUS_RETVAL will be set.
43 AC_DEFUN([FUNC_SNPRINTF_RETVAL],
44 [AC_REQUIRE([FUNC_SNPRINTF_SIZE])
45 if test $x_cv_func_snprintf_size != yes; then x_cv_func_snprintf_retval=no; else
46 AC_CACHE_CHECK([if snprintf return value is sane], x_cv_func_snprintf_retval,
47 [AC_RUN_IFELSE(
48 [AC_LANG_PROGRAM(
49 [[#if STDC_HEADERS || HAVE_STDIO_H
50 # include <stdio.h>
51 #else
52 int snprintf(char *str, size_t size, const char *format, ...);
53 #endif
54 ]],
55 [[char foo[10]; exit((snprintf(foo, 1, "%d", 9876)==4)?0:1);]])],
56 [x_cv_func_snprintf_retval=yes],
57 [x_cv_func_snprintf_retval=no],
58 [x_cv_func_snprintf_retval=no])])
60 test $x_cv_func_snprintf_retval != yes && AC_DEFINE(SNPRINTF_BOGUS_RETVAL, 1, [Define if snprintf's return value isn't as specified by C99])
61 ])# FUNC_SNPRINTF_RETVAL
63 # FUNC_SNPRINTF_NULL_OK
64 # ---------------------
65 # Checks whether snprintf acceps a NULL string if size is zero. Sets
66 # x_cv_func_snprintf_null_ok. If so, define SNPRINTF_NULL_OK.
68 # Note that this depends on FUNC_SNPRINTF_SIZE, so if that fails this will fail
69 # too and SNPRINTF_BOGUS_RETVAL will be set.
70 AC_DEFUN([FUNC_SNPRINTF_NULL_OK],
71 [AC_REQUIRE([FUNC_SNPRINTF_SIZE])
72 if test $x_cv_func_snprintf_size != yes; then x_cv_func_snprintf_null_ok=no; else
73 AC_CACHE_CHECK([if snprintf(NULL, 0, ...) works], x_cv_func_snprintf_null_ok,
74 [AC_RUN_IFELSE(
75 [AC_LANG_PROGRAM(
76 [[#if STDC_HEADERS || HAVE_STDIO_H
77 # include <stdio.h>
78 #else
79 int snprintf(char *str, size_t size, const char *format, ...);
80 #endif
81 ]],
82 [int r=snprintf(NULL, 0, "%d", 100); exit((r==3 || r==-1)?0:1);])],
83 [x_cv_func_snprintf_null_ok=yes],
84 [x_cv_func_snprintf_null_ok=no],
85 [x_cv_func_snprintf_null_ok=no])])
87 test $x_cv_func_snprintf_null_ok = yes && AC_DEFINE(SNPRINTF_NULL_OK, 1, [Define if snprintf(NULL, 0, ...) works properly])
88 ])# FUNC_SNPRINTF_NULL_OK
90 # FUNC_SNPRINTF([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
91 # -------------
92 # Checks various aspects of snprintf. In particular:
93 #  * Does it exist?
94 #  * Is the size honored?
95 #  * Is the return value correct?
96 #  * Is NULL with length 0 ok?
97 # If all the above pass, HAVE_WORKING_SNPRINTF is defined and
98 # x_cv_func_snprintf_working is set to yes. Otherwise, it's set to no.
99 AC_DEFUN([FUNC_SNPRINTF],
100 [AC_REQUIRE([FUNC_SNPRINTF_RETVAL])
101 AC_REQUIRE([FUNC_SNPRINTF_NULL_OK])
102 if test $x_cv_func_snprintf_retval = yes -a $x_cv_func_snprintf_null_ok = yes; then
103     AC_DEFINE(HAVE_WORKING_SNPRINTF, 1, [Define if snprintf works properly])
104     x_cv_func_snprintf_working=yes
105     $1
106 else
107     x_cv_func_snprintf_working=no
108     $2
110 ])# FUNC_SNPRINTF
112 # FUNC_SNPRINTF_LIBOBJ
113 # --------------------
114 # If FUNC_SNPRINTF fails, does AC_LIBOBJ
115 AC_DEFUN([FUNC_SNPRINTF_LIBOBJ],
116 [FUNC_SNPRINTF(, [AC_LIBOBJ([snprintf])
117 AC_DEFINE([snprintf], [rpl_snprintf], [Define to rpl_snprintf if the replacement function should be used.])])])
118 ])#FUNC_SNPRINTF_LIBOBJ