First, oh great Unix gurus, forgive if this is a stupid question.
Unix/Linux is not my main thing but I have been programming in C/C++ for many years. I will do my best to be specific.
I have a program in C/C++ that needs to modify the time of a given file. Currently I do this using utime() passing it a filespec and an FTIME structure (I get the time of other files using ustat elsewhere).
This code works fine when there are no permission issues (hence the title), so I think it is safe to say I am using these functions correctly.
However, when the file to be modified was created by root and the user running my program is (in some way) not as privileged in the permissions area, then utime() call fails with errno = 1.
What I don't understand is why it fails if the file is set for RW for User, Group and World. Even though user X running the program is not root, I thought they can still write to it because root has it open to the world for writing. What am I missing here?
If the file is owned by user X it works or if root is the user it works, but if they don't match it does not. I would expect it to work for all users if the file is writable for everyone.
Should I be using a different method? I did think is was odd that I could call utime without opening the file to get a file handle first.
Someone said it is because the containing directory is hwere the write permissions have to be, but I tried making the folder RW for world too.
Please enlighten me to the underlying issue here. I want to understand this.
Thanks.