如何使用C在Linux中获取文件的所有者名称?
发布时间:2020-12-16 05:47:34 所属栏目:百科 来源:网络整理
导读:如何使用C获取 Linux文件系统上的文件的所有者名称和组名? stat()调用仅给出所有者ID和组ID,但不给出实际名称. -rw-r--r--. 1 john devl 3052 Sep 6 18:10 blah.txt 如何以编程方式获
如何使用C获取
Linux文件系统上的文件的所有者名称和组名? stat()调用仅给出所有者ID和组ID,但不给出实际名称.
-rw-r--r--. 1 john devl 3052 Sep 6 18:10 blah.txt 如何以编程方式获取“john”和“devl”? 解决方法
使用
getpwuid() 和
getgrgid() .
#include <pwd.h> #include <grp.h> #include <sys/stat.h> struct stat info; stat(filename,&info); // Error check omitted struct 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Java设计模式学习记录-迭代器模式 Java设计模式
- getCompoundDrawables
- 正则表达式 知识点
- c# – 上下文菜单出现时如何获取鼠标位置?
- react-native – 如何使用本机反应来侦听物理按钮?
- postgresql报错Error while loading shared libraries: lib
- c# – IIS 7.x,添加启用HTTPS的站点:SiteCollection.Add(s
- ajax – 出于这个世界Comet编程和基于Web的聊天
- tdd – 测试驱动开发迫使公共方法太多
- postgresql – 尽管“SET client_min_messages TO WARNING”