xref: /netbsd-src/external/gpl3/gcc/dist/libssp/snprintf-chk.c (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg /* Checking snprintf.
2*b1e83836Smrg    Copyright (C) 2005-2022 Free Software Foundation, Inc.
34fee23f9Smrg 
44fee23f9Smrg This file is part of GCC.
54fee23f9Smrg 
64fee23f9Smrg GCC is free software; you can redistribute it and/or modify it under
74fee23f9Smrg the terms of the GNU General Public License as published by the Free
84fee23f9Smrg Software Foundation; either version 3, or (at your option) any later
94fee23f9Smrg version.
104fee23f9Smrg 
114fee23f9Smrg In addition to the permissions in the GNU General Public License, the
124fee23f9Smrg Free Software Foundation gives you unlimited permission to link the
134fee23f9Smrg compiled version of this file into combinations with other programs,
144fee23f9Smrg and to distribute those combinations without any restriction coming
154fee23f9Smrg from the use of this file.  (The General Public License restrictions
164fee23f9Smrg do apply in other respects; for example, they cover modification of
174fee23f9Smrg the file, and distribution when not linked into a combine
184fee23f9Smrg executable.)
194fee23f9Smrg 
204fee23f9Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
214fee23f9Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
224fee23f9Smrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
234fee23f9Smrg for more details.
244fee23f9Smrg 
254fee23f9Smrg Under Section 7 of GPL version 3, you are granted additional
264fee23f9Smrg permissions described in the GCC Runtime Library Exception, version
274fee23f9Smrg 3.1, as published by the Free Software Foundation.
284fee23f9Smrg 
294fee23f9Smrg You should have received a copy of the GNU General Public License and
304fee23f9Smrg a copy of the GCC Runtime Library Exception along with this program;
314fee23f9Smrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
324fee23f9Smrg <http://www.gnu.org/licenses/>.  */
334fee23f9Smrg 
344fee23f9Smrg 
354fee23f9Smrg #include "config.h"
364fee23f9Smrg #include <ssp/ssp.h>
374fee23f9Smrg #include <stdarg.h>
384fee23f9Smrg #ifdef HAVE_STDIO_H
394fee23f9Smrg # include <stdio.h>
404fee23f9Smrg #endif
414fee23f9Smrg 
424fee23f9Smrg extern void __chk_fail (void) __attribute__((__noreturn__));
434fee23f9Smrg 
444fee23f9Smrg #ifdef HAVE_USABLE_VSNPRINTF
454fee23f9Smrg int
__snprintf_chk(char * s,size_t n,int flags,size_t slen,const char * format,...)464fee23f9Smrg __snprintf_chk (char *s, size_t n, int flags __attribute__((unused)),
474fee23f9Smrg 		size_t slen, const char *format, ...)
484fee23f9Smrg {
494fee23f9Smrg   va_list arg;
504fee23f9Smrg   int done;
514fee23f9Smrg 
524fee23f9Smrg   if (n > slen)
534fee23f9Smrg     __chk_fail ();
544fee23f9Smrg 
554fee23f9Smrg   va_start (arg, format);
564fee23f9Smrg   done = vsnprintf (s, n, format, arg);
574fee23f9Smrg   va_end (arg);
584fee23f9Smrg 
594fee23f9Smrg   return done;
604fee23f9Smrg }
614fee23f9Smrg #endif
62