blob: 49691334064b618e09ecfa99ef7ed07a9590aa19 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
bartafe82262008-06-01 08:48:48 +00002
3/*--------------------------------------------------------------------*/
4/*--- Replacements for strlen() and strnlen(), which run on the ---*/
5/*--- simulated CPU. ---*/
6/*--------------------------------------------------------------------*/
7
8/*
bartbedfd232009-03-26 19:07:15 +00009 This file is part of DRD, a heavyweight Valgrind tool for
10 detecting threading errors. The code below has been extracted
11 from memchec/mc_replace_strmem.c, which has the following copyright
12 notice:
bartafe82262008-06-01 08:48:48 +000013
bart31b983d2010-02-21 14:52:59 +000014 Copyright (C) 2000-2009 Julian Seward
bartbedfd232009-03-26 19:07:15 +000015 jseward@acm.org
bartafe82262008-06-01 08:48:48 +000016
bartbedfd232009-03-26 19:07:15 +000017 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of the
20 License, or (at your option) any later version.
bartafe82262008-06-01 08:48:48 +000021
bartbedfd232009-03-26 19:07:15 +000022 This program is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
bartafe82262008-06-01 08:48:48 +000026
bartbedfd232009-03-26 19:07:15 +000027 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 02111-1307, USA.
bartafe82262008-06-01 08:48:48 +000031
bartbedfd232009-03-26 19:07:15 +000032 The GNU General Public License is contained in the file COPYING.
bartafe82262008-06-01 08:48:48 +000033*/
34
35#include "pub_tool_basics.h"
36#include "pub_tool_hashtable.h"
37#include "pub_tool_redir.h"
38#include "pub_tool_tooliface.h"
39#include "valgrind.h"
40
41
bartbedfd232009-03-26 19:07:15 +000042#define STRNLEN(soname, fnname) \
bartafe82262008-06-01 08:48:48 +000043 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ); \
44 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname) ( const char* str, SizeT n ) \
bartbedfd232009-03-26 19:07:15 +000045 { \
46 SizeT i = 0; \
47 while (i < n && str[i] != 0) i++; \
48 return i; \
bartafe82262008-06-01 08:48:48 +000049 }
50
njne6154662009-02-10 04:23:41 +000051STRNLEN(VG_Z_LIBC_SONAME, strnlen)
bart31b983d2010-02-21 14:52:59 +000052
bartafe82262008-06-01 08:48:48 +000053
54// Note that this replacement often doesn't get used because gcc inlines
55// calls to strlen() with its own built-in version. This can be very
56// confusing if you aren't expecting it. Other small functions in this file
57// may also be inline by gcc.
bartbedfd232009-03-26 19:07:15 +000058#define STRLEN(soname, fnname) \
59 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ); \
60 SizeT VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* str ) \
61 { \
62 SizeT i = 0; \
63 while (str[i] != 0) i++; \
64 return i; \
bartafe82262008-06-01 08:48:48 +000065 }
66
njne6154662009-02-10 04:23:41 +000067STRLEN(VG_Z_LIBC_SONAME, strlen)
njnb4cfbc42009-05-04 04:20:02 +000068#if defined(VGO_linux)
njne6154662009-02-10 04:23:41 +000069STRLEN(VG_Z_LD_LINUX_SO_2, strlen)
70STRLEN(VG_Z_LD_LINUX_X86_64_SO_2, strlen)
njnb4cfbc42009-05-04 04:20:02 +000071#endif
bartafe82262008-06-01 08:48:48 +000072
73/*--------------------------------------------------------------------*/
74/*--- end ---*/
75/*--------------------------------------------------------------------*/