diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-06-28 22:14:35 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-06-28 22:14:35 +0000 |
commit | 45fcb767c3d32d764053c8694825e3ac2da02e1c (patch) | |
tree | 238e6a6472ec35f18aaf54e5bae0a88af0da9e5d /cpukit/libcsupport/src/getpwent.c | |
parent | 2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-45fcb767c3d32d764053c8694825e3ac2da02e1c.tar.bz2 |
2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/__brk.c, libcsupport/src/__gettod.c,
libcsupport/src/__times.c, libcsupport/src/fchdir.c,
libcsupport/src/ftrylockfile.c, libcsupport/src/getpwent.c,
libcsupport/src/gxx_wrappers.c, libcsupport/src/libio_sockets.c,
libcsupport/src/pipe.c: Use rtems_set_errno_and_return_minus_one()
where it was missed before.
Diffstat (limited to 'cpukit/libcsupport/src/getpwent.c')
-rw-r--r-- | cpukit/libcsupport/src/getpwent.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/cpukit/libcsupport/src/getpwent.c b/cpukit/libcsupport/src/getpwent.c index a4b47e50fa..210f4bedd5 100644 --- a/cpukit/libcsupport/src/getpwent.c +++ b/cpukit/libcsupport/src/getpwent.c @@ -24,6 +24,7 @@ #include <ctype.h> #include <rtems/libio_.h> +#include <rtems/seterr.h> /* * Static, thread-unsafe, buffers @@ -188,31 +189,28 @@ static int getpw_r( init_etc_passwd_group(); - if ((fp = fopen("/etc/passwd", "r")) == NULL) { - errno = EINVAL; - return -1; - } + if ((fp = fopen("/etc/passwd", "r")) == NULL) + rtems_set_errno_and_return_minus_one( EINVAL ); + for(;;) { - if (!scanpw(fp, pwd, buffer, bufsize)) { - errno = EINVAL; - fclose(fp); - return -1; - } + if (!scanpw(fp, pwd, buffer, bufsize)) + goto error_einval; + if (name) { match = (strcmp(pwd->pw_name, name) == 0); - } - else { + } else { match = (pwd->pw_uid == uid); } + if (match) { fclose(fp); *result = pwd; return 0; } } +error_einval: fclose(fp); - errno = EINVAL; - return -1; + rtems_set_errno_and_return_minus_one( EINVAL ); } int getpwnam_r( @@ -347,31 +345,28 @@ static int getgr_r( init_etc_passwd_group(); - if ((fp = fopen("/etc/group", "r")) == NULL) { - errno = EINVAL; - return -1; - } + if ((fp = fopen("/etc/group", "r")) == NULL) + rtems_set_errno_and_return_minus_one( EINVAL ); + for(;;) { - if (!scangr(fp, grp, buffer, bufsize)) { - errno = EINVAL; - fclose(fp); - return -1; - } + if (!scangr(fp, grp, buffer, bufsize)) + goto error_einval; + if (name) { match = (strcmp(grp->gr_name, name) == 0); - } - else { + } else { match = (grp->gr_gid == gid); } + if (match) { fclose(fp); *result = grp; return 0; } } +error_einval: fclose(fp); - errno = EINVAL; - return -1; + rtems_set_errno_and_return_minus_one( EINVAL ); } int getgrnam_r( |