-
copying Permissions
Hello people,
Does anyone know the code in C to:
Copy one file to another, with the names of the files given on the command line. E.G:
Command FirstFile1 SecondFile2.
It should copy the file: “FirstFile1” , to the new file: “SecondFile”.
…Also ensures that the file access Permissions of the new file match those of the original file.
Regards Tom.
Hope to here from someone soon.
-
depending on os you could make a system call, but this is not the best way to do it.
-
i'm using unix.
-
Tom,
If you don't want to use Iain's suggestion, I recommend reading the originating file's permissions using stat() or lstat() (the difference is lstat() does not follow symbolic links). stat() and lstat() will fill a structure with plenty of information about the file in question. The member st_mode has the permission bits for the file.
You would then fopen the origin file and creat() or fopen() the destination file. If you fopen(), the new file will have a default mode of 0666, so you will want to change the mode using fchmod() before you closed the file descriptor. If you use creat(), you can set the mode as part of creat()'s arguments.
Once you get to that point, it is simply a matter of reading from one descriptor, writing to the other, and then cleaning up after yourself.
-
thanks
thanks Jason,
i try that.
Tom