Set the permissions (777) of a file (example.txt)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/stat.h> int main(int argc, char **argv) { char mode[] = "0777"; char buf[100] = "/home/user/example.txt"; int i; i = strtol(mode, 0, 8); if (chmod (buf,i) < 0) { fprintf(stderr, "%s: error in chmod(%s, %s) - %d (%s)\n", argv[0], buf, mode, errno, strerror(errno)); exit(1); } return(0); } |