用C复制文件后,保持fileowner和权限 [英] Keeping fileowner and permissions after copying file in C

查看:136
本文介绍了用C复制文件后,保持fileowner和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的问题:在C中,我创建了一个文件的副本(含部分变更)这是通过fopen()函数,getchar函数和平凡的putchar完成。
复制文件是好的,OUTPUTFILE本身是什么,我希望它是。

here is my problem: In C, I create the copy of a file (with some changes) This is done trivially via fopen(), getchar and putchar. Copying the file is fine and the outputfile itself is what I want it to be.

我的问题是:我以为我会经常使用这个程序的须藤,然后将生成的文件既有另一个所有者(根),以及不同的权限(执行权利都没有了)

My problem is: I assume that I will use this program often as sudo and then the resulting file has both another owner (root) as well as different permissions (execute rights are gone).

我的问题是:我如何可以复制所有者和原始文件的权限,然后将它们写入到新的

My question is: How can I copy the owner and permissions of the original file and then write them into the new one?

推荐答案

使用的 FSTAT 的(2)系统调用,以获取有关业主和权限,而细节的 fchmod 的(2)的 fchown 的(2)系统调用进行设置。见在 setfile 的一个例子的* BSD的 CP 的(1)<函数href=\"http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/bin/cp/utils.c?rev=1.61;content-type=text/plain\"相对=nofollow>来源$ C ​​$ C 。

Use the fstat(2) system call to obtain the details about the owner and the permissions, and the fchmod(2) and fchown(2) system calls to set them. See an example in the setfile function of the *BSD cp(1) source code.

这篇关于用C复制文件后,保持fileowner和权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆