#include <stdio.h>
const int CUSTOM_FILENO = 3;
// run the program in the shell like "./extra-fd 3>out"
// it writes a line to the file "out"
int main() {
FILE* file = fdopen(CUSTOM_FILENO, "w");
if (file == NULL) {
char buf[48];
sprintf(buf, "cannot output to fd=%d", CUSTOM_FILENO);
perror(buf);
return 1;
}
fputs("Hello, world!\n", file);
fclose(file);
fprintf(stderr, "successfully write to fd=%d\n", CUSTOM_FILENO);
}