/* * fdopen.c * Opens a FILE* file handle from an int. */ #include #include #include #include #include #include #include int main(int argc, char **argv) { int fint; FILE *fptr; if((fint=open("testfile", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR))==-1) { fprintf(stdout,"failed to open testfile, %s\n",strerror(errno)); fflush(stdout); return -1; } if(!(fptr=fdopen(fint,"w"))) { fprintf(stdout,"failed to open file* descriptor %s\n",strerror(errno)); fflush(stdout); close(fint); } fwrite("hello",5,1,fptr); fclose(fptr); close(fint); return 0; }