.TH fileno() "" "" "STDIO Function (libc)"
.PC "Get file descriptor"
.B "#include <stdio.h>"
\fBint fileno(\fIfp\^\fB) FILE *\fIfp\^\fB;\fR
.PP
.II "file descriptor^get from FILE structure"
.B fileno()
returns the file descriptor associated with the file stream
.IR fp .
The file descriptor is the integer returned by
.B open()
or
.BR creat() ;
it corresponds to a
.B FILE
structure, as returned by the STDIO function
.BR fopen() .
.SH Example
This example reads a file descriptor and prints it on the screen.
.DM
#include <stdio.h>
.DE
.DM
main(argc,argv)
int argc; char *argv[];
{
	FILE *fp;
	int fd;
.DE
.DM
	if (argc !=2) {
		printf("Usage: fd_from_fp filename\en");
		exit(0);
	}
.DE
.DM
	if ((fp = fopen(argv[1], "r")) == NULL) {
		printf("Cannot open input file\en");
		exit(0);
	}
.DE
.DM
	fd = fileno(fp);
	printf("The file descriptor for %s is %d\en",
		argv[1], fd);
}
.DE
.SH "See Also"
.Xr "FILE," file.d
.Xr "file descriptor," file_desc
.Xr "libc" libc
.br
\*(PX Standard, \(sc8.2.1
