What I would like to have is something like that :
./client.out:functionC.c:78: Error blabla <--- Here is my problem
./client.out:client.c:98: Error blabla
Here are my sample functions
/* client.c */
int main(int argc, char *argv[]) {
if(functionCalled() == -1){
fprintf(stderr, "%s:%s:%d: Error blabla\n", argv[0], __FILE__, __LINE__);
}
return 0;
}
/* functionC.c */
int functionCalled(){
fprintf(stderr, "%s:%s:%d: Error blabla\n", ?????, __FILE__, __LINE__);
return -1;
}
Obviously I can't send the main.c
name through the parameters. Do you think it is possible to get the mother program which calls the function ? I have a client and a server calling the same function but in case of error I need to know which program (client or server) crashed.
ANSWER :
Using : extern char *progName;
in the functionC.c and char *progName;
in client.c