source: web/old/remctl-2.14/m4/snprintf.m4 @ f6f3e91

web
Last change on this file since f6f3e91 was f6f3e91, checked in by Jessica B. Hamrick <jhamrick@…>, 15 years ago

Preserve directory hierarchy (not sure what happened to it)

  • Property mode set to 100644
File size: 1.7 KB
Line 
1dnl Test for a working C99 snprintf.
2dnl
3dnl Check for a working snprintf.  Some systems have an snprintf that doesn't
4dnl nul-terminate if the buffer isn't large enough.  Others return -1 if the
5dnl string doesn't fit into the buffer instead of returning the number of
6dnl characters that would have been formatted.  Still others don't support
7dnl NULL as the buffer argument (just to get a count of the formatted length).
8dnl
9dnl Provides RRA_FUNC_SNPRINTF, which adds snprintf.o to LIBOBJS unless a
10dnl fully working snprintf is found.
11dnl
12dnl Written by Russ Allbery <rra@stanford.edu>
13dnl Copyright 2006, 2008, 2009
14dnl     Board of Trustees, Leland Stanford Jr. University
15dnl
16dnl See LICENSE for licensing terms.
17
18dnl Source used by RRA_FUNC_SNPRINTF.
19AC_DEFUN([_RRA_FUNC_SNPRINTF_SOURCE], [[
20#include <stdio.h>
21#include <stdarg.h>
22
23char buf[2];
24
25int
26test(char *format, ...)
27{
28    va_list args;
29    int count;
30
31    va_start(args, format);
32    count = vsnprintf(buf, sizeof buf, format, args);
33    va_end(args);
34    return count;
35}
36
37int
38main()
39{
40    return ((test("%s", "abcd") == 4 && buf[0] == 'a' && buf[1] == '\0'
41             && snprintf(NULL, 0, "%s", "abcd") == 4) ? 0 : 1);
42}
43]])
44
45dnl The user-callable test.
46AC_DEFUN([RRA_FUNC_SNPRINTF],
47[AC_CACHE_CHECK([for working snprintf], [rra_cv_func_snprintf_works],
48    [AC_RUN_IFELSE([AC_LANG_SOURCE([_RRA_FUNC_SNPRINTF_SOURCE])],
49        [rra_cv_func_snprintf_works=yes],
50        [rra_cv_func_snprintf_works=no],
51        [rra_cv_func_snprintf_works=no])])
52 AS_IF([test "$rra_cv_func_snprintf_works" = yes],
53    [AC_DEFINE([HAVE_SNPRINTF], 1,
54        [Define if your system has a working snprintf function.])],
55    [AC_LIBOBJ([snprintf])])])
Note: See TracBrowser for help on using the repository browser.