vul_io_user_info.cxx
Go to the documentation of this file.
1 // This is core/vul/io/vul_io_user_info.cxx
2 //:
3 // \file
4 #include <iostream>
5 #include "vul_io_user_info.h"
6 #include <vul/vul_user_info.h>
7 
8 //=========================================================================
9 //: Binary save self to stream.
10 void vsl_b_write(vsl_b_ostream &os, const vul_user_info & p)
11 {
12  constexpr short io_version_no = 1;
13  vsl_b_write(os, io_version_no);
14  vsl_b_write(os, p.uid);
15  vsl_b_write(os, p.gid);
16  vsl_b_write(os, p.name);
18  vsl_b_write(os, p.full_name);
19  vsl_b_write(os, p.shell);
20  vsl_b_write(os, p.passwd);
21 }
22 
23 //=========================================================================
24 //: Binary load self from stream.
25 void vsl_b_read(vsl_b_istream &is, vul_user_info & p)
26 {
27  if (!is) return;
28 
29  short v;
30  vsl_b_read(is, v);
31  switch (v)
32  {
33  case 1:
34  vsl_b_read(is, p.uid);
35  vsl_b_read(is, p.gid);
36  vsl_b_read(is, p.name);
38  vsl_b_read(is, p.full_name);
39  vsl_b_read(is, p.shell);
40  vsl_b_read(is, p.passwd);
41  break;
42 
43  default:
44  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vul_user_info&)\n"
45  << " Unknown version number "<< v << '\n';
46  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
47  return;
48  }
49 }
50 
51 
52 //=========================================================================
53 //: Output a human readable summary to the stream
54 void vsl_print_summary(std::ostream& os,const vul_user_info & p)
55 {
56  os << "( uid,gid,name,home_directory,full_name,shell,passwd="
57  << p.uid<<','<<p.gid<<','<<p.name
58  << " home_directory,full_name,shell="
59  << p.home_directory<<','<< p.full_name<<','<<p.shell
60  << " passwd=" << p.passwd<<')';
61 }
Reads information about a user from the password file.
void vsl_print_summary(std::ostream &os, const vul_user_info &p)
Output a human readable summary to the stream.
binary io for vul_user_info.
void vsl_b_read(vsl_b_istream &is, vul_user_info &p)
Binary load self from stream.
Reads information about a user from the password file.
Definition: vul_user_info.h:22
uid_type gid
Definition: vul_user_info.h:29
std::string passwd
Definition: vul_user_info.h:34
std::string name
Definition: vul_user_info.h:30
void vsl_b_write(vsl_b_ostream &os, const vul_user_info &p)
Binary save self to stream.
std::string full_name
Definition: vul_user_info.h:32
uid_type uid
Definition: vul_user_info.h:28
std::string shell
Definition: vul_user_info.h:33
std::string home_directory
Definition: vul_user_info.h:31