git.fiddlerwoaroof.com
sys_pwd.h
189f062b
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
a8b53afd
 #ifndef _SYS_PWD_H
 #define _SYS_PWD_H
 
 #include <memory>
 #include <pwd.h>
 
189f062b
 class pwd_ifc
 {
 public:
4d825470
     virtual ~pwd_ifc() {}
189f062b
     virtual int getpwnam_r (const char *user_name, passwd *out, char *buffer,
bf756dea
                             size_t buffer_sz, passwd **result) const
189f062b
     {
         *result = 0;
         return 0;
     };
a8b53afd
 };
 
3ae0e083
 class pwd
189f062b
 {
 public:
     typedef std::shared_ptr<pwd_ifc> delegate;
 
 private:
     delegate delegate_;
 
 public:
     pwd (const delegate delegate) : delegate_ (delegate) {}
     pwd() : delegate_ (delegate (new pwd_ifc)) {}
     int getpwnam_r (const char *user_name, passwd *out, char *buffer,
bf756dea
                     size_t buffer_sz, passwd **result) const
189f062b
     {
         return delegate_-> getpwnam_r (user_name, out, buffer, buffer_sz, result);
     }
da1b9b25
     static pwd create();
a8b53afd
 };
 
 #endif
189f062b