0

I have for the last few hours been looking up how to get and set the user ID, group ID, and file permissions, flags and other important information of a file using C++. I have seen code examples and my current code works wonders on Linux, which uses and

My current "Get User ID" code looks like this, and I will be adding #if defines to check OS and use OS specific gets / sets.

My question is rather broad, but if I could be pointed to some sort of universal library to do this, I would greatly appreciate it. Honestly anything that works on Mac, Linux and Windows would interest me. I've tried looking and only have come up with stat, which returns something similar to this: Owner: 1465530688

long perms::getUID(string filename)
{
    struct stat info;
    stat(filename.c_str(), &info);

    printf("Owner: %ld\n", (long)info.st_uid);
    return (long)info.st_uid;
 }
  • [`getuid()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getuid.html) [`getgid()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getgid.html) [`stat()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/stat.html) [`lstat()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/lstat.html) – Jonathan Leffler Dec 21 '15 at 05:59
  • Stat works on Linux. Not Mac. I tested the code above on Linux and tried it on Mac. It returns a weird value. – Tara Piccari Dec 21 '15 at 07:37

0 Answers0