Advertisement
Guest User

Untitled

a guest
Mar 1st, 2018
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # [pjb@despina :0.0 c]$ make arg0
  2. cc arg0.c -o arg0
  3. # [pjb@despina :0.0 c]$ ./arg0
  4. argv[0]=./arg0
  5. # [pjb@despina :0.0 c]$ ( PATH=$(pwd) ; arg0 )
  6. argv[0]=arg0
  7. # [pjb@despina :0.0 c]$ $(pwd)/arg0
  8. argv[0]=/Users/pjb/src/c/arg0
  9. # [pjb@despina :0.0 c]$ cat arg0.c
  10. #include <stdio.h>
  11. int main(int argc,char* argv[]){
  12. printf("argv[0]=%s\n",argv[0]);
  13. return 0;
  14. }
  15. # [pjb@despina :0.0 c]$
  16.  
  17. # [pjb@despina :0.0 c]$ cat arg0.c
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. int main(int argc,char* argv[]){
  21. if(argc>1){
  22. char* pname=argv[0];
  23. argv[0]="You're fucked";
  24. execv(pname,argv);
  25. }
  26. printf("argv[0]=%s\n",argv[0]);
  27. return 0;
  28. }
  29. # [pjb@despina :0.0 c]$ make arg0
  30. cc arg0.c -o arg0
  31. # [pjb@despina :0.0 c]$ ./arg0 foo
  32. argv[0]=You're fucked
  33. # [pjb@despina :0.0 c]$
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement