diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-06-05 11:10:15 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-06-05 11:10:15 +0000 |
commit | 38f39368891d83c63e6f4aa3b00b19b80444b041 (patch) | |
tree | 84c6f229a06e2dc946c671a4d7b2dab26b314900 /winsup/cygwin/pwdgrp.h | |
parent | ce006ffa7f6985c2dbe6128d74ba6beda562743a (diff) | |
download | newlib-38f39368891d83c63e6f4aa3b00b19b80444b041.zip newlib-38f39368891d83c63e6f4aa3b00b19b80444b041.tar.gz newlib-38f39368891d83c63e6f4aa3b00b19b80444b041.tar.bz2 |
* grp.cc (etc_group): Removed.
(parse_grp): Make line parameter nonconst. Don't copy data into new
allocated memory. Check for CR instead of LF to accomodate new
read method.
(add_grp_line): Make line parameter nonconst.
(read_etc_group): Rearrange using new pwdgrp_read class.
* passwd.cc (parse_pwd): Don't copy data into new allocated memory.
Check for CR instead of LF to accomodate new read method.
(read_etc_passwd): Rearrange using new pwdgrp_read class.
* pwdgrp.h (pwdgrp_check::set_last_modified): Use different
parameters.
(class pwdgrp_read): New class for opening and reading passwd and
group files.
Diffstat (limited to 'winsup/cygwin/pwdgrp.h')
-rw-r--r-- | winsup/cygwin/pwdgrp.h | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 568259d..d2dcfcd 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -44,12 +44,81 @@ public: { state = nstate; } - void set_last_modified (FILE *f) + void set_last_modified (HANDLE fh, const char *name) { if (!file_w32[0]) - strcpy (file_w32, cygheap->fdtab[fileno (f)]->get_win32_name ()); - - GetFileTime (cygheap->fdtab[fileno (f)]->get_handle (), - NULL, NULL, &last_modified); + strcpy (file_w32, name); + GetFileTime (fh, NULL, NULL, &last_modified); } }; + +class pwdgrp_read { + path_conv pc; + HANDLE fh; + char *buf; + char *lptr, *eptr; + +public: + pwdgrp_read () + : fh (INVALID_HANDLE_VALUE), buf (NULL), lptr (NULL), eptr (NULL) {} + virtual ~pwdgrp_read () + { + close (); + if (buf) + free (buf); + } + + bool open (const char *posix_fname) + { + if (buf) + free (buf); + buf = lptr = eptr = NULL; + + pc.check (posix_fname); + if (pc.error || !pc.exists () || !pc.isdisk () || pc.isdir ()) + return false; + + fh = CreateFile (pc, GENERIC_READ, wincap.shared (), NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, 0); + if (fh) + { + DWORD size = GetFileSize (fh, NULL), read_bytes; + buf = (char *) malloc (size + 1); + if (!ReadFile (fh, buf, size, &read_bytes, NULL)) + { + if (buf) + free (buf); + buf = NULL; + CloseHandle (fh); + fh = INVALID_HANDLE_VALUE; + return false; + } + buf[read_bytes] = '\0'; + return true; + } + return false; + } + char *gets () + { + if (!buf) + return NULL; + if (!lptr) + lptr = buf; + else if (!eptr) + return lptr = NULL; + else + lptr = eptr; + eptr = strchr (lptr, '\n'); + if (eptr) + *eptr++ = '\0'; + return lptr; + } + inline HANDLE get_fhandle () { return fh; } + inline const char *get_fname () { return pc; } + void close () + { + if (fh != INVALID_HANDLE_VALUE) + CloseHandle (fh); + fh = INVALID_HANDLE_VALUE; + } +}; |