c copy file permissions from another file

£可爱£侵袭症+ 提交于 2019-12-30 10:36:35

问题


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 that variable to set those permissions to another file?


回答1:


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);


来源:https://stackoverflow.com/questions/16680302/c-copy-file-permissions-from-another-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!