Dec
14

Whats is difference between file descriptor and file pointer?

Author JIGAR PATEL    Category c, linux, Tips, tips     Tags

After having 1 year of experience in c programming when someone has asked this to me i was surprised that why i dont know this…!!

Well when i will going to interview someone in someday this would be my 1st question to him/her…!!!

File Descriptor :  

  “A file descriptor is a low-level integer “handle” used to identify an opened file (or socket, or whatever) at the kernel level, in Linux and other Unix-like systems.”

 int fd;
 fd = open(path, O_CREAT | O_RDONLY, 0644);
 close(fd);

This way you are using that is file-descriptor. In short,  file-descriptor is

  1. Low/Kernel level handler
  2. passe to read() and write() of UNIX System Calls
  3. Doesn’t include buffering and such features
  4. Less portable and lacks efficiency
  5. It’s some what OS specific so its not part of standard c programming language.

File Pointer :

“A FILE pointer is a C standard library-level construct, used to represent a file. The FILE wraps the file descriptor, and adds buffering and other features to make I/O easier.”

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

When you write this then you are using file pointer. file pointer is

  1. It is high level interface
  2. Passed to fread() and fwrite() functions
  3. Includes buffering,error indication and EOF detection,etc.
  4. Provides higher portability and efficiency.
  5. It’s  part of standard c programming language.

 
see also

Convert file descriptor to file pointer | Convert file pointer to file descriptor in Linux by C programming

 

JIGAR PATEL

hey I am an Artist who love to write code…! Well I am an EC graduate From Ganpat University and now i am working as Embedded software engineer in one private firm.. find me at here JigAr Patel

More PostsWebsiteTwitterFacebook

You may like to read this also....

1 Comment to “Whats is difference between file descriptor and file pointer?”

Post comment

*

CommentLuv badge
Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

latest comments

Find us on Facebook

Top Authors

35 posts
saurabh
22 posts
10 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

My Bookmarks

Sponsers Link