summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/uinfo.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-01-24 03:53:46 +0000
committerChristopher Faylor <me@cgf.cx>2003-01-24 03:53:46 +0000
commitac4133746eeaad61b2bb2f71bd8861615b052427 (patch)
tree40d48ebf8a73cbd5ec8a206ab0a953033942d303 /winsup/cygwin/uinfo.cc
parent09a88426740b765a99759d29da0e2a5f98c7281b (diff)
downloadcygnal-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/uinfo.cc')
-rw-r--r--winsup/cygwin/uinfo.cc66
1 files changed, 44 insertions, 22 deletions
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 0c154ea69..b52cc0989 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -391,34 +391,58 @@ cygheap_user::env_name (const char *name, size_t namelen)
}
char *
-pwdgrp::gets (char*& eptr)
+pwdgrp::next_str (char c)
{
- char *lptr;
- if (!eptr)
+ if (!lptr)
+ return NULL;
+ char search[] = ":\n\0\0";
+ search[2] = c;
+ char *res = lptr;
+ char *p = strpbrk (lptr, search);
+ if (!p)
lptr = NULL;
else
{
- lptr = eptr;
- eptr = strchr (lptr, '\n');
- if (eptr)
- {
- if (eptr > lptr && *(eptr - 1) == '\r')
- *(eptr - 1) = 0;
- *eptr++ = '\0';
- }
+ lptr = (*p == '\n') ? NULL : p + 1;
+ *p = '\0';
}
- return lptr;
+ return res;
}
-void
-pwdgrp::add_line (char *line)
+int
+pwdgrp::next_int (char c)
+{
+ char *p = next_str (c);
+ if (!p)
+ return -1;
+ char *cp;
+ unsigned n = strtoul (p, &cp, 10);
+ if (p == cp)
+ return -1;
+ return n;
+}
+
+char *
+pwdgrp::add_line (char *eptr)
{
- if (curr_lines >= max_lines)
+ if (eptr)
{
- max_lines += 10;
- *pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
+ lptr = eptr;
+ eptr = strchr (lptr, '\n');
+ if (eptr)
+ {
+ if (eptr > lptr && eptr[-1] == '\r')
+ eptr[-1] = '\n';
+ eptr++;
+ }
+ if (curr_lines >= max_lines)
+ {
+ max_lines += 10;
+ *pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
+ }
+ (void) (this->*parse) ();
}
- (void) (this->*parse) (line);
+ return eptr;
}
bool
@@ -459,11 +483,9 @@ pwdgrp::load (const char *posix_fname)
CloseHandle (fh);
buf[read_bytes] = '\0';
char *eptr = buf;
- eptr = buf;
- char *line;
curr_lines = 0;
- while ((line = gets (eptr)) != NULL)
- add_line (line);
+ while ((eptr = add_line (eptr)))
+ continue;
debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
res = true;
}