File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / m4 / ax_func_snprintf.m4
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 16:12:54 2014 UTC (10 years, 1 month ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_10p3_0, v1_8_10p3, HEAD
sudo v 1.8.10p3

    1: # ===========================================================================
    2: #     http://www.gnu.org/software/autoconf-archive/ax_func_snprintf.html
    3: # ===========================================================================
    4: #
    5: # SYNOPSIS
    6: #
    7: #   AX_FUNC_SNPRINTF
    8: #
    9: # DESCRIPTION
   10: #
   11: #   Checks for a fully C99 compliant snprintf, in particular checks whether
   12: #   it does bounds checking and returns the correct string length; does the
   13: #   same check for vsnprintf. If no working snprintf or vsnprintf is found,
   14: #   request a replacement and warn the user about it. Note: the mentioned
   15: #   replacement is freely available and may be used in any project
   16: #   regardless of it's license.
   17: #
   18: # LICENSE
   19: #
   20: #   Copyright (c) 2008 Ruediger Kuhlmann <info@ruediger-kuhlmann.de>
   21: #
   22: #   Copying and distribution of this file, with or without modification, are
   23: #   permitted in any medium without royalty provided the copyright notice
   24: #   and this notice are preserved. This file is offered as-is, without any
   25: #   warranty.
   26: 
   27: #serial 5
   28: 
   29: AC_DEFUN([AX_FUNC_SNPRINTF],
   30: [AC_CHECK_FUNCS(snprintf vsnprintf)
   31: AC_MSG_CHECKING(for working snprintf)
   32: AC_CACHE_VAL(ac_cv_have_working_snprintf,
   33: [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
   34: 
   35: int main(void)
   36: {
   37:     char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
   38:     char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
   39:     int i;
   40:     i = snprintf (bufs, 2, "%s", "111");
   41:     if (strcmp (bufs, "1")) exit (1);
   42:     if (i != 3) exit (1);
   43:     i = snprintf (bufd, 2, "%d", 111);
   44:     if (strcmp (bufd, "1")) exit (1);
   45:     if (i != 3) exit (1);
   46:     exit(0);
   47: }]])],[ac_cv_have_working_snprintf=yes],[ac_cv_have_working_snprintf=no],[ac_cv_have_working_snprintf=cross])])
   48: AC_MSG_RESULT([$ac_cv_have_working_snprintf])
   49: AC_MSG_CHECKING(for working vsnprintf)
   50: AC_CACHE_VAL(ac_cv_have_working_vsnprintf,
   51: [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
   52: #include <stdarg.h>
   53: 
   54: int my_vsnprintf (char *buf, const char *tmpl, ...)
   55: {
   56:     int i;
   57:     va_list args;
   58:     va_start (args, tmpl);
   59:     i = vsnprintf (buf, 2, tmpl, args);
   60:     va_end (args);
   61:     return i;
   62: }
   63: 
   64: int main(void)
   65: {
   66:     char bufs[5] = { 'x', 'x', 'x', '\0', '\0' };
   67:     char bufd[5] = { 'x', 'x', 'x', '\0', '\0' };
   68:     int i;
   69:     i = my_vsnprintf (bufs, "%s", "111");
   70:     if (strcmp (bufs, "1")) exit (1);
   71:     if (i != 3) exit (1);
   72:     i = my_vsnprintf (bufd, "%d", 111);
   73:     if (strcmp (bufd, "1")) exit (1);
   74:     if (i != 3) exit (1);
   75:     exit(0);
   76: }]])],[ac_cv_have_working_vsnprintf=yes],[ac_cv_have_working_vsnprintf=no],[ac_cv_have_working_vsnprintf=cross])])
   77: AC_MSG_RESULT([$ac_cv_have_working_vsnprintf])
   78: if test x$ac_cv_have_working_snprintf$ac_cv_have_working_vsnprintf != "xyesyes"; then
   79:   AC_LIBOBJ(snprintf)
   80:   AC_MSG_WARN([Replacing missing/broken (v)snprintf() with sudo's version.])
   81:   AC_DEFINE(PREFER_PORTABLE_SNPRINTF, 1, [Enable replacement (v)snprintf if system (v)snprintf is broken.])
   82: fi])

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>