Guard against vsnprintf implementations that mishandle a size=0 argument.
[gnulib.git] / m4 / vsnprintf-posix.m4
1 # vsnprintf-posix.m4 serial 4
2 dnl Copyright (C) 2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
8 [
9   AC_REQUIRE([gl_EOVERFLOW])
10   AC_REQUIRE([gl_PRINTF_SIZES_C99])
11   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
12   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
13   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
14   AC_REQUIRE([gl_PRINTF_POSITIONS])
15   gl_cv_func_vsnprintf_posix=no
16   AC_CHECK_FUNCS([vsnprintf])
17   if test $ac_cv_func_vsnprintf = yes; then
18     dnl Assume that if vsnprintf() exists, snprintf() also exists.
19     gl_SNPRINTF_TRUNCATION_C99
20     gl_SNPRINTF_RETVAL_C99
21     gl_SNPRINTF_DIRECTIVE_N
22     gl_VSNPRINTF_ZEROSIZE_C99
23     case "$gl_cv_func_printf_sizes_c99" in
24       *yes)
25         case "$gl_cv_func_printf_directive_a" in
26           *yes)
27             case "$gl_cv_func_printf_directive_f" in
28               *yes)
29                 case "$gl_cv_func_printf_directive_n" in
30                   *yes)
31                     case "$gl_cv_func_printf_positions" in
32                       *yes)
33                         case "$gl_cv_func_snprintf_truncation_c99" in
34                           *yes)
35                             case "$gl_cv_func_snprintf_retval_c99" in
36                               *yes)
37                                 case "$gl_cv_func_snprintf_directive_n" in
38                                   *yes)
39                                     case "$gl_cv_func_vsnprintf_zerosize_c99" in
40                                       *yes)
41                                         # vsnprintf exists and is already POSIX
42                                         # compliant.
43                                         gl_cv_func_vsnprintf_posix=yes
44                                         ;;
45                                     esac
46                                     ;;
47                                 esac
48                                 ;;
49                             esac
50                             ;;
51                         esac
52                         ;;
53                     esac
54                     ;;
55                 esac
56                 ;;
57             esac
58             ;;
59         esac
60         ;;
61     esac
62   fi
63   if test $gl_cv_func_vsnprintf_posix = no; then
64     gl_PREREQ_VASNPRINTF_DIRECTIVE_A
65     gl_PREREQ_VASNPRINTF_DIRECTIVE_F
66     gl_REPLACE_VASNPRINTF
67     gl_REPLACE_VSNPRINTF
68   fi
69 ])