* 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.
This commit is contained in:
Christopher Faylor
2003-01-24 03:53:46 +00:00
parent 09a8842674
commit ac4133746e
8 changed files with 134 additions and 141 deletions

View File

@@ -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 = (*p == '\n') ? NULL : p + 1;
*p = '\0';
}
return res;
}
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 (eptr)
{
lptr = eptr;
eptr = strchr (lptr, '\n');
if (eptr)
{
if (eptr > lptr && *(eptr - 1) == '\r')
*(eptr - 1) = 0;
*eptr++ = '\0';
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) ();
}
return lptr;
}
void
pwdgrp::add_line (char *line)
{
if (curr_lines >= max_lines)
{
max_lines += 10;
*pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
}
(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;
}