MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / parse_line

Function parse_line

src/os/linux/users.cpp:43–62  ·  view source on GitHub ↗

Parse a /etc/passwd line: name:x:uid:gid:gecos:home:shell

Source from the content-addressed store, hash-verified

41
42// Parse a /etc/passwd line: name:x:uid:gid:gecos:home:shell
43bool parse_line(const std::string& line, PasswdEntry& e) {
44 if (line.empty() || line[0] == '#') return false;
45 std::vector<std::string> f;
46 std::string acc;
47 for (char c : line) {
48 if (c == ':') { f.push_back(std::move(acc)); acc.clear(); }
49 else if (c != '\r' && c != '\n') acc.push_back(c);
50 }
51 f.push_back(std::move(acc));
52 if (f.size() < 7) return false;
53 e.name = f[0];
54 try {
55 e.uid = static_cast<u32>(std::stoul(f[2]));
56 e.gid = static_cast<u32>(std::stoul(f[3]));
57 } catch (...) { return false; }
58 e.gecos = f[4];
59 e.home = f[5];
60 e.shell = f[6];
61 return true;
62}
63
64// Parse a whole /etc/passwd blob into a uid → entry map.
65std::map<u32, PasswdEntry> parse_passwd(const std::string& passwd) {

Callers 1

parse_passwdFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected