使用
getpwuid()和
getgrgid()。
#include <pwd.h>#include <grp.h>#include <sys/stat.h>struct stat info;stat(filename, &info); // Error check omittedstruct passwd *pw = getpwuid(info.st_uid);struct group *gr = getgrgid(info.st_gid);// If pw != 0, pw->pw_name contains the user name// If gr != 0, gr->gr_name contains the group name



