What is the difference between a file descriptor and a file pointer?

Possible duplicate:
What is the difference between a file descriptor and a file pointer?

If I open the file as follows:

FILE *fp = fopen("mr32.txr","r"); 

then fp is a file pointer or file descriptor? What is the difference between the two?

+4
source share
3 answers

fp - FILE pointer

File pointer:

  • This is a high level interface.
  • Passed to fread () and fwrite ()
  • Includes buffering, error indication, and EOF detection, etc.
  • Provides higher mobility and efficiency.

File descriptor:

  • Low-level / kernel-level handler.
  • passe for reading () and write () UNIX system calls
  • Does not include buffering and such functions
  • Less portable and lacking in efficiency.

based on this

+3
source

This is a pointer to a FILE structure, if that is what you are asking for. The file descriptor is an integer. The FILE structure and its associated APIs are part of the C standard. File descriptors and related functions are not. In practice, you can use any set of functions interchangeably, although there are some noticeable differences in the default behavior here and there. You can read the manual pages to find out which functions accept which parameters. On systems with file descriptors, you can usually use the fdopen(3) function to get the FILE structure from the open file descriptor and fileno(3) to go the other way.

+4
source

FILE is a structure containing information about a file, including a file descriptor.

+2
source

Source: https://habr.com/ru/post/1382009/


All Articles