Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Set executable mode on the file

$
0
0
I have the following code wherein I , fopen (source) in "r" mode, fopen (destination) in "w" mode, copy the contents, fclose both and then attempt to retain the mode.

struct stat fs;
stat (destfile, &fs);
int destmode = fs.st_mode;
destmode |= sourcefile.mode; //could be 444, 555 or 777
destmode &= ~0222; //Remove the write mode
destmode &= 0111; //Will this set the executable mode??

chmod (destfile, destmode);



Is "destmode &= 0111; " the right way to forcibly set the executable bit?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>