一、函数
#include <unistd.h>
int chown(const char *path, uid_t owner, gid_t group);
int fchown(int fd, uid_t owner, gid_t group);
int lchown(const char *path, uid_t owner, gid_t group);
#include <fcntl.h> /* Definition of AT_* constants */
#include <unistd.h>
int fchownat(int dirfd, const char *pathname,uid_t owner, gid_t group, int flags);
//返回值:成功返回0;出错返回-1
- 功能:用来更改文件的用户ID、组ID
- 如果owner、group中的任意一个为-1,则对应的ID不变
lchown、fchownat
fchown
二、修改限制
- _POSIX_CHOWN_RESTRICTED常量:https://blog.csdn.net/qq_41453285/article/details/89960726
- 如果_POSIX_CHOWN_RESTRICTED对指定的文件生效
我们终端使用的chown命令也是如此