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

前端 未结 6 1285
你的背包
你的背包 2020-11-27 12:45

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?

6条回答
  •  悲&欢浪女
    2020-11-27 13:35

    read() --> Directly using this system call to kernel and that performs the IO operation.

    fread() --> Is a function provided in standard library.

    Calling fread() is mainly used for binary file data where struct data are stored. The main difference between these two is the number of system calls in your application.

    The fread() kind of standard IO library functions are optimized for system calls, rather your application making system calls.

提交回复
热议问题