fileno() STDIO Function fileno() Get file descriptor #include <stdio.h> int fileno(fp) FILE *fp; fileno returns the file descriptor associated with the file stream fp. The file descriptor is the integer returned by open or creat. It is used by routines such as fopen to create a FILE stream. ***** Example ***** This example reads a file descriptor and prints it on the screen. #include <stdio.h> main(argc,argv) int argc; char *argv[]; { FILE *fp; int fd; if (argc !=2) { printf("Usage: fd_from_fp filename\n"); exit(0); } if ((fp = fopen(argv[1], "r")) == NULL) { printf("Cannot open input file\n"); exit(0); } fd = fileno(fp); printf("The file descriptor for %s is %d\n", argv[1], fd); } ***** See Also ***** FILE, file descriptor, STDIO COHERENT Lexicon Page 1