diff options
author | Christopher Faylor <me@cgf.cx> | 2003-01-20 02:57:54 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-01-20 02:57:54 +0000 |
commit | 7905c4f158c479c3d08e112c55f91be38aa70dae (patch) | |
tree | 9fcc54ea43fa128e60ecf3b52373ed25f77b382b /winsup/cygwin/grp.cc | |
parent | 6f2480fbf706f944d20f8db3f17733ee8978987e (diff) | |
download | newlib-7905c4f158c479c3d08e112c55f91be38aa70dae.zip newlib-7905c4f158c479c3d08e112c55f91be38aa70dae.tar.gz newlib-7905c4f158c479c3d08e112c55f91be38aa70dae.tar.bz2 |
* pwdgrp.h (etc): Move to path.h.
(pwdgrp::max_lines): New field.
(pwdgrp::curr_lines): New field.
(pwdgrp::pwdgrp_buf): Ditto.
(pwdgrp_buf_elem_size): Ditto.
(pwdgrp_parse): Ditto.
(pwdgrp::gets): Just declare here.
(pwdgrp::load): Ditto. Just take one argument.
(pwdgrp::load): Define overloaded function accepting passwd buf.
(pwdgrp::load): Define overloaded function accepting group buf.
* grp.cc: Use pwdgrp elements rather than standalone static variables
throughout.
(curr_lines): Eliminate.
(max_lines): Ditto.
(add_grp_line): Ditto.
(parse_grp): Define as returning boolean. Accept void * arg and line count.
Coerce first argument into __group32 buf reference. Increment curr_line as
appropriate.
(read_etc_group): Pass pwdgrp buffer to gr.load.
* passwd.cc: Use pwdgrp elements rather than standalone static variables
throughout.
(curr_lines): Eliminate.
(max_lines): Ditto.
(add_grp_line): Ditto.
(parse_passwd): Define as returning boolean. Accept void * arg and line count.
Coerce first argument into passwd buf reference. Increment curr_line as
appropriate.
(read_etc_group): Pass pwdgrp buffer to pr.load.
* path.cc (etc::fn): Extend buffer size to allow index by 1 rather than zero.
(etc::last_modified): Ditto.
(etc::change_possible): Ditto. Renamed from sawchange. Change to signed char
since elements are now tri-state.
(etc::init): Assume "handle" is 1 based rather than 0.
(etc::test_file_change): New function. Sets change_possible based on file date
comparison.
(etc::dir_changed): Check file states immediately after changed_h is
initialized to avoid a race.
(etc::file_changed): Use test_file_change to detect if file needs to be
updated.
* path.h (etc): Move class here from pwdgrp.h.
* uinfo.cc: Move etc:: functions to path.cc. Move pwdgrp functions here.
(pwdgrp::gets): Eliminate buf checks. Just check eptr and set lptr.
(pwdgrp::add_line): New function.
(pwdgrp::load): Call generic add_line function which will call correct parser.
Diffstat (limited to 'winsup/cygwin/grp.cc')
-rw-r--r-- | winsup/cygwin/grp.cc | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 85ec51d..dc13304 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -26,27 +26,22 @@ details. */ #include "cygheap.h" #include "pwdgrp.h" -/* Read /etc/group only once for better performance. This is done - on the first call that needs information from it. */ - -static struct __group32 NO_COPY *group_buf; /* group contents in memory */ -static int NO_COPY curr_lines; -static int NO_COPY max_lines; - /* Position in the group cache */ #define grp_pos _reent_winsup ()->_grp_pos -static pwdgrp NO_COPY gr; +static pwdgrp gr; +static __group32 *group_buf; static char * NO_COPY null_ptr; -static int -parse_grp (struct __group32 &grp, char *line) +bool +pwdgrp::parse_grp (char *line) { char *dp = strchr (line, ':'); if (!dp) - return 0; + return false; +# define grp (* group_buf)[curr_lines] *dp++ = '\0'; grp.gr_name = line; @@ -80,23 +75,12 @@ parse_grp (struct __group32 &grp, char *line) grp.gr_mem = namearray; } } - return 1; + curr_lines++; + return true; } } - return 0; -} - -/* Read one line from /etc/group into the group cache */ -static void -add_grp_line (char *line) -{ - if (curr_lines == max_lines) - { - max_lines += 10; - group_buf = (struct __group32 *) realloc (group_buf, max_lines * sizeof (struct __group32)); - } - if (parse_grp (group_buf[curr_lines], line)) - curr_lines++; + return false; +# undef grp } class group_lock @@ -130,12 +114,11 @@ read_etc_group () /* if we got blocked by the mutex, then etc_group may have been processed */ if (gr.isinitializing ()) { - for (int i = 0; i < curr_lines; i++) + for (int i = 0; i < gr.curr_lines; i++) if ((group_buf + i)->gr_mem != &null_ptr) free ((group_buf + i)->gr_mem); - curr_lines = 0; - if (!gr.load ("/etc/group", add_grp_line)) + if (!gr.load ("/etc/group", group_buf)) debug_printf ("gr.load failed"); /* Complete /etc/group in memory if needed */ @@ -156,11 +139,11 @@ read_etc_group () snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:%s", group_name, strbuf, myself->gid, cygheap->user.name ()); debug_printf ("Completing /etc/group: %s", linebuf); - add_grp_line (linebuf); + gr.add_line (linebuf); } static char NO_COPY pretty_ls[] = "????????::-1:"; if (wincap.has_security ()) - add_grp_line (pretty_ls); + gr.add_line (pretty_ls); } return; } @@ -174,7 +157,7 @@ internal_getgrsid (cygsid &sid) read_etc_group (); if (sid.string (sid_string)) - for (int i = 0; i < curr_lines; i++) + for (int i = 0; i < gr.curr_lines; i++) if (!strcmp (sid_string, group_buf[i].gr_passwd)) return group_buf + i; return NULL; @@ -186,7 +169,7 @@ internal_getgrgid (__gid32_t gid, bool check) if (gr.isuninitialized () || (check && gr.isinitializing ())) read_etc_group (); - for (int i = 0; i < curr_lines; i++) + for (int i = 0; i < gr.curr_lines; i++) if (group_buf[i].gr_gid == gid) return group_buf + i; return NULL; @@ -198,7 +181,7 @@ internal_getgrnam (const char *name, bool check) if (gr.isuninitialized () || (check && gr.isinitializing ())) read_etc_group (); - for (int i = 0; i < curr_lines; i++) + for (int i = 0; i < gr.curr_lines; i++) if (strcasematch (group_buf[i].gr_name, name)) return group_buf + i; @@ -206,8 +189,7 @@ internal_getgrnam (const char *name, bool check) return NULL; } -static -struct __group16 * +static struct __group16 * grp32togrp16 (struct __group16 *gp16, struct __group32 *gp32) { if (!gp16 || !gp32) @@ -263,7 +245,7 @@ getgrent32 () if (gr.isinitializing ()) read_etc_group (); - if (grp_pos < curr_lines) + if (grp_pos < gr.curr_lines) return group_buf + grp_pos++; return NULL; @@ -290,7 +272,7 @@ internal_getgrent (int pos) if (gr.isuninitialized ()) read_etc_group (); - if (pos < curr_lines) + if (pos < gr.curr_lines) return group_buf + pos; return NULL; } |