从另一个文件C复制文件的权限 [英] c copy file permissions from another file
本文介绍了从另一个文件C复制文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是复制文件的UNIX文件权限,并将它们设置到另一个文件最简单的方法?是否有一个文件的权限存储到变量,然后使用该变量这些权限设置到另一个文件的方法?
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?
推荐答案
当然。使用 STAT()
和 CHMOD()
(可能需要root)。
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);
这篇关于从另一个文件C复制文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文