Reputation: 91
I am using the Linux stat function to find the length of a file in bytes and then I am trying the read the entire file (this is so I don't have to check for a null terminator and can create a perfect sized buffer to store the data) (I am not concerned about the file changing during the read). I tried using fgets but quickly remembered that it terminates at a new line and so this will not work. Is there a version of fgets that does not do this?
Upvotes: 0
Views: 53
Reputation: 16540
suggest:
use mmap()
to make the contents available via a simple
memory reference.
Upvotes: 0
Reputation: 224102
The standard C library routine fread
will attempt to read a requested number of bytes (expressed as a number of objects of a given size) from a stream, and the Linux/Unix/POSIX routine read
will attempt to read a requested number of bytes (expressed as a number of bytes) from a file descriptor.
Upvotes: 4