File: ac_func_snprintf.m4

package info (click to toggle)
sagasu 2.0.10-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,532 kB
  • ctags: 1,064
  • sloc: ansic: 6,198; sh: 4,475; cpp: 1,831; makefile: 412; yacc: 316; perl: 144; sed: 16
file content (29 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
dnl  Checks for a fully C99 compliant snprintf

AC_DEFUN([AC_FUNC_SNPRINTF],
[AC_CHECK_FUNCS(snprintf vsnprintf)
AC_MSG_CHECKING(for working snprintf)
AC_CACHE_VAL(ac_cv_have_working_snprintf,
[AC_TRY_RUN(
[#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
    char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
    int i;
    i = snprintf (bufs, 2, "%s", "111");
    if (strcmp (bufs, "1")) exit (1);
    if (i != 3) exit (1);
    i = snprintf (bufd, 2, "%d", 111);
    if (strcmp (bufd, "1")) exit (1);
    if (i != 3) exit (1);
    exit(0);
}], ac_cv_have_working_snprintf=yes, ac_cv_have_working_snprintf=no, ac_cv_have_working_snprintf=cross)])
AC_MSG_RESULT([$ac_cv_have_working_snprintf])

if test x$ac_cv_have_working_snprintf != "xyes"; then
	AC_MSG_ERROR([this program requires the snprintf(3) function.])
fi])