On Godbolt, opening /dev/null
for writing fails when you use fopen
but succeeds when you use open
, and I have no idea why.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
if (fopen("/dev/null", "w") == NULL) {
perror("fopen");
}
if (open("/dev/null", O_WRONLY) == -1) {
perror("open");
}
}
https://godbolt.org/z/1Y6x58Tv6