fopen should allow you to open the file for reading, but will not open it for writing. Note that if you try to open the file for writing, it WILL NOT return a null file, but as soon as you try to write to it the program will crash. That is what happened to me (Windows XP Pro SP3) with this program:
#include <stdio.h>
int main(int argc, char **argv) {
char *exe = argv[0];
strcat(exe, ".exe")
printf("%s\n", exe);
FILE *in = fopen(exe, "r");
FILE *out = fopen(exe, "w");
if (in == NULL) printf("in is NULL!\n");
if (out == NULL) printf("out is NULL!\n");
char line[1024];
printf("Attempting to read...\n");
fgets(line, 1024, in);
printf("%s\n\n", line);
printf("Attempting to write...\n");
fputs("hello", out);
return 0;
}
What the program does is try to read from itself, and write to itself.
DISCLAIMER: I take no responsibility for any damage this program may cause to any part of your computer.
EDIT: Added the operating system I tested this program on.