From 0f75ef88d72d061c5e3b5fca2029c0816c61d571 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Wed, 1 Mar 2000 20:53:05 +0000 Subject: [PATCH] (readline): be more liberal in what we accept from el_gets. if count == 0 -> interpret it as EOF. also copy the string first and then cut of the newline, it's cleaner git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7988 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/editline/edit_compat.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/editline/edit_compat.c b/lib/editline/edit_compat.c index c281dae13..9d60edfb7 100644 --- a/lib/editline/edit_compat.c +++ b/lib/editline/edit_compat.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan + * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -73,7 +73,8 @@ readline(const char* prompt) HistEvent ev; #endif int count; - char *ret; + const char *str; + if(e == NULL){ #ifdef EL_INIT_FOUR e = el_init("", stdin, stdout, stderr); @@ -91,11 +92,16 @@ readline(const char* prompt) el_set(e, EL_EDITOR, "emacs"); /* XXX? */ } pr = prompt ? prompt : ""; - ret = (char*)el_gets(e, &count); - if (ret) { + str = el_gets(e, &count); + if (str && count > 0) { + char *ret = strdup (str); + + if (ret == NULL) + return NULL; + if (ret[strlen(ret) - 1] == '\n') ret[strlen(ret) - 1] = '\0'; - return strdup(ret); + return ret; } return NULL; }