Search code examples
clinuxchown

Change owner and group in C?


I want to change owner and group of a file in C. I google it, but if find only some code that use system() and chmod command or relative functions.

Is there a way to do this without system() functions and Bash commands?


Solution

  • You can use the chmod, fchmodat and/or fchmod system calls. All three are located in <sys/stat.h>.

    For ownership, there's chown and fchownat, both in <unistd.h>.