Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit handle systems without getpwent_r
details: https://anonhg.NetBSD.org/src/rev/176dbff45394
branches: trunk
changeset: 767738:176dbff45394
user: christos <christos%NetBSD.org@localhost>
date: Thu Jul 28 17:33:39 2011 +0000
description:
handle systems without getpwent_r
diffstat:
lib/libedit/readline.c | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diffs (65 lines):
diff -r 911043e4f780 -r 176dbff45394 lib/libedit/readline.c
--- a/lib/libedit/readline.c Thu Jul 28 16:28:12 2011 +0000
+++ b/lib/libedit/readline.c Thu Jul 28 17:33:39 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.93 2011/07/28 00:54:26 christos Exp $ */
+/* $NetBSD: readline.c,v 1.94 2011/07/28 17:33:39 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.93 2011/07/28 00:54:26 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.94 2011/07/28 17:33:39 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -1673,14 +1673,17 @@
* a completion generator for usernames; returns _first_ username
* which starts with supplied text
* text contains a partial username preceded by random character
- * (usually '~'); state is ignored
+ * (usually '~'); state resets search from start (??? should we do that anyway)
* it's callers responsibility to free returned value
*/
char *
username_completion_function(const char *text, int state)
{
- struct passwd *pwd, pwres;
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
char pwbuf[1024];
+#endif
+ struct passwd *pass = NULL;
if (text[0] == '\0')
return (NULL);
@@ -1691,15 +1694,21 @@
if (state == 0)
setpwent();
- while (getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pwd) == 0
- && pwd != NULL && text[0] == pwd->pw_name[0]
- && strcmp(text, pwd->pw_name) == 0);
+ while (
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pass) == 0 && pass != NULL
+#else
+ (pass = getpwent()) != NULL
+#endif
+ && text[0] == pass->pw_name[0]
+ && strcmp(text, pass->pw_name) == 0)
+ continue;
- if (pwd == NULL) {
+ if (pass == NULL) {
endpwent();
return NULL;
}
- return strdup(pwd->pw_name);
+ return strdup(pass->pw_name);
}
Home |
Main Index |
Thread Index |
Old Index