vsnprintf-chk.c revision 169695
1234285Sdim/* Checking vsnprintf.
2234285Sdim   Copyright (C) 2005 Free Software Foundation, Inc.
3234285Sdim
4234285SdimThis file is part of GCC.
5234285Sdim
6234285SdimGCC is free software; you can redistribute it and/or modify it under
7234285Sdimthe terms of the GNU General Public License as published by the Free
8234285SdimSoftware Foundation; either version 2, or (at your option) any later
9234285Sdimversion.
10234285Sdim
11234285SdimIn addition to the permissions in the GNU General Public License, the
12234285SdimFree Software Foundation gives you unlimited permission to link the
13234285Sdimcompiled version of this file into combinations with other programs,
14234285Sdimand to distribute those combinations without any restriction coming
15234285Sdimfrom the use of this file.  (The General Public License restrictions
16234285Sdimdo apply in other respects; for example, they cover modification of
17234285Sdimthe file, and distribution when not linked into a combine
18234285Sdimexecutable.)
19234285Sdim
20234285SdimGCC is distributed in the hope that it will be useful, but WITHOUT ANY
21234285SdimWARRANTY; without even the implied warranty of MERCHANTABILITY or
22234285SdimFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23234285Sdimfor more details.
24234285Sdim
25234285SdimYou should have received a copy of the GNU General Public License
26234285Sdimalong with GCC; see the file COPYING.  If not, write to the Free
27234285SdimSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28234285Sdim02110-1301, USA.  */
29234285Sdim
30234285Sdim/* As a special exception, if you link this library with files compiled with
31234285Sdim   GCC to produce an executable, this does not cause the resulting executable
32234285Sdim   to be covered by the GNU General Public License. This exception does not
33234285Sdim   however invalidate any other reasons why the executable file might be
34234285Sdim   covered by the GNU General Public License.  */
35234285Sdim
36234285Sdim#include "config.h"
37234285Sdim#include <ssp/ssp.h>
38234285Sdim#include <stdarg.h>
39243830Sdim#ifdef HAVE_STDIO_H
40243830Sdim# include <stdio.h>
41243830Sdim#endif
42251662Sdim
43251662Sdimextern void __chk_fail (void) __attribute__((__noreturn__));
44251662Sdim
45234285Sdim#ifdef HAVE_USABLE_VSNPRINTF
46234285Sdimint
47234285Sdim__vsnprintf_chk (char *s, size_t n, int flags __attribute__((unused)),
48234285Sdim		 size_t slen, const char *format, va_list arg)
49234285Sdim{
50234285Sdim  if (n > slen)
51234285Sdim    __chk_fail ();
52234285Sdim
53234285Sdim  return vsnprintf (s, n, format, arg);
54234285Sdim}
55#endif
56