On Sat, Jun 11, 2016 at 03:03:14PM +0200, Anton Lindqvist wrote:
> The setupterm(3) manual states:
> 
> > If errret is not null, then setupterm returns OK or ERR and stores a
> > status value in the integer pointed to by errret.  
> > ...
> > If errret is null, setupterm prints an error message upon finding an
> > error and exits.     
> 
> Since less(1) passes NULL, it will not return on error but instead
> terminate the program.
> 
> Checking the returned value against ERR requires including curses.h
> which causes a naming conflict with the existing beep function. I
> therefore kept the condition as is.
> 
> The error message is borrowed from setupterm when errret is NULL and
> does currently not distinguish between error code 0 and -1.
> 
> Should patches to less(1) be submitted upstream[1] instead? If true, I
> apologize for the noise.
> 
> [1] https://github.com/gdamore/less-fork
> 
> Index: screen.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/less/screen.c,v
> retrieving revision 1.23
> diff -u -p -u -r1.23 screen.c
> --- screen.c  16 Mar 2016 15:36:26 -0000      1.23
> +++ screen.c  11 Jun 2016 09:12:05 -0000
> @@ -16,6 +16,7 @@
>  
>  #include <sys/ioctl.h>
>  
> +#include <err.h>
>  #include <term.h>
>  #include <termios.h>
>  
> @@ -266,6 +267,7 @@ get_term(void)
>  {
>       char *t1, *t2;
>       char *term;
> +     int  err;
>  
>       /*
>        * Find out what kind of terminal this is.
> @@ -274,8 +276,11 @@ get_term(void)
>               term = DEFAULT_TERM;
>       hardcopy = 0;
>  
> -     if (setupterm(term, 1, NULL) < 0) {
> -             hardcopy = 1;
> +     if (setupterm(term, 1, &err) < 0) {
> +             if (err == 1)
> +                     hardcopy = 1;
> +             else
> +                     errx(1, "%s: unknown terminal type", term);
>       }
>       if (hard_copy == 1)
>               hardcopy = 1;

The patch has been merged upstream[1].

[1] https://github.com/gdamore/less-fork/commit/b5bc797

--
:wq

Reply via email to