在C ++中修改后要修复文件权限? [英] Fixing file permissions after modifying in C++?

查看:94
本文介绍了在C ++中修改后要修复文件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据保存在程序的可执行文件中.我将其复制到一个临时文件中,覆盖一个以'魔术字符串'开头的部分,并将其重命名为原始文件.我知道这是个坏主意,但我只是出于实验目的.

I'm saving my data in the executable file of the program. I copy it to a temporary file, overwrite a part starting at a 'magic string' and rename it to the original. I know this is a bad idea, but I'm doing it just for experimenting.

到目前为止,我一切正常,除了每次替换文件时必须重新启用允许以可执行文件身份运行".有什么方法可以解决这个问题?

I got everything to work so far, except for that I have to re-enable "Allow running as an executable" each time the file is replaced. What ways are there to solve this?

其他信息:我使用linux.

Additional information: I use linux.

推荐答案

如果要避免使用system(),可以使用

If you want to avoid using system(), you can use

#include <sys/stat.h>
int chmod(const char *path, mode_t mode);

它记录在 http://linux.die.net/man/3/chmod .

另请参见: C ++-如何设置文件权限(跨平台) ).

这篇关于在C ++中修改后要修复文件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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