From 590bd46743151a55ba68a7d211f82b2485c57d3a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Jul 2011 10:33:06 -0700 Subject: [PATCH] Port to OpenBSD. See http://lists.gnu.org/archive/html/emacs-devel/2011-07/msg00688.html and the surrounding thread. * minibuf.c (read_minibuf_noninteractive): Rewrite to use getchar rather than fgets, and retry after EINTR. Otherwise, 'emacs --batch -f byte-compile-file' fails on OpenBSD if an inactivity timer goes off. * s/openbsd.h (BROKEN_SIGIO): Define. * unexelf.c (unexec) [__OpenBSD__]: Don't update the .mdebug section of the Alpha COFF symbol table. --- src/ChangeLog | 13 +++++++++++++ src/minibuf.c | 36 +++++++++++++++++++++++------------- src/s/openbsd.h | 6 +++++- src/unexelf.c | 4 ++-- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ccb2d1dc907..e098e536efb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2011-07-19 Paul Eggert + + Port to OpenBSD. + See http://lists.gnu.org/archive/html/emacs-devel/2011-07/msg00688.html + and the surrounding thread. + * minibuf.c (read_minibuf_noninteractive): Rewrite to use getchar + rather than fgets, and retry after EINTR. Otherwise, 'emacs + --batch -f byte-compile-file' fails on OpenBSD if an inactivity + timer goes off. + * s/openbsd.h (BROKEN_SIGIO): Define. + * unexelf.c (unexec) [__OpenBSD__]: + Don't update the .mdebug section of the Alpha COFF symbol table. + 2011-07-19 Lars Magne Ingebrigtsen * lread.c (syms_of_lread): Clarify when `lexical-binding' is used diff --git a/src/minibuf.c b/src/minibuf.c index cf37c337be4..7e59cf157b5 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -19,6 +19,7 @@ along with GNU Emacs. If not, see . */ #include +#include #include #include @@ -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 diff --git a/src/s/openbsd.h b/src/s/openbsd.h index 175d61dc9c9..0a8bab2290f 100644 --- a/src/s/openbsd.h +++ b/src/s/openbsd.h @@ -1,5 +1,9 @@ /* System file for openbsd. */ -/* The same as NetBSD. Note there are differences in configure. */ +/* Nearly the same as NetBSD. Note there are differences in configure. */ #include "netbsd.h" +/* The symbol SIGIO is defined, but the feature doesn't work in the + way Emacs needs it to. See + . */ +#define BROKEN_SIGIO diff --git a/src/unexelf.c b/src/unexelf.c index 951e7c0eea6..a169ffcb5c8 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -1053,7 +1053,7 @@ temacs: memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, NEW_SECTION_H (nn).sh_size); -#ifdef __alpha__ +#if defined __alpha__ && !defined __OpenBSD__ /* Update Alpha COFF symbol table: */ if (strcmp (old_section_names + OLD_SECTION_H (n).sh_name, ".mdebug") == 0) @@ -1072,7 +1072,7 @@ temacs: symhdr->cbRfdOffset += new_data2_size; symhdr->cbExtOffset += new_data2_size; } -#endif /* __alpha__ */ +#endif /* __alpha__ && !__OpenBSD__ */ #if defined (_SYSTYPE_SYSV) if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG -- 2.39.2