Re: Replacing read() by a debugging function



On Jan 28, 3:45 pm, fnegroni <f.e.negr...@xxxxxxxxxxxxxx> wrote:
And therefore function pointers achieve exactly the intended goal, bar
optimisation.

Hello fnegroni,

you have replied 3 times in my thread, thank you.

But I don't get your point. In the 1st reply you have
rephrased my original question and in the following
just written "look above".

So my question again: is there a way to replace
a syscall? I'm trying the following, but it doesn't work:

4DEL03468:~ {542} cat replace-write.c
#include <stdio.h>
#include <unistd.h>

ssize_t write2(int d, const void *buf, size_t nbytes) {
fprintf(stderr, "ok, replaced\n");
}

int main(int argc, char *argv[]) {
write = write2;
write(STDERR_FILENO, "blah\n", 5);
}

4DEL03468:~ {543} gcc replace-write.c -o replace-write.exe
replace-write.c: In function `main':
replace-write.c:9: error: invalid lvalue in assignment

And yes Eric, I haven't measured yet how much does
an "if(debug)" last (I probably can do it with gprof?)
but I'm sure it takes more than nothing, esp. in a loop.

Regards
Alex
.



Relevant Pages

  • Re: Replacing read() by a debugging function
    ... optimisation. ... rephrased my original question and in the following ... write = write2; ... Traditionally system calls have been defined 'weak' such that ...
    (comp.unix.programmer)
  • Re: about string and character
    ... Looking forward for amusing explanations of how a sequence of one ... I don't take it because it converts a pointer to a char for some ... Do they represent a string or part of one; four individual char; 2 ... It has nothing to do with the original question though, ...
    (comp.lang.c)
  • Re: about string and character
    ... for instance yours wasn't an answer to the original question. ... The byte occupied by this object constitutes a one-character string, ... Do they represent a string or part of one; four individual char; 2 ... the right hand expression of possibly be different than the right ...
    (comp.lang.c)