5

I want to get the owner and group from a file using boost::filesystem, but never found any way to do so.

I can get the file's permissions, but as I don't know the file's owner this just doesn't mean anything.

I found the posix fstat function, but again I'd like to use boost or another C++ library rather than C functions.

Jaffa
  • 12,442
  • 4
  • 49
  • 101
  • possible duplicate of [How can I determine the owner of a file or directory using boost filesystem?](http://stackoverflow.com/questions/10681929/how-can-i-determine-the-owner-of-a-file-or-directory-using-boost-filesystem) – CharlesB Sep 11 '12 at 16:56
  • 2
    @CharlesB How can my post duplicate this? The other may be a duplicate but not mine as its the older one. – Jaffa Sep 17 '12 at 06:45

1 Answers1

-1

What you're asking to do is a Unix system call. But you don't want to call it? Why? What possible value could boost provide? It's not portability, as nothing outside of a Unix is going to have a meaningful st_gid field.

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
  • It will be portable to all posix systems :) So perhaps there are so C++ library implementing this. And as I'm working on a CLI tool, it's not really designed for Windows and other non-posix systems – Jaffa Apr 23 '12 at 23:26
  • 3
    POSIX is spec, Unix is an implementation, it's not exactly the same. A posix system may not be a unix system. And in that case you NEVER use any library, cause everything is a system call. Why should I use `new` as it's resolved to a syscall? It's the same here. – Jaffa Apr 24 '12 at 16:07
  • Do you want your answer or not? Clearly everything is not a system call: you cannot open a window, uncompress a zlib stream or compute a MD5 hash with a system call. But you **can** stat a file. You are writing in a language which provides unobstructed access to your platform's syscalls. Use it. – Andy Ross Apr 24 '12 at 22:52
  • Just one point, a syscall involves an interruption instruction which cannot be reproduced natively in C or C++. The fstat functions is already a wrapper around a syscall, not a syscall itself, so there may be C++ lib which does the same. You present me the syscall as THE solution when it's just one wrapper. But if there is no C++ solution just say it, that's all I want to know! – Jaffa Apr 25 '12 at 08:29
  • You have to **execute** the system in all cases. That is how, fundamentally, your process asks the OS for the information. All wrappers ultimately end up making a trap to the OS. The stat/fstat functions in the C library are the simplest possible wrappers, and as they are natively available to you in C/C++, they are what you should use. – Andy Ross Apr 25 '12 at 20:31
  • The fact they are the simplest doesn't mean you should use them, or why are other libraries for? If I have to do some networking I'll use some OO library to make things easier, I won't issue directly the syscall used to redirect data to a specific memory area in the same time as a signal is send to the network controller. But anyway, as I've not any other answer I'll still use the C function, and thanks for the discussion :) – Jaffa Apr 25 '12 at 20:40
  • 9
    @AndyRoss `boost::filesystem` does provide an abstraction for POSIX permission bitmasks like read/write/execute, so it absolutely makes sense to ask why `boost::filesystem` omits an abstraction for POSIX owner/group. – Gunther Piez Jun 17 '13 at 12:49