Skip to content

Instantly share code, notes, and snippets.

@scifisamurai
Last active August 29, 2015 13:57
Show Gist options
  • Save scifisamurai/9926874 to your computer and use it in GitHub Desktop.
Save scifisamurai/9926874 to your computer and use it in GitHub Desktop.
Example of writing a program that will mimic chmod behavior. NOTE: This is overly simple, not robust, & hardcoded/derived. Much more would be needed for a useful program.
/*See man -s 2 chmod for more information */
#include <stdio.h>
#include <sys/stat.h>
int main(void){
/*mode_t mode = S_IXOTH */
mode_t mode = 00755; /*Replace this with the actual mode you want. Ideally you'd want to ask the user */
chmod("hi.txt", mode); /*This assumes hi.txt is present. You'd want to prompt the user for a filename in a real scenario */
return 0;
}
/*gcc simple_chmod.c; ./a.out */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment