mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-19 04:49:25 +08:00
* grp.cc (getgrgid_r): Simplify code by using stpcpy.
(getgrnam_r): Ditto. * passwd.cc (getpwuid_r32): Simplify code by using stpcpy. (getpwnam_r): Ditto.
This commit is contained in:
parent
93e884989a
commit
b89fb103f2
@ -1,3 +1,10 @@
|
||||
2009-01-26 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* grp.cc (getgrgid_r): Simplify code by using stpcpy.
|
||||
(getgrnam_r): Ditto.
|
||||
* passwd.cc (getpwuid_r32): Simplify code by using stpcpy.
|
||||
(getpwnam_r): Ditto.
|
||||
|
||||
2009-01-26 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* uinfo.cc (pwdgrp::load): Open file with FILE_OPEN_FOR_BACKUP_INTENT
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* grp.cc
|
||||
|
||||
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007 Red Hat, Inc.
|
||||
2007, 2008, 2009 Red Hat, Inc.
|
||||
|
||||
Original stubs by Jason Molenda of Cygnus Support, crash@cygnus.com
|
||||
First implementation by Gunther Ebert, gunther.ebert@ixos-leipzig.de
|
||||
@ -195,20 +195,13 @@ getgrgid_r (__gid32_t gid, struct __group32 *grp, char *buffer, size_t bufsize,
|
||||
/* make a copy of tempgr */
|
||||
*result = grp;
|
||||
grp->gr_gid = tempgr->gr_gid;
|
||||
grp->gr_name = buffer;
|
||||
grp->gr_passwd = grp->gr_name + strlen (tempgr->gr_name) + 1;
|
||||
grp->gr_mem = (char **) (grp->gr_passwd + strlen (tempgr->gr_passwd) + 1);
|
||||
char *mem = (char *) grp->gr_mem + (i + 1) * sizeof (char *);
|
||||
buffer = stpcpy (grp->gr_name = buffer, tempgr->gr_name);
|
||||
buffer = stpcpy (grp->gr_passwd = buffer + 1, tempgr->gr_passwd);
|
||||
grp->gr_mem = (char **) (buffer + 1);
|
||||
buffer = (char *) grp->gr_mem + (i + 1) * sizeof (char *);
|
||||
for (i = 0; tempgr->gr_mem[i]; ++i)
|
||||
{
|
||||
grp->gr_mem[i] = mem;
|
||||
mem += strlen (tempgr->gr_mem[i]) + 1;
|
||||
}
|
||||
buffer = stpcpy (grp->gr_mem[i] = buffer, tempgr->gr_mem[i]) + 1;
|
||||
grp->gr_mem[i] = NULL;
|
||||
strcpy (grp->gr_name, tempgr->gr_name);
|
||||
strcpy (grp->gr_passwd, tempgr->gr_passwd);
|
||||
for (i = 0; tempgr->gr_mem[i]; ++i)
|
||||
strcpy (grp->gr_mem[i], tempgr->gr_mem[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -252,20 +245,13 @@ getgrnam_r (const char *nam, struct __group32 *grp, char *buffer,
|
||||
/* make a copy of tempgr */
|
||||
*result = grp;
|
||||
grp->gr_gid = tempgr->gr_gid;
|
||||
grp->gr_name = buffer;
|
||||
grp->gr_passwd = grp->gr_name + strlen (tempgr->gr_name) + 1;
|
||||
grp->gr_mem = (char **) (grp->gr_passwd + strlen (tempgr->gr_passwd) + 1);
|
||||
char *mem = (char *) grp->gr_mem + (i + 1) * sizeof (char *);
|
||||
buffer = stpcpy (grp->gr_name = buffer, tempgr->gr_name);
|
||||
buffer = stpcpy (grp->gr_passwd = buffer + 1, tempgr->gr_passwd);
|
||||
grp->gr_mem = (char **) (buffer + 1);
|
||||
buffer = (char *) grp->gr_mem + (i + 1) * sizeof (char *);
|
||||
for (i = 0; tempgr->gr_mem[i]; ++i)
|
||||
{
|
||||
grp->gr_mem[i] = mem;
|
||||
mem += strlen (tempgr->gr_mem[i]) + 1;
|
||||
}
|
||||
buffer = stpcpy (grp->gr_mem[i] = buffer, tempgr->gr_mem[i]) + 1;
|
||||
grp->gr_mem[i] = NULL;
|
||||
strcpy (grp->gr_name, tempgr->gr_name);
|
||||
strcpy (grp->gr_passwd, tempgr->gr_passwd);
|
||||
for (i = 0; tempgr->gr_mem[i]; ++i)
|
||||
strcpy (grp->gr_mem[i], tempgr->gr_mem[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* passwd.cc: getpwnam () and friends
|
||||
|
||||
Copyright 1996, 1997, 1998, 2001, 2002, 2003, 2007 Red Hat, Inc.
|
||||
Copyright 1996, 1997, 1998, 2001, 2002, 2003, 2007, 2008, 2009 Red Hat, Inc.
|
||||
|
||||
This file is part of Cygwin.
|
||||
|
||||
@ -159,9 +159,9 @@ getpwuid_r32 (__uid32_t uid, struct passwd *pwd, char *buffer, size_t bufsize, s
|
||||
return 0;
|
||||
|
||||
/* check needed buffer size. */
|
||||
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
||||
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
||||
strlen (temppw->pw_passwd) + 5;
|
||||
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_passwd)
|
||||
+ strlen (temppw->pw_gecos) + strlen (temppw->pw_dir)
|
||||
+ strlen (temppw->pw_shell) + 5;
|
||||
if (needsize > bufsize)
|
||||
return ERANGE;
|
||||
|
||||
@ -169,17 +169,12 @@ getpwuid_r32 (__uid32_t uid, struct passwd *pwd, char *buffer, size_t bufsize, s
|
||||
*result = pwd;
|
||||
pwd->pw_uid = temppw->pw_uid;
|
||||
pwd->pw_gid = temppw->pw_gid;
|
||||
pwd->pw_name = buffer;
|
||||
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
||||
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
||||
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
||||
buffer = stpcpy (pwd->pw_name = buffer, temppw->pw_name);
|
||||
buffer = stpcpy (pwd->pw_passwd = buffer + 1, temppw->pw_passwd);
|
||||
buffer = stpcpy (pwd->pw_gecos = buffer + 1, temppw->pw_gecos);
|
||||
buffer = stpcpy (pwd->pw_dir = buffer + 1, temppw->pw_dir);
|
||||
stpcpy (pwd->pw_shell = buffer + 1, temppw->pw_shell);
|
||||
pwd->pw_comment = NULL;
|
||||
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
||||
strcpy (pwd->pw_name, temppw->pw_name);
|
||||
strcpy (pwd->pw_dir, temppw->pw_dir);
|
||||
strcpy (pwd->pw_shell, temppw->pw_shell);
|
||||
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
||||
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -217,9 +212,9 @@ getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, s
|
||||
return 0;
|
||||
|
||||
/* check needed buffer size. */
|
||||
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
||||
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
||||
strlen (temppw->pw_passwd) + 5;
|
||||
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_passwd)
|
||||
+ strlen (temppw->pw_gecos) + strlen (temppw->pw_dir)
|
||||
+ strlen (temppw->pw_shell) + 5;
|
||||
if (needsize > bufsize)
|
||||
return ERANGE;
|
||||
|
||||
@ -227,17 +222,12 @@ getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, s
|
||||
*result = pwd;
|
||||
pwd->pw_uid = temppw->pw_uid;
|
||||
pwd->pw_gid = temppw->pw_gid;
|
||||
pwd->pw_name = buffer;
|
||||
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
||||
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
||||
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
||||
buffer = stpcpy (pwd->pw_name = buffer, temppw->pw_name);
|
||||
buffer = stpcpy (pwd->pw_passwd = buffer + 1, temppw->pw_passwd);
|
||||
buffer = stpcpy (pwd->pw_gecos = buffer + 1, temppw->pw_gecos);
|
||||
buffer = stpcpy (pwd->pw_dir = buffer + 1, temppw->pw_dir);
|
||||
stpcpy (pwd->pw_shell = buffer + 1, temppw->pw_shell);
|
||||
pwd->pw_comment = NULL;
|
||||
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
||||
strcpy (pwd->pw_name, temppw->pw_name);
|
||||
strcpy (pwd->pw_dir, temppw->pw_dir);
|
||||
strcpy (pwd->pw_shell, temppw->pw_shell);
|
||||
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
||||
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user