ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
ftools.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
10
11#include "alib/files/ftools.hpp"
12
13#if !defined (_WIN32)
14# include <pwd.h>
15# include <grp.h>
16#endif
17
18namespace alib::files {
19
20//==================================================================================================
21//=== OwnerAndGroupResolver
22//==================================================================================================
23std::pair<String,String> OwnerAndGroupResolver::Get( const FInfo& entry )
24{
25#if !defined ( _WIN32)
26 auto owner= entry.Owner();
27 if( lastUID != owner )
28 {
29 lastUID= owner;
30 auto* ownerPW= getpwuid(owner);
31 lastUIDResult.Reset(String(ownerPW ? ownerPW->pw_name : "?"));
32 }
33
34 auto group= entry.Group();
35 if( lastGID != group )
36 {
37 lastGID= group;
38 auto* groupPW= getgrgid(group);
39 lastGIDResult.Reset(String(groupPW ? groupPW->gr_name : "?") );
40 }
41
42 return std::pair<String,String>( lastUIDResult, lastGIDResult );
43
44#else
45 (void) entry;
46 {
47 return std::pair<String, String>(A_CHAR("<Unknown>"), A_CHAR("<Unknown>"));
48 }
49#endif
50
51}
52
53
54} // namespace [alib::files]
constexpr uint32_t Group() const noexcept
Definition finfo.hpp:434
constexpr uint32_t Owner() const noexcept
Definition finfo.hpp:432
FInfo::TOwnerAndGroupID lastUID
The last requested user ID..
Definition ftools.hpp:25
ALIB_API std::pair< String, String > Get(const FInfo &finfo)
Definition ftools.cpp:23
FInfo::TOwnerAndGroupID lastGID
The last requested group ID.
Definition ftools.hpp:26
AString lastUIDResult
The result associated with lastUID.
Definition ftools.hpp:27
AString lastGIDResult
The result associated with lastGID.
Definition ftools.hpp:28
#define A_CHAR(STR)
strings::TString< character > String
Type alias in namespace alib.