My program receives an executable binary file through a TCP socket.
I need to save this file in to the harddisk as a executable program. File is successfully received but the problem is the default file attribute is being set to non executable.
How to change the file's attribute as executable in C in Ubuntu?
Thank you, Regards, Robo
How about int chmod(const char *path, mode_t mode) and int fchmod(int fd, mode_t mode) ?
apropos chmod
man 2 chmod
The most basic example:
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
char * fpath = "/path/to/binary";
int ret=0;
if(ret = chmod(fpath, S_IRUSR|S_IXUSR) < 0){
perror("chmod failed");
exit(1);
}
printf("chmod ok\n");
exit(0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With