Alex Rivera | Logout

What is the difference between read() and fread()?

Asked 2009-02-24T23:40:16.927
75

I'm reading source code of the linux tool badblocks. They use the read() function there. Is there a difference to the standard C fread() function? (I'm not counting the arguments as a difference.)

Edit
Report

1 Answer

14

As I remember it the read() level APIs do not do buffering - so if you read() 1 byte at a time you will have a huge perf penalty compared to doing the same thing with fread(). fread() will pull a block and dole it out as you ask for it. read() will drop to the kernel for each call.

answered 2009-02-24T23:43:43.893

Your Answer