summaryrefslogtreecommitdiffstats
path: root/login-utils/chsh.c
diff options
context:
space:
mode:
authorSami Kerola2017-04-23 19:51:51 +0200
committerSami Kerola2017-05-03 00:22:05 +0200
commite41ae450937e51d6016ba6a43f0559efdc09f4e2 (patch)
tree4727e6b7af11f29ed9e4c159ca9baecdc583e433 /login-utils/chsh.c
parentfindfs: use getopt_long() to parse options (diff)
downloadkernel-qcow2-util-linux-e41ae450937e51d6016ba6a43f0559efdc09f4e2.tar.gz
kernel-qcow2-util-linux-e41ae450937e51d6016ba6a43f0559efdc09f4e2.tar.xz
kernel-qcow2-util-linux-e41ae450937e51d6016ba6a43f0559efdc09f4e2.zip
chfn, chsh: use readline(3) to receive user input
The readline offers editing capabilities while the user is entering the line, unlike fgets(3) and getline(3) that were used earlier. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/chsh.c')
-rw-r--r--login-utils/chsh.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 979a287fe..1fb377593 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -57,6 +57,11 @@
# include "auth.h"
#endif
+#ifdef HAVE_LIBREADLINE
+# define _FUNCTION_DEF
+# include <readline/readline.h>
+#endif
+
struct sinfo {
char *username;
char *shell;
@@ -173,14 +178,18 @@ static char *ask_new_shell(char *question, char *oldshell)
{
int len;
char *ans = NULL;
+#ifndef HAVE_LIBREADLINE
size_t dummy = 0;
- ssize_t sz;
+#endif
if (!oldshell)
oldshell = "";
printf("%s [%s]: ", question, oldshell);
- sz = getline(&ans, &dummy, stdin);
- if (sz == -1)
+#ifdef HAVE_LIBREADLINE
+ if ((ans = readline(NULL)) == NULL)
+#else
+ if (getline(&ans, &dummy, stdin) < 0)
+#endif
return NULL;
/* remove the newline at the end of ans. */
ltrim_whitespace((unsigned char *) ans);