sample might as well be in C
This commit is contained in:
parent
6c45dd47da
commit
4c22783a54
2 changed files with 5 additions and 5 deletions
41
sample/main.c
Normal file
41
sample/main.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) Lysann Tranvouez. All rights reserved.
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mach_detours.h"
|
||||
|
||||
char* (*real_strerror)(int errno) = strerror;
|
||||
|
||||
static int counter = 0;
|
||||
|
||||
char* my_strerror(const int errno)
|
||||
{
|
||||
counter++;
|
||||
return real_strerror(errno);
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
counter = 0;
|
||||
strerror(0);
|
||||
assert(counter == 0);
|
||||
|
||||
detour_transaction_begin();
|
||||
detour_attach((detour_func_t*)&real_strerror, (detour_func_t)my_strerror);
|
||||
detour_transaction_commit();
|
||||
|
||||
assert(counter == 0);
|
||||
strerror(0);
|
||||
assert(counter == 1);
|
||||
|
||||
detour_transaction_begin();
|
||||
detour_detach((detour_func_t*)&real_strerror, (detour_func_t)my_strerror);
|
||||
detour_transaction_commit();
|
||||
|
||||
assert(counter == 1);
|
||||
strerror(0);
|
||||
assert(counter == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue