Definition | #include <stdio.h> FILE *fdopen(int fd, const char *mode);
|
Parameters
int fd
File descriptor that was assigned by a const char *mode String which specifies the access mode (see description under | |
Return val. | File pointer to the assigned FILE structure if successful. |
Note | If errors occur, e.g. due to an invalid file descriptor, |
Example | The following program opens the file fname for elementary as well as standard input/output #include <stdio.h> #include <stdlib.h> FILE *fp; int fd; char buf[10]; int c; int main(void) { int n; /* deal with the file descriptor first */ if((fd = open("fname",2)) < 0) { perror("open"); exit(1); } if((n = read(fd,buf,10)) > 0) write(1,buf,n); /* link file pointer with file descriptor */ fp = fdopen(fd,"w"); while((c = getchar()) != EOF) putc(c,fp); fclose(fp); return 0; } |
See also | creat, creat64, fclose, fseek, fseek64, fopen, fopen64, freopen, freopen64, open, open64 |