Thread: copying Permissions

  1. #1
    Unregistered
    Guest

    Arrow 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.

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    depending on os you could make a system call, but this is not the best way to do it.
    Monday - what a way to spend a seventh of your life

  3. #3
    Unregistered
    Guest

    i'm using unix.

    i'm using unix.

  4. #4
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    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.
    Jason Deckard

  5. #5
    Unregistered
    Guest

    Wink thanks

    thanks Jason,

    i try that.


    Tom

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grant read/write/modify permissions to everyone
    By Elkvis in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2008, 06:12 PM
  2. displaying file permissions
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 11-26-2005, 07:04 AM
  3. C File permissions
    By vipers in forum C Programming
    Replies: 1
    Last Post: 04-24-2004, 12:00 PM
  4. Linux, forms, dirs, permissions, cgi-bin, and C
    By ronin in forum C Programming
    Replies: 0
    Last Post: 12-19-2003, 06:10 PM
  5. Shallow/Deep copying, pointers
    By littleweseth in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 06:36 PM