Reputation: 3894
This question is in reference to How can I get a file's size in C?
Most answers suggesting the use of the function stat to get the file length also comes with a tag to do error checking.
What kind of error checking do we need here?
Thanks.
Upvotes: 2
Views: 650
Reputation: 40627
Like many Unix/POSIX API functions, stat(2)
returns a negative integer on failure. Unfortunately, this integer is always -1 for stat. Hence, you need to check the errno
global variable (defined in <errno.h>
) to see what the exact error was.
Ben has listed some of the errors you can run into; the errno codes for these and other errors are listed in the stat manpage.
Upvotes: 3
Reputation: 283803
Upvotes: 2