1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
"http://www.w3.org/TR/html4/strict.dtd">
6
<title>Autoconf Macro: ac_func_snprintf</title>
7
<link rel="stylesheet" type="text/css" href="ac-archive.css">
11
<table summary="web navigation" style="width:100%;">
14
<td style="width:50%;" align="center">[<a href="index.html">Macro Index
17
<td style="width:50%;" align="center">[<a href=
18
"../m4source/ac_func_snprintf.m4">Download M4 Source</a>]</td>
24
<h1>ac_func_snprintf</h1>
29
<p style="text-align:left; white-space:nowrap;">
30
<code>AC_FUNC_SNPRINTF</code></p>
36
<p>Checks for a fully C99 compliant snprintf, in particular checks whether
37
it does bounds checking and returns the correct string length; does the
38
same check for vsnprintf. If no working snprintf or vsnprintf is found,
39
request a replacement and warn the user about it. Note: the mentioned
40
replacement is freely available and may be used in any project regardless
41
of it's licence (just like the autoconf special exemption).</p>
47
<p>1.4 (last modified: 2002-09-26)</p>
53
<p>R�diger Kuhlmann <info@ruediger-kuhlmann.de></p>
56
<h2>M4 Source Code</h2>
59
<pre class="m4source">
60
AC_DEFUN([AC_FUNC_SNPRINTF],
61
[AC_CHECK_FUNCS(snprintf vsnprintf)
62
AC_MSG_CHECKING(for working snprintf)
63
AC_CACHE_VAL(ac_cv_have_working_snprintf,
65
[#include <stdio.h>
69
char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
70
char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
72
i = snprintf (bufs, 2, "%s", "111");
73
if (strcmp (bufs, "1")) exit (1);
75
i = snprintf (bufd, 2, "%d", 111);
76
if (strcmp (bufd, "1")) exit (1);
79
}], ac_cv_have_working_snprintf=yes, ac_cv_have_working_snprintf=no, ac_cv_have_working_snprintf=cross)])
80
AC_MSG_RESULT([$ac_cv_have_working_snprintf])
81
AC_MSG_CHECKING(for working vsnprintf)
82
AC_CACHE_VAL(ac_cv_have_working_vsnprintf,
84
[#include <stdio.h>
85
#include <stdarg.h>
87
int my_vsnprintf (char *buf, const char *tmpl, ...)
91
va_start (args, tmpl);
92
i = vsnprintf (buf, 2, tmpl, args);
99
char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
100
char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
102
i = my_vsnprintf (bufs, "%s", "111");
103
if (strcmp (bufs, "1")) exit (1);
104
if (i != 3) exit (1);
105
i = my_vsnprintf (bufd, "%d", 111);
106
if (strcmp (bufd, "1")) exit (1);
107
if (i != 3) exit (1);
109
}], ac_cv_have_working_vsnprintf=yes, ac_cv_have_working_vsnprintf=no, ac_cv_have_working_vsnprintf=cross)])
110
AC_MSG_RESULT([$ac_cv_have_working_vsnprintf])
111
if test x$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf != "xyesyes"; then
113
AC_MSG_WARN([Replacing missing/broken (v)snprintf() with version from http://www.ijs.si/software/snprintf/.])
114
AC_DEFINE(PREFER_PORTABLE_SNPRINTF, 1, "enable replacement (v)snprintf if system (v)snprintf is broken")
122
<a href="COPYING.html">GNU General Public License</a> with this special
123
<a href="COPYING-Exception.html">exception</a>.