2

In pset6, server.c,

what should I do to make sure the file is readable?

the problem set guide says it's possible to use "stat" or "access"?

since both return 0 on success and -1 if not, how do I know if the file is readable?

or can I use the return value 0 or -1 to determine if the file is readable?

Thanks!

3
  • Did you read the man pages of any of the 2 functions?
    – kzidane
    Feb 20 '15 at 11:27
  • Yes, I did. But I'm a little bit confusing about what to do to determine if readable. If I use stat, it seems that "mode_t st_mode;" in struct stat might be what I have to deal with. And if I use access, "mode" also seems to be what I have to deal with as well. But what should I do to deal with those mode things?
    – Y_C
    Feb 20 '15 at 13:56
  • I'm now understanding a bit. And, is it okay to use "access(path, R_OK) == 0" to determine if the file is readable?
    – Y_C
    Feb 20 '15 at 14:20
2

This can be done by using "access", as suggested in the pset sheet.

e.g.

use

access(path, R_OK)

to check if the file is readable, and it'll return 0 if readable and return -1 if not.

consult manpage for more information.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .