Back to index

glibc  2.9
test-stpcpy_chk.c
Go to the documentation of this file.
00001 /* Test and measure stpcpy checking functions.
00002    Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #define STRCPY_RESULT(dst, len) ((dst) + (len))
00022 #define TEST_MAIN
00023 #include "../string/test-string.h"
00024 
00025 extern void __attribute__ ((noreturn)) __chk_fail (void);
00026 char *simple_stpcpy_chk (char *, const char *, size_t);
00027 extern char *normal_stpcpy (char *, const char *, size_t)
00028   __asm ("stpcpy");
00029 extern char *__stpcpy_chk (char *, const char *, size_t);
00030 
00031 IMPL (simple_stpcpy_chk, 0)
00032 IMPL (normal_stpcpy, 1)
00033 IMPL (__stpcpy_chk, 2)
00034 
00035 char *
00036 simple_stpcpy_chk (char *dst, const char *src, size_t len)
00037 {
00038   if (! len)
00039     __chk_fail ();
00040   while ((*dst++ = *src++) != '\0')
00041     if (--len == 0)
00042       __chk_fail ();
00043   return dst - 1;
00044 }
00045 
00046 #include "test-strcpy_chk.c"