~ubuntu-branches/ubuntu/hardy/autoconf-archive/hardy

« back to all changes in this revision

Viewing changes to htmldoc/ac_func_snprintf.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2004-06-26 09:43:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040626094357-3be3jwcz1vcdhpe8
Tags: upstream-20040616
Import upstream version 20040616

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
 
2
"http://www.w3.org/TR/html4/strict.dtd">
 
3
 
 
4
<html lang="en">
 
5
<head>
 
6
  <title>Autoconf Macro: ac_func_snprintf</title>
 
7
  <link rel="stylesheet" type="text/css" href="ac-archive.css">
 
8
</head>
 
9
 
 
10
<body>
 
11
  <table summary="web navigation" style="width:100%;">
 
12
    <tbody>
 
13
      <tr>
 
14
        <td style="width:50%;" align="center">[<a href="index.html">Macro Index
 
15
        Page</a>]</td>
 
16
 
 
17
        <td style="width:50%;" align="center">[<a href=
 
18
        "../m4source/ac_func_snprintf.m4">Download M4 Source</a>]</td>
 
19
      </tr>
 
20
    </tbody>
 
21
  </table>
 
22
  <hr>
 
23
 
 
24
  <h1>ac_func_snprintf</h1>
 
25
 
 
26
  <h2>Synopsis</h2>
 
27
 
 
28
  <div class="indent">
 
29
    <p style="text-align:left; white-space:nowrap;">
 
30
    <code>AC_FUNC_SNPRINTF</code></p>
 
31
  </div>
 
32
 
 
33
  <h2>Description</h2>
 
34
 
 
35
  <div class="indent">
 
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>
 
42
  </div>
 
43
 
 
44
  <h2>Version</h2>
 
45
 
 
46
  <div class="indent">
 
47
    <p>1.4 (last modified: 2002-09-26)</p>
 
48
  </div>
 
49
 
 
50
  <h2>Author</h2>
 
51
 
 
52
  <div class="indent">
 
53
    <p>R�diger Kuhlmann &lt;info@ruediger-kuhlmann.de&gt;</p>
 
54
  </div>
 
55
 
 
56
  <h2>M4 Source Code</h2>
 
57
 
 
58
  <div class="indent">
 
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,
 
64
[AC_TRY_RUN(
 
65
[#include &lt;stdio.h&gt;
 
66
 
 
67
int main(void)
 
68
{
 
69
    char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
 
70
    char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
 
71
    int i;
 
72
    i = snprintf (bufs, 2, "%s", "111");
 
73
    if (strcmp (bufs, "1")) exit (1);
 
74
    if (i != 3) exit (1);
 
75
    i = snprintf (bufd, 2, "%d", 111);
 
76
    if (strcmp (bufd, "1")) exit (1);
 
77
    if (i != 3) exit (1);
 
78
    exit(0);
 
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,
 
83
[AC_TRY_RUN(
 
84
[#include &lt;stdio.h&gt;
 
85
#include &lt;stdarg.h&gt;
 
86
 
 
87
int my_vsnprintf (char *buf, const char *tmpl, ...)
 
88
{
 
89
    int i;
 
90
    va_list args;
 
91
    va_start (args, tmpl);
 
92
    i = vsnprintf (buf, 2, tmpl, args);
 
93
    va_end (args);
 
94
    return i;
 
95
}
 
96
 
 
97
int main(void)
 
98
{
 
99
    char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
 
100
    char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
 
101
    int i;
 
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);
 
108
    exit(0);
 
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
 
112
  AC_LIBOBJ(snprintf)
 
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")
 
115
fi])
 
116
</pre>
 
117
  </div>
 
118
 
 
119
  <h2>Copyright</h2>
 
120
 
 
121
  <div class="indent">
 
122
    <a href="COPYING.html">GNU General Public License</a> with this special
 
123
    <a href="COPYING-Exception.html">exception</a>.
 
124
  </div>
 
125
</body>
 
126
</html>