test file permissions
Posted on 2006-05-13
This seems like it should be obvious, yet I can't find the answer anywhere.
I need to test whether or not the current process can read, write, and execute a given file. I am not trying to display the file mode as a string (which is what all examples I've found so far show), I want to know what I can do with a file.
I've been testing read and write by opening the file and catching errors, but this seems hackish and doesn't work at all for execute permissions.
Do I really need to deconvolute the mode mask and test user, group, all in turn, by hand? Surely this already exists somewhere.