diff options
| author | Paul Eggert | 2011-07-19 13:37:27 -0700 |
|---|---|---|
| committer | Paul Eggert | 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 emacs-63cf7836ae7616ce91d7eeaeac997d71609e191b.zip | |
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/>. */ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | #include <config.h> | 21 | #include <config.h> |
| 22 | #include <errno.h> | ||
| 22 | #include <stdio.h> | 23 | #include <stdio.h> |
| 23 | #include <setjmp.h> | 24 | #include <setjmp.h> |
| 24 | 25 | ||
| @@ -236,8 +237,9 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 236 | int allow_props, int inherit_input_method) | 237 | int allow_props, int inherit_input_method) |
| 237 | { | 238 | { |
| 238 | ptrdiff_t size, len; | 239 | ptrdiff_t size, len; |
| 239 | char *line, *s; | 240 | char *line; |
| 240 | Lisp_Object val; | 241 | Lisp_Object val; |
| 242 | int c; | ||
| 241 | 243 | ||
| 242 | fprintf (stdout, "%s", SDATA (prompt)); | 244 | fprintf (stdout, "%s", SDATA (prompt)); |
| 243 | fflush (stdout); | 245 | fflush (stdout); |
| @@ -246,22 +248,30 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, | |||
| 246 | size = 100; | 248 | size = 100; |
| 247 | len = 0; | 249 | len = 0; |
| 248 | line = (char *) xmalloc (size); | 250 | line = (char *) xmalloc (size); |
| 249 | while ((s = fgets (line + len, size - len, stdin)) != NULL | 251 | |
| 250 | && (len = strlen (line), | 252 | while ((c = getchar ()) != '\n') |
| 251 | len == size - 1 && line[len - 1] != '\n')) | ||
| 252 | { | 253 | { |
| 253 | if (STRING_BYTES_BOUND / 2 < size) | 254 | if (c < 0) |
| 254 | memory_full (SIZE_MAX); | 255 | { |
| 255 | size *= 2; | 256 | if (errno != EINTR) |
| 256 | line = (char *) xrealloc (line, size); | 257 | break; |
| 258 | } | ||
| 259 | else | ||
| 260 | { | ||
| 261 | if (len == size) | ||
| 262 | { | ||
| 263 | if (STRING_BYTES_BOUND / 2 < size) | ||
| 264 | memory_full (SIZE_MAX); | ||
| 265 | size *= 2; | ||
| 266 | line = (char *) xrealloc (line, size); | ||
| 267 | } | ||
| 268 | line[len++] = c; | ||
| 269 | } | ||
| 257 | } | 270 | } |
| 258 | 271 | ||
| 259 | if (s) | 272 | if (len) |
| 260 | { | 273 | { |
| 261 | char *nl = strchr (line, '\n'); | 274 | val = make_string (line, len); |
| 262 | if (nl) | ||
| 263 | *nl = '\0'; | ||
| 264 | val = build_string (line); | ||
| 265 | xfree (line); | 275 | xfree (line); |
| 266 | } | 276 | } |
| 267 | else | 277 | else |