Fixing file permissions after modifying in C++?

25,303

Solution 1

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

Solution 2

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

Try it:

system("chmod 755 yourExeFile")
Share:
25,303
RPFeltz
Author by

RPFeltz

Updated on July 16, 2022

Comments

  • RPFeltz
    RPFeltz almost 2 years

    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.

  • David Grayson
    David Grayson about 12 years
    Use 755 if you prefer not getting hacked.
  • RPFeltz
    RPFeltz about 12 years
    That did the job! Very simple too.
  • sb32134
    sb32134 over 5 years
    maybe add the semicolon in above? :)