【问题标题】:Ubuntu file ownership cppUbuntu 文件所有权 cpp
【发布时间】:2014-02-20 04:59:56
【问题描述】:

如描述。我需要使用 cpp 代码找出谁拥有文件,我使用的是 boost 文件系统,ubuntu 12.04 上的代码块(这无关紧要,但是)。如果有人能给我特定功能的功能名称或参考链接,我会很感激。

【问题讨论】:

标签: c++ file ubuntu ownership


【解决方案1】:

boost::filesystem不支持此功能,可以获取文件属性,仅此而已。

这样的事情应该可以工作:

#include <sys/stat.h>

struct stat st;
stat("myFile.txt", &st);
struct passwd *pw = getpwuid(st.st_uid);
struct group  *gr = getgrgid(st.st_gid);

注意:前面的代码不是错误安全的,这取决于你

【讨论】:

  • 使用path 上的相应函数来获取系统相关格式的名称,因为他使用的是boost::filesystem。 (当然还有错误检查。)
猜你喜欢
  • 2012-02-17
  • 1970-01-01
  • 2021-05-18
  • 2014-03-18
  • 1970-01-01
  • 2015-01-16
  • 1970-01-01
  • 2022-06-18
  • 2014-01-07
相关资源
最近更新 更多