So I'm trying to figure out how to work this, but I'm not getting anywhere. We have an assignment where we have to sort a file we get from stdin. Part of the requirement is that we have to use fstat to get information about the file. Mainly, if it's a regular file or not. If it is, we have to allocate enough memory with malloc to store it.
The problem I'm having is figuring out how to get fstat to work correctly. I know that there's a macros S_ISREG(m) that we can check using the st_mode field...? How...?
Is it a bool and how do I even access it? The problem is I can find all these documents explaining WHAT all the things are, but not how to use them. Basically, I have:
struct stat buffer;
status = fstat(0, &buffer);
size = buffer.st_size;
That stores the stat struct with all the information. What I need is something that will let me do something like this:
if(/*is a regular file*/)
do something else;
The problem being I don't think I'm even storing size correctly and I'm not sure how to use the st_mode field :\