0

As in description. I need to find out who own a file using cpp code, i am using boost filesystem, codeblocks on ubuntu 12.04 (which is irrelevant, but). If anyone could give me function name, or reference link, to particular function, i would be greatful.

Fabricio Araujo
  • 3,810
  • 3
  • 28
  • 43
Artur
  • 13
  • 4
  • A simple google search give me this link: http://stackoverflow.com/questions/7328327/how-to-get-files-owner-name-in-linux-using-c – Amadeus Jan 28 '14 at 18:09

1 Answers1

0

boost::filesystem does not support this functionality, you can obtain file attributes, but that's it.

Something like this should work:

#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);

Note: The previous code is not error safe, that's up to you

ichramm
  • 6,437
  • 19
  • 30
  • With, the appropriate function on the `path` to get the name in the system dependent format, since he's using `boost::filesystem`. (And error checking, of course.) – James Kanze Jan 28 '14 at 18:52