source: valtobtest/subversion-1.6.2/contrib/server-side/svnstsw/conf/stsw_func_snprintf_broken.m4 @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

File size: 4.3 KB
Line 
1# -*- Autoconf -*-
2
3# Copyright (c) 2008 BBN Technologies Corp.  All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13# 3. Neither the name of BBN Technologies nor the names of its contributors
14#    may be used to endorse or promote products derived from this software
15#    without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY BBN TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL BBN TECHNOLOGIES OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28
29
30# Sets the shell variable snprintf_broken to "yes" if the snprintf()
31# function is broken.
32
33# increment the serial number any time this file is changed
34# serial 0
35AC_DEFUN([STSW_FUNC_SNPRINTF_BROKEN],
36    [
37        stsw_enable_snprintf_tests=yes
38        AC_ARG_ENABLE(
39            [snprintf-tests],
40            [AS_HELP_STRING(
41                [--disable-snprintf-tests],
42
43                [Do not test whether the return value of snprintf()
44                 conforms to the C99 standard.  Use only if you are
45                 cross-compiling and you are sure that your snprintf()
46                 conforms to the C99 standard.])],
47
48            [
49                if test "x$enableval" = "xno" ; then
50                    stsw_enable_snprintf_tests=no
51                fi
52            ])
53        AC_MSG_CHECKING([whether snprintf tests should be run])
54        AC_MSG_RESULT([$stsw_enable_snprintf_tests])
55
56        snprintf_broken=no
57        if test "x$stsw_enable_snprintf_tests" = "xyes" ; then
58            AC_CACHE_CHECK(
59                [if snprintf is broken],
60                [stsw_cv_func_snprintf_broken],
61                [
62                    AC_LANG_PUSH([C])
63                    AC_RUN_IFELSE(
64                        [AC_LANG_PROGRAM(
65                            [[
66                                #include <stdio.h>
67                                #include <string.h>
68                            ]],
69                            [[
70                                char buf[32];
71                                const char* teststr = "0123456789ABCDEF";
72                                memset(buf, 1, sizeof(buf));
73                                if (snprintf(buf, 8, "%s", teststr) != 16)
74                                    return 1;
75                                if (buf[7] != '\0')
76                                    return 1;
77                                if (snprintf(buf, sizeof(buf), "%s", teststr) != 16)
78                                    return 1;
79                                return 0;
80                            ]])],
81                        [
82                            # action if true
83                            stsw_cv_func_snprintf_broken=no
84                        ],
85                        [
86                            # action if false
87                            stsw_cv_func_snprintf_broken=yes
88                        ],
89                        [
90                            # action if cross-compiling
91                            AC_MSG_ERROR([Unable to test if snprintf() is broken when cross-compiling.  Manually check snprintf() and use --disable-snprintf-tests if appropriate.])
92                        ])
93                    AC_LANG_POP([C])
94                ])
95            if test "x$stsw_cv_func_snprintf_broken" = "xyes" ; then
96                snprintf_broken=yes
97            fi
98        fi
99    ])
Note: See TracBrowser for help on using the repository browser.