summaryrefslogtreecommitdiffstats
path: root/source/lib/readline.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-01-19 22:54:07 +0000
committerJeremy Allison <jra@samba.org>2002-01-19 22:54:07 +0000
commit1918165601bfb7ad69880922e0885a93a2afaa5a (patch)
tree386e944dd2548107a56b88223bb6b25691fbff82 /source/lib/readline.c
parent3f57b0768c91d6441cdcb20bf7f4c0e3c312a76d (diff)
downloadsamba-1918165601bfb7ad69880922e0885a93a2afaa5a.tar.gz
samba-1918165601bfb7ad69880922e0885a93a2afaa5a.tar.xz
samba-1918165601bfb7ad69880922e0885a93a2afaa5a.zip
Readline has problems on non tty fd's. Use readline replacement to in cases
where stdin is !isatty to allow stripts to work. Jeremy.
Diffstat (limited to 'source/lib/readline.c')
-rw-r--r--source/lib/readline.c65
1 files changed, 39 insertions, 26 deletions
diff --git a/source/lib/readline.c b/source/lib/readline.c
index c030ea276f0..dd2793df661 100644
--- a/source/lib/readline.c
+++ b/source/lib/readline.c
@@ -23,45 +23,58 @@
#include "includes.h"
/****************************************************************************
-display the prompt and wait for input. Call callback() regularly
+ Display the prompt and wait for input. Call callback() regularly
****************************************************************************/
+
char *smb_readline(char *prompt, void (*callback)(void),
char **(completion_fn)(const char *text, int start, int end))
{
char *ret;
+ int fd = fileno(stdin);
+
#if HAVE_LIBREADLINE
- if (completion_fn) {
- rl_attempted_completion_function = completion_fn;
- }
- if (callback) rl_event_hook = (Function *)callback;
- ret = readline(prompt);
- if (ret && *ret) add_history(ret);
- return ret;
-#else
- fd_set fds;
- extern FILE *dbf;
- static pstring line;
- struct timeval timeout;
- int fd = fileno(stdin);
+ /*
+ * Current versions of readline on Linux seem to have
+ * problems with EOF on a pipe.
+ */
+
+ if (isatty(fd)) {
+ if (completion_fn)
+ rl_attempted_completion_function = completion_fn;
- fprintf(dbf, "%s", prompt);
- fflush(dbf);
+ if (callback)
+ rl_event_hook = (Function *)callback;
+ ret = readline(prompt);
+ if (ret && *ret)
+ add_history(ret);
+ return ret;
+ } else
+#endif
+ {
+ fd_set fds;
+ extern FILE *dbf;
+ static pstring line;
+ struct timeval timeout;
- while (1) {
- timeout.tv_sec = 5;
- timeout.tv_usec = 0;
+ fprintf(dbf, "%s", prompt);
+ fflush(dbf);
- FD_ZERO(&fds);
- FD_SET(fd,&fds);
+ while (1) {
+ timeout.tv_sec = 5;
+ timeout.tv_usec = 0;
+
+ FD_ZERO(&fds);
+ FD_SET(fd,&fds);
- if (sys_select_intr(fd+1,&fds,&timeout) == 1) {
- ret = fgets(line, sizeof(line), stdin);
- return ret;
+ if (sys_select_intr(fd+1,&fds,&timeout) == 1) {
+ ret = fgets(line, sizeof(line), stdin);
+ return ret;
+ }
+ if (callback)
+ callback();
}
- if (callback) callback();
}
-#endif
}
/****************************************************************************