Wednesday, July 9, 2008

atexit() example. exit (1) in main, but $?=0

This atexit function just look like another way to obfuscate programs.
Example:


[rtg@rtgCent cpp_exa]$ cat atex.c
#include <stdio.h>
#include <stdlib.h>

void mine(void)
{
printf("mine!\n");
exit(0);
}

void yours(void)
{
printf("yours!\n");
exit(1);
}

int main(int argc,char **argv )
{
atexit(mine);
atexit(yours);
printf("exiting...\n");
exit(1);
}
[rtg@rtgCent cpp_exa]$ gcc atex.c
[rtg@rtgCent cpp_exa]$ ./a.out
exiting...
yours!
mine!
[rtg@rtgCent cpp_exa]$ echo $?
0

No comments: