strncpy-chk.c revision 169696
1285809Sscottl/* Checking strncpy.
2285809Sscottl   Copyright (C) 2005 Free Software Foundation, Inc.
3285809Sscottl
4285809SscottlThis file is part of GCC.
5285809Sscottl
6285809SscottlGCC is free software; you can redistribute it and/or modify it under
7285809Sscottlthe terms of the GNU General Public License as published by the Free
8285809SscottlSoftware Foundation; either version 2, or (at your option) any later
9285809Sscottlversion.
10285809Sscottl
11285809SscottlIn addition to the permissions in the GNU General Public License, the
12285809SscottlFree Software Foundation gives you unlimited permission to link the
13285809Sscottlcompiled version of this file into combinations with other programs,
14285809Sscottland to distribute those combinations without any restriction coming
15285809Sscottlfrom the use of this file.  (The General Public License restrictions
16285809Sscottldo apply in other respects; for example, they cover modification of
17285809Sscottlthe file, and distribution when not linked into a combine
18285809Sscottlexecutable.)
19285809Sscottl
20285809SscottlGCC is distributed in the hope that it will be useful, but WITHOUT ANY
21285809SscottlWARRANTY; without even the implied warranty of MERCHANTABILITY or
22285809SscottlFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23285809Sscottlfor more details.
24285809Sscottl
25285809SscottlYou should have received a copy of the GNU General Public License
26285809Sscottlalong with GCC; see the file COPYING.  If not, write to the Free
27285809SscottlSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28285809Sscottl02110-1301, USA.  */
29285809Sscottl
30285809Sscottl/* As a special exception, if you link this library with files compiled with
31285809Sscottl   GCC to produce an executable, this does not cause the resulting executable
32285809Sscottl   to be covered by the GNU General Public License. This exception does not
33285809Sscottl   however invalidate any other reasons why the executable file might be
34285809Sscottl   covered by the GNU General Public License.  */
35285809Sscottl
36285809Sscottl#include "config.h"
37285809Sscottl#include <ssp/ssp.h>
38285809Sscottl#ifdef HAVE_STRING_H
39285809Sscottl# include <string.h>
40285809Sscottl#endif
41285809Sscottl
42285809Sscottlextern void __chk_fail (void) __attribute__((__noreturn__));
43285809Sscottl
44285809Sscottl#ifdef HAVE_STRNCPY
45285809Sscottlchar *
46285809Sscottl__strncpy_chk (char *__restrict__ dest, const char *__restrict__ src,
47285809Sscottl               size_t len, size_t slen)
48285809Sscottl{
49285809Sscottl  if (len > slen)
50285809Sscottl    __chk_fail ();
51285809Sscottl  return strncpy (dest, src, len);
52285809Sscottl}
53285809Sscottl#endif
54285809Sscottl