xref: /netbsd-src/external/gpl3/gcc.old/dist/libssp/strncpy-chk.c (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg /* Checking strncpy.
2*8feb0f0bSmrg    Copyright (C) 2005-2020 Free Software Foundation, Inc.
336ac495dSmrg 
436ac495dSmrg This file is part of GCC.
536ac495dSmrg 
636ac495dSmrg GCC is free software; you can redistribute it and/or modify it under
736ac495dSmrg the terms of the GNU General Public License as published by the Free
836ac495dSmrg Software Foundation; either version 3, or (at your option) any later
936ac495dSmrg version.
1036ac495dSmrg 
1136ac495dSmrg In addition to the permissions in the GNU General Public License, the
1236ac495dSmrg Free Software Foundation gives you unlimited permission to link the
1336ac495dSmrg compiled version of this file into combinations with other programs,
1436ac495dSmrg and to distribute those combinations without any restriction coming
1536ac495dSmrg from the use of this file.  (The General Public License restrictions
1636ac495dSmrg do apply in other respects; for example, they cover modification of
1736ac495dSmrg the file, and distribution when not linked into a combine
1836ac495dSmrg executable.)
1936ac495dSmrg 
2036ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
2136ac495dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
2236ac495dSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2336ac495dSmrg for more details.
2436ac495dSmrg 
2536ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
2636ac495dSmrg permissions described in the GCC Runtime Library Exception, version
2736ac495dSmrg 3.1, as published by the Free Software Foundation.
2836ac495dSmrg 
2936ac495dSmrg You should have received a copy of the GNU General Public License and
3036ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
3136ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
3236ac495dSmrg <http://www.gnu.org/licenses/>.  */
3336ac495dSmrg 
3436ac495dSmrg #include "config.h"
3536ac495dSmrg #include <ssp/ssp.h>
3636ac495dSmrg #ifdef HAVE_STRING_H
3736ac495dSmrg # include <string.h>
3836ac495dSmrg #endif
3936ac495dSmrg 
4036ac495dSmrg extern void __chk_fail (void) __attribute__((__noreturn__));
4136ac495dSmrg 
4236ac495dSmrg #ifdef HAVE_STRNCPY
4336ac495dSmrg char *
__strncpy_chk(char * __restrict__ dest,const char * __restrict__ src,size_t len,size_t slen)4436ac495dSmrg __strncpy_chk (char *__restrict__ dest, const char *__restrict__ src,
4536ac495dSmrg                size_t len, size_t slen)
4636ac495dSmrg {
4736ac495dSmrg   if (len > slen)
4836ac495dSmrg     __chk_fail ();
4936ac495dSmrg   return strncpy (dest, src, len);
5036ac495dSmrg }
5136ac495dSmrg #endif
52