Ali Azimi Ali Azimi - 9 months ago 57
Linux Question

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?

thanks all. but new problem! :
is there a way to get a user uid and gid without using "id -u username" command in c? parsing /etc/passwd? or better way?

Mat Mat

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>.