xref: /dflybsd-src/contrib/gcc-4.7/libssp/mempcpy-chk.c (revision 94b98a915ba84699b2a2adab9146fbc2cf617459)
1*f02514dfSJohn Marino /* Checking mempcpy.
2*f02514dfSJohn Marino    Copyright (C) 2005, 2009 Free Software Foundation, Inc.
3*f02514dfSJohn Marino 
4*f02514dfSJohn Marino This file is part of GCC.
5*f02514dfSJohn Marino 
6*f02514dfSJohn Marino GCC is free software; you can redistribute it and/or modify it under
7*f02514dfSJohn Marino the terms of the GNU General Public License as published by the Free
8*f02514dfSJohn Marino Software Foundation; either version 3, or (at your option) any later
9*f02514dfSJohn Marino version.
10*f02514dfSJohn Marino 
11*f02514dfSJohn Marino In addition to the permissions in the GNU General Public License, the
12*f02514dfSJohn Marino Free Software Foundation gives you unlimited permission to link the
13*f02514dfSJohn Marino compiled version of this file into combinations with other programs,
14*f02514dfSJohn Marino and to distribute those combinations without any restriction coming
15*f02514dfSJohn Marino from the use of this file.  (The General Public License restrictions
16*f02514dfSJohn Marino do apply in other respects; for example, they cover modification of
17*f02514dfSJohn Marino the file, and distribution when not linked into a combine
18*f02514dfSJohn Marino executable.)
19*f02514dfSJohn Marino 
20*f02514dfSJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
21*f02514dfSJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
22*f02514dfSJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23*f02514dfSJohn Marino for more details.
24*f02514dfSJohn Marino 
25*f02514dfSJohn Marino Under Section 7 of GPL version 3, you are granted additional
26*f02514dfSJohn Marino permissions described in the GCC Runtime Library Exception, version
27*f02514dfSJohn Marino 3.1, as published by the Free Software Foundation.
28*f02514dfSJohn Marino 
29*f02514dfSJohn Marino You should have received a copy of the GNU General Public License and
30*f02514dfSJohn Marino a copy of the GCC Runtime Library Exception along with this program;
31*f02514dfSJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
32*f02514dfSJohn Marino <http://www.gnu.org/licenses/>.  */
33*f02514dfSJohn Marino 
34*f02514dfSJohn Marino 
35*f02514dfSJohn Marino #include "config.h"
36*f02514dfSJohn Marino #include <ssp/ssp.h>
37*f02514dfSJohn Marino #ifdef HAVE_STRING_H
38*f02514dfSJohn Marino # include <string.h>
39*f02514dfSJohn Marino #endif
40*f02514dfSJohn Marino 
41*f02514dfSJohn Marino extern void __chk_fail (void) __attribute__((__noreturn__));
42*f02514dfSJohn Marino 
43*f02514dfSJohn Marino #ifdef HAVE_MEMPCPY
44*f02514dfSJohn Marino void *
__mempcpy_chk(void * __restrict__ dest,const void * __restrict__ src,size_t len,size_t slen)45*f02514dfSJohn Marino __mempcpy_chk (void *__restrict__ dest, const void *__restrict__ src,
46*f02514dfSJohn Marino                size_t len, size_t slen)
47*f02514dfSJohn Marino {
48*f02514dfSJohn Marino   if (len > slen)
49*f02514dfSJohn Marino     __chk_fail ();
50*f02514dfSJohn Marino   return memcpy (dest, src, len) + len;
51*f02514dfSJohn Marino }
52*f02514dfSJohn Marino #endif
53