如何使用 C++ 在 Linux 中获取文件的所有者名称?
如何使用 C++ 获取 Linux 文件系统上文件的所有者名称和组名称? stat()
调用仅提供所有者 ID 和组 ID,但不提供实际名称。
-rw-r--r--. 1 john devl 3052 Sep 6 18:10 blah.txt
如何以编程方式获取“john”和“devl”?
How can I get get the owner name and group name of a file on a Linux filesystem using C++? The stat()
call only gives me owner ID and group ID but not the actual name.
-rw-r--r--. 1 john devl 3052 Sep 6 18:10 blah.txt
How can I get 'john' and 'devl' programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
getpwuid()
和getgrgid()
。Use
getpwuid()
andgetgrgid()
.一种方法是使用
stat()
来获取文件的 uid,然后getpwuid()
获取用户名作为字符串。One way would be to use
stat()
to get the uid of a file and thengetpwuid()
to get the username as a string.