{ struct stat st; /* The following makes sure that file descriptors 0 (stdin), 1 (stdout) and 2 (stderr) will not be "reused", because if e.g. file descriptor 2 would be reused when opening a file, a write to stderr would write to that file and most likely corrupt it. */ if ((fstat (0, &st) == -1 && open ("/dev/null", O_RDONLY) == -1) || (fstat (1, &st) == -1 && open ("/dev/null", O_WRONLY) == -1) || (fstat (2, &st) == -1 && open ("/dev/null", O_WRONLY) == -1)) { fprintf(error_stream, "%s: error: cannot open '/dev/null'\n", progname); return EXIT_FAILURE; } }