if (term != NULL && term[0] != '\0')
{
struct { char buf[1024]; char canary[4]; } termcapbuf;
- struct { char buf[1024]; char canary[4]; } termentrybuf;
int retval;
- char *termentryptr;
/* Call tgetent, being defensive against buffer overflow. */
memcpy (termcapbuf.canary, "CnRy", 4);
/* Buffer overflow! */
abort ();
- /* Prepare for calling tgetstr, being defensive against buffer
- overflow. ncurses' tgetstr() supports a second argument NULL,
- but NetBSD's tgetstr() doesn't. */
- memcpy (termentrybuf.canary, "CnRz", 4);
- #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr)
-
- /* Retrieve particular values depending on the terminal type. */
- stream->max_colors = tgetnum ("Co");
- stream->no_color_video = tgetnum ("nc");
- stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP));
- stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP));
- stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP));
- stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP));
- stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP));
- stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP));
- stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP));
- stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP));
- stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP));
- stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP));
- stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP));
+ if (retval > 0)
+ {
+ struct { char buf[1024]; char canary[4]; } termentrybuf;
+ char *termentryptr;
+
+ /* Prepare for calling tgetstr, being defensive against buffer
+ overflow. ncurses' tgetstr() supports a second argument NULL,
+ but NetBSD's tgetstr() doesn't. */
+ memcpy (termentrybuf.canary, "CnRz", 4);
+ #define TEBP ((termentryptr = termentrybuf.buf), &termentryptr)
+
+ /* Retrieve particular values depending on the terminal type. */
+ stream->max_colors = tgetnum ("Co");
+ stream->no_color_video = tgetnum ("nc");
+ stream->set_a_foreground = xstrdup0 (tgetstr ("AF", TEBP));
+ stream->set_foreground = xstrdup0 (tgetstr ("Sf", TEBP));
+ stream->set_a_background = xstrdup0 (tgetstr ("AB", TEBP));
+ stream->set_background = xstrdup0 (tgetstr ("Sb", TEBP));
+ stream->orig_pair = xstrdup0 (tgetstr ("op", TEBP));
+ stream->enter_bold_mode = xstrdup0 (tgetstr ("md", TEBP));
+ stream->enter_italics_mode = xstrdup0 (tgetstr ("ZH", TEBP));
+ stream->exit_italics_mode = xstrdup0 (tgetstr ("ZR", TEBP));
+ stream->enter_underline_mode = xstrdup0 (tgetstr ("us", TEBP));
+ stream->exit_underline_mode = xstrdup0 (tgetstr ("ue", TEBP));
+ stream->exit_attribute_mode = xstrdup0 (tgetstr ("me", TEBP));
#ifdef __BEOS__
- /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB" it
- contains balues in terminfo syntax but the system's tparam() function
- understands only the termcap syntax. */
- if (stream->set_a_foreground != NULL
- && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0)
- {
- free (stream->set_a_foreground);
- stream->set_a_foreground = xstrdup ("\033[3%dm");
- }
- if (stream->set_a_background != NULL
- && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0)
- {
- free (stream->set_a_background);
- stream->set_a_background = xstrdup ("\033[4%dm");
- }
+ /* The BeOS termcap entry for "beterm" is broken: For "AF" and "AB"
+ it contains balues in terminfo syntax but the system's tparam()
+ function understands only the termcap syntax. */
+ if (stream->set_a_foreground != NULL
+ && strcmp (stream->set_a_foreground, "\033[3%p1%dm") == 0)
+ {
+ free (stream->set_a_foreground);
+ stream->set_a_foreground = xstrdup ("\033[3%dm");
+ }
+ if (stream->set_a_background != NULL
+ && strcmp (stream->set_a_background, "\033[4%p1%dm") == 0)
+ {
+ free (stream->set_a_background);
+ stream->set_a_background = xstrdup ("\033[4%dm");
+ }
#endif
- /* Done with tgetstr. Detect possible buffer overflow. */
- #undef TEBP
- if (memcmp (termentrybuf.canary, "CnRz", 4) != 0)
- /* Buffer overflow! */
- abort ();
+ /* Done with tgetstr. Detect possible buffer overflow. */
+ #undef TEBP
+ if (memcmp (termentrybuf.canary, "CnRz", 4) != 0)
+ /* Buffer overflow! */
+ abort ();
+ }
}
/* Infer the capabilities. */