I want to replace all instances of '::memcpy()' with my custom made 'customMemcpy()' defined in a file 'Memory.h' in my project. This call is made from lot of places so doing it manually is pain. Is there any clever method to do it programmatically?
Asked
Active
Viewed 198 times
-2
-
4Whats wrong with Find and Replace? – Ash Burlaczenko Mar 21 '12 at 15:38
-
2It seems you have already got a 'method to do it problematically' :-( Perhaps you want to do it programmatically, in which case perhaps your IDE (vi ? Emacs ? Notepad ?) can help. Tell us what that is, we may be able to provide proper help rather than silly comments. – High Performance Mark Mar 21 '12 at 15:39
-
1You could `#define memcpy customMemcpy`, assuming the parameters are the same. – Grimm The Opiner Mar 21 '12 at 15:40
-
2Any text editing tool I know of (even ed) has a "Search&Replace" function. Why not use that? – cli_hlt Mar 21 '12 at 15:40
-
Using Search and replace is not really good enough it can cause too many problems. http://stackoverflow.com/a/4665620/14065 In this case modify to change memcpy to XXXmemcpyXXX. – Martin York Mar 21 '12 at 16:09
-
@LokiAstari: most IDE Search and Replace have an option for "Match entire word" that fixes that problem. – Mooing Duck Mar 21 '12 at 17:42
-
@MooingDuck: No IDE can not cope with the size of the code base I use. – Martin York Mar 21 '12 at 19:17
3 Answers
0
You can use wrapping mechanism, see http://sourceware.org/binutils/docs/ld/Options.html (find --wrap=symbol
) for example. This way gives you acess both to your and original function.

vissi2
- 83
- 6
0
find . -name '*.cpp' -print0 | xargs -0 -l sed -i -e 's/\<memcpy\>/customMemcpy/'

Robᵩ
- 163,533
- 20
- 239
- 308
0
#define memcpy(dst,src,size) custom_memcpy(dst, src, size)
void custom_memcpy(void* dst, const void* src, size_t size)
{
//TODO: Implement Custom Memcpy
}

TVOHM
- 2,740
- 1
- 19
- 29