What is the contents of FILE *

I have this program

#include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <fcntl.h> int main(void) { FILE* f = fopen("/Users/user/a.cc", "rb"); printf("%i\n", f); // 1976385616 printf("%i\n", *f); // 1976385768 int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); printf("%i\n", sockfd); // 4 fclose(f); close(sockfd); int fd = open("/Users/user/a.cc", O_TRUNC | O_WRONLY, 0); printf("%i\n", (int) fd); // 3 close(fd); } 

I know that 3 and 4 represent file descriptors with 0, 1, 2 equal to stdin , stdout and stderr respectively. Obviously fopen does not use a file descriptor.

What is the meaning of FILE* ? How fopen , if not, with file descriptors?

+2
c linux unix file-descriptor
Apr 08 '16 at 1:56
source share
1 answer

What is the meaning of FILE *?

This is a pointer to a FILE structure, for glibc its definition is here . Which, among other things, contains a file descriptor. You can get the file descriptor from FILE* using the POSIX fileno function.

See Interfacing file descriptors and standard input / output streams for details.

+1
Apr 08 '16 at 16:31 on
source share
— -



All Articles