Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing file permissions after modifying in 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?

Additional information: I use linux.

like image 398
RPFeltz Avatar asked Feb 15 '12 02:02

RPFeltz


2 Answers

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

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

It is documented in http://linux.die.net/man/3/chmod.

See also: C++ - How to set file permissions (cross platform).

like image 143
Barham Avatar answered Nov 10 '22 06:11

Barham


If you include stdlib.h, you can use system("command").

Try it:

system("chmod 755 yourExeFile")
like image 22
Behnam Safari Avatar answered Nov 10 '22 06:11

Behnam Safari