1254721Semaste/* Checking snprintf.
2254721Semaste   Copyright (C) 2005 Free Software Foundation, Inc.
3254721Semaste
4254721SemasteThis file is part of GCC.
5254721Semaste
6254721SemasteGCC is free software; you can redistribute it and/or modify it under
7254721Semastethe terms of the GNU General Public License as published by the Free
8254721SemasteSoftware Foundation; either version 2, or (at your option) any later
9254721Semasteversion.
10254721Semaste
11254721SemasteIn addition to the permissions in the GNU General Public License, the
12254721SemasteFree Software Foundation gives you unlimited permission to link the
13254721Semastecompiled version of this file into combinations with other programs,
14254721Semasteand to distribute those combinations without any restriction coming
15254721Semastefrom the use of this file.  (The General Public License restrictions
16254721Semastedo apply in other respects; for example, they cover modification of
17254721Semastethe file, and distribution when not linked into a combine
18254721Semasteexecutable.)
19254721Semaste
20254721SemasteGCC is distributed in the hope that it will be useful, but WITHOUT ANY
21254721SemasteWARRANTY; without even the implied warranty of MERCHANTABILITY or
22254721SemasteFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23254721Semastefor more details.
24254721Semaste
25254721SemasteYou should have received a copy of the GNU General Public License
26254721Semastealong with GCC; see the file COPYING.  If not, write to the Free
27254721SemasteSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28254721Semaste02110-1301, USA.  */
29254721Semaste
30254721Semaste/* As a special exception, if you link this library with files compiled with
31254721Semaste   GCC to produce an executable, this does not cause the resulting executable
32254721Semaste   to be covered by the GNU General Public License. This exception does not
33254721Semaste   however invalidate any other reasons why the executable file might be
34254721Semaste   covered by the GNU General Public License.  */
35254721Semaste
36254721Semaste#include "config.h"
37254721Semaste#include <ssp/ssp.h>
38254721Semaste#include <stdarg.h>
39254721Semaste#ifdef HAVE_STDIO_H
40254721Semaste# include <stdio.h>
41254721Semaste#endif
42254721Semaste
43254721Semasteextern void __chk_fail (void) __attribute__((__noreturn__));
44254721Semaste
45254721Semaste#ifdef HAVE_USABLE_VSNPRINTF
46254721Semasteint
47254721Semaste__snprintf_chk (char *s, size_t n, int flags __attribute__((unused)),
48254721Semaste		size_t slen, const char *format, ...)
49254721Semaste{
50254721Semaste  va_list arg;
51254721Semaste  int done;
52254721Semaste
53254721Semaste  if (n > slen)
54254721Semaste    __chk_fail ();
55254721Semaste
56254721Semaste  va_start (arg, format);
57254721Semaste  done = vsnprintf (s, n, format, arg);
58254721Semaste  va_end (arg);
59254721Semaste
60254721Semaste  return done;
61254721Semaste}
62254721Semaste#endif
63254721Semaste