c copy file permissions from another file

前端 未结 1 701
既然无缘
既然无缘 2021-01-14 14:39

What\'s the simplest way to copy the unix file permissions of a file and set them to another file? Is there a way to store a file\'s permissions to a variable and then use t

相关标签:
1条回答
  • 2021-01-14 14:52

    Sure. Use stat() and chmod() (may need root).

    #include <sys/stat.h>
    
    struct stat st;
    stat("/foo/bar.txt", &st);
    chmod("/baz/quirk.jpg", st.st_mode);
    
    0 讨论(0)
提交回复
热议问题