在Linux的C应用编程中,可以使用chown函数来更改文件的拥有者及拥有者组。此函数申明如下:
/usr/include/unistd.h文件中
/* Change the owner and group of FILE. */extern int chown (__const char *__file, __uid_t __owner, __gid_t __group)__THROW __nonnull ((1)) __wur;
此函数的第一个参数为欲更改用户的文件,第二个参数为更改后的文件拥有者linux数据恢复,第三个参数为更改后该文件拥有者所在的组。
对于已打开的文件linux修改文件内容linux软件工程师,使用fchown函数来更改。其第一个参数为已打开文件的文件描述符,其他同chown函数。该函数申明如下:
/* Change the owner and group of the file that FD is open on. */extern int fchown (int __fd, __uid_t __owner, __gid_t __group) __THROW __wur;
对于联接文件,则可以使用lchown函数。其参数同于chown函数。
/* Change owner and group of FILE, if it is a symbolic link the ownership of the symboliclink is changed. */extern int lchown (__const char *__file, __uid_t __owner, __gid_t __group) __THROW __nonnull ((1)) __wur;
以上这3个函数倘若执行成功,将返回0linux修改文件内容,否则返回-1。