I copy a file by opening the source in read-only mode and the destination in write-only mode. It’s simple and it works.
The problem is that sometimes I am copying a file that sits on an NFS drive, or other network drives and when in these cases the permissions get all screwed and SELinux complains. I then go and manually set the permissions of the files I just copied and it’s OK. I can access them again (via ftp, web, etc).
Is there any way to copy a file and change the permissions to a certain user and group?
Code is appreciated.
Thanks
EDIT:
would something like
open(argv[2], O_WRONLY | O_CREAT, 0666)
work?
According to http://www.delorie.com/gnu/docs/glibc/libc_290.html, there is a function:
This should do what you want.