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.
Is "destmode &= 0111; " the right way to forcibly set the executable bit?
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?