diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-07-19 13:37:27 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-07-19 13:37:27 -0700 |
commit | 63cf7836ae7616ce91d7eeaeac997d71609e191b (patch) | |
tree | 801b7c438808303fd47cf19aec1d899c78c2472f /src/minibuf.c | |
parent | 7403ff044d82d390bdc4cdd3954448daedcd4571 (diff) | |
parent | 0d8de0fd0a5a63cc9558b5c99f9c7f1ddcaf338a (diff) | |
download | emacs-63cf7836ae7616ce91d7eeaeac997d71609e191b.tar.gz |
Merge from intsign.
Diffstat (limited to 'src/minibuf.c')
-rw-r--r-- | src/minibuf.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index 951bf028c38..eb564a10ec6 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -19,6 +19,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> +#include <errno.h> #include <stdio.h> #include <setjmp.h> @@ -236,8 +237,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, int allow_props, int inherit_input_method) { ptrdiff_t size, len; - char *line, *s; + char *line; Lisp_Object val; + int c; fprintf (stdout, "%s", SDATA (prompt)); fflush (stdout); @@ -246,22 +248,30 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, size = 100; len = 0; line = (char *) xmalloc (size); - while ((s = fgets (line + len, size - len, stdin)) != NULL - && (len = strlen (line), - len == size - 1 && line[len - 1] != '\n')) + + while ((c = getchar ()) != '\n') { - if (STRING_BYTES_BOUND / 2 < size) - memory_full (SIZE_MAX); - size *= 2; - line = (char *) xrealloc (line, size); + if (c < 0) + { + if (errno != EINTR) + break; + } + else + { + if (len == size) + { + if (STRING_BYTES_BOUND / 2 < size) + memory_full (SIZE_MAX); + size *= 2; + line = (char *) xrealloc (line, size); + } + line[len++] = c; + } } - if (s) + if (len) { - char *nl = strchr (line, '\n'); - if (nl) - *nl = '\0'; - val = build_string (line); + val = make_string (line, len); xfree (line); } else |