~ubuntu-branches/ubuntu/hoary/wmweather+/hoary

« back to all changes in this revision

Viewing changes to m4/vsnprintf.m4

  • Committer: Bazaar Package Importer
  • Author(s): Martin Stigge
  • Date: 2004-01-24 00:32:54 UTC
  • Revision ID: james.westby@ubuntu.com-20040124003254-w0zfa0s27evqfcds
Tags: upstream-2.5
ImportĀ upstreamĀ versionĀ 2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# FUNC_VSNPRINTF_EXISTS
 
2
# --------------------
 
3
# Checks if vsnprintf exists. 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 cv_func_vsnprintf_exists=no; else
 
7
AC_CHECK_FUNC(vsnprintf, [cv_func_vsnprintf_exists=yes], [cv_func_vsnprintf_exists=no])
 
8
fi
 
9
])# FUNC_VSNPRINTF_EXISTS
 
10
 
 
11
# FUNC_VSNPRINTF_SIZE
 
12
# ------------------
 
13
# Checks if vsnprintf honors its size argument. VSNPRINTF_IS_VSPRINTF is defined
 
14
# if not. cv_func_vsnprintf_size is set to yes or no.
 
15
#
 
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 $cv_func_vsnprintf_exists != yes; then cv_func_vsnprintf_size=no; else
 
21
AC_CACHE_CHECK([if vsnprintf honors the size argument], 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;
 
37
}
 
38
]],
 
39
[[char foo[]="ABC"; doit(foo, 2, "%d", 12);
 
40
exit((foo[0]=='1' && foo[1]=='\0' && foo[2]=='C')?0:1);]])],
 
41
[cv_func_vsnprintf_size=yes],
 
42
[cv_func_vsnprintf_size=no],
 
43
[cv_func_vsnprintf_size=no])])
 
44
fi
 
45
test $cv_func_vsnprintf_size != yes && AC_DEFINE(VSNPRINTF_IS_VSPRINTF, 1, [Define if vsnprintf ignores the size argument])
 
46
])# FUNC_VSNPRINTF_SIZE
 
47
 
 
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
# cv_func_vsnprintf_retval is set to yes or no.
 
53
#
 
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 $cv_func_vsnprintf_size != yes; then cv_func_vsnprintf_retval=no; else
 
59
AC_CACHE_CHECK([if vsnprintf return value is sane], 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;
 
75
}
 
76
]],
 
77
[[char foo[10]; exit((doit(foo, 1, "%d", 9876)==4)?0:1);]])],
 
78
[cv_func_vsnprintf_retval=yes],
 
79
[cv_func_vsnprintf_retval=no],
 
80
[cv_func_vsnprintf_retval=no])])
 
81
fi
 
82
test $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
 
84
 
 
85
# FUNC_VSNPRINTF_NULL_OK
 
86
# ---------------------
 
87
# Checks whether vsnprintf acceps a NULL string if size is zero. Sets
 
88
# cv_func_vsnprintf_null_ok. If so, define VSNPRINTF_NULL_OK.
 
89
#
 
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 $cv_func_vsnprintf_size != yes; then cv_func_vsnprintf_null_ok=no; else
 
95
AC_CACHE_CHECK([if vsnprintf(NULL, 0, ...) works], 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;
 
111
}
 
112
]],
 
113
[int r=doit(NULL, 0, "%d", 100); exit((r==3 || r==-1)?0:1);])],
 
114
[cv_func_vsnprintf_null_ok=yes],
 
115
[cv_func_vsnprintf_null_ok=no],
 
116
[cv_func_vsnprintf_null_ok=no])])
 
117
fi
 
118
test $cv_func_vsnprintf_null_ok = yes && AC_DEFINE(VSNPRINTF_NULL_OK, 1, [Define if vsnprintf(NULL, 0, ...) works properly])
 
119
])# FUNC_VSNPRINTF_NULL_OK
 
120
 
 
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
# 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 $cv_func_vsnprintf_retval = yes -a $cv_func_vsnprintf_null_ok = yes; then
 
134
    AC_DEFINE(HAVE_WORKING_VSNPRINTF, 1, [Define if vsnprintf works properly])
 
135
    cv_func_snprintf_working=yes
 
136
    $1
 
137
else
 
138
    cv_func_snprintf_working=no
 
139
    $2
 
140
fi
 
141
])# FUNC_VSNPRINTF
 
142
 
 
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
])#FUNC_VSNPRINTF_LIBOBJ