diff options
author | Christopher Faylor <me@cgf.cx> | 2003-01-24 03:53:46 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-01-24 03:53:46 +0000 |
commit | ac4133746eeaad61b2bb2f71bd8861615b052427 (patch) | |
tree | 40d48ebf8a73cbd5ec8a206ab0a953033942d303 /winsup/cygwin/passwd.cc | |
parent | 09a88426740b765a99759d29da0e2a5f98c7281b (diff) | |
download | cygnal-ac4133746eeaad61b2bb2f71bd8861615b052427.tar.gz cygnal-ac4133746eeaad61b2bb2f71bd8861615b052427.tar.bz2 cygnal-ac4133746eeaad61b2bb2f71bd8861615b052427.zip |
* pwdrp.h (pwdgrp::refresh): Lock entire test prior to reading.
* grp.cc (pwdgrp::parse_group): Eliminate arg and use class member instead.
Use next_str and next_int to parse arguments.
* passwd.cc (pwdgrp::parse_passwd): Ditto.
(grab_string): Eliminate.
(grab_int): Ditto.
* pwdgrp.h (pwdgrp::parse): Eliminate input arg.
(pwdgrp::parse_passwd): Reflect above change.
(pwdgrp::parse_group): Reflect above change.
(pwdgrp::next_str): New function.
(pwdgrp::next_int): Ditto.
(pwdgrp::gets): Eliminate.
* uinfo.cc (pwdgrp::next_str): New function.
(pwdgrp::next_int): Ditto.
(pwdgrp::add_line): Subsume gets.
(pwdgrp::gets): Eliminate.
(pwdgrp::load): Just call add_line to parse input buffer.
Diffstat (limited to 'winsup/cygwin/passwd.cc')
-rw-r--r-- | winsup/cygwin/passwd.cc | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index 81ba9edab..0b85f95bf 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -33,52 +33,31 @@ static pwdgrp pr (passwd_buf); /* Position in the passwd cache */ #define pw_pos _reent_winsup ()->_pw_pos -/* Remove a : terminated string from the buffer, and increment the pointer */ -static char * -grab_string (char **p) -{ - char *src = *p; - char *res = src; - - while (*src && *src != ':') - src++; - - if (*src == ':') - { - *src = 0; - src++; - } - *p = src; - return res; -} - -/* same, for ints */ -static unsigned int -grab_int (char **p) -{ - char *src = *p; - unsigned int val = strtoul (src, p, 10); - *p = (*p == src || **p != ':') ? almost_null : *p + 1; - return val; -} - /* Parse /etc/passwd line into passwd structure. */ bool -pwdgrp::parse_passwd (char *buf) +pwdgrp::parse_passwd () { + int n; # define res (*passwd_buf)[curr_lines] /* Allocate enough room for the passwd struct and all the strings in it in one go */ - res.pw_name = grab_string (&buf); - res.pw_passwd = grab_string (&buf); - res.pw_uid = grab_int (&buf); - res.pw_gid = grab_int (&buf); - if (!*buf) + memset (&res, 0, sizeof (res)); + res.pw_name = next_str (); + res.pw_passwd = next_str (); + + n = next_int (); + if (n < 0) + return false; + res.pw_uid = n; + + n = next_int (); + if (n < 0) return false; + res.pw_gid = n; res.pw_comment = 0; - res.pw_gecos = grab_string (&buf); - res.pw_dir = grab_string (&buf); - res.pw_shell = grab_string (&buf); + res.pw_gecos = next_str (); + res.pw_dir = next_str (); + res.pw_shell = next_str (); curr_lines++; return true; # undef res |