Menu

#435 flac command line program does not get console size if termios.h defines TIOCGWINSZ

1.3.1
closed-fixed
Erik
None
5
2016-01-26
2016-01-19
Max
No

The flac command line utility does not actually get the width of the terminal, but just assumes it to be 80 characters, if termios.h on your system defines TIOCGWINSZ. In src/flac/utils.c, there's the following code:

int get_console_width(void)
{
        int width = 0;
#if defined _WIN32
        width = win_get_console_width();
#elif defined __EMX__
        int s[2];
        _scrsize (s);
        width = s[0];
#elif defined GWINSZ_IN_SYS_IOCTL
        struct winsize w;
        if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1)
            width = w.ws_col;
#endif
    if (width <= 0)
            width = 80;
    return width;
}

During configuration, GWINSZ_IN_SYS_IOCTL is defined if termios.h on your system does NOT define TIOCGWINSZ, in which case sys/ioctl.h must be included. That means (on non-WIN32 systems), the code to get the actual window size is compiled only if TIOCGWINSZ does not appear in termios.h.

Contact: maximilian.fillinger@uni-duesseldorf.de

Discussion

  • Erik

    Erik - 2016-01-20
    • assigned_to: Erik
     
  • Erik

    Erik - 2016-01-20

    All I can tell from your report is that you are not on Windows. However, it would help immensely if you could tell exactly what non-Windows OS you are on.

     
  • Max

    Max - 2016-01-20

    Sorry, it seems I got ahead of myself. I'm running OpenBSD-current.

     
  • lvqcl

    lvqcl - 2016-01-25

    From https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Particular-Headers.html

    If the use of TIOCGWINSZ requires < sys/ioctl.h>, then define GWINSZ_IN_SYS_IOCTL. Otherwise TIOCGWINSZ can be found in <termios.h>.

    Use:

         #ifdef HAVE_TERMIOS_H
         # include <termios.h>
         #endif
    
         #ifdef GWINSZ_IN_SYS_IOCTL
         # include <sys/ioctl.h>
         #endif
    

    The current code in get_console_width() doesn't work if TIOCGWINSZ is defined in termios.h and GWINSZ_IN_SYS_IOCTL is not defined.

     
  • Erik

    Erik - 2016-01-25

    I was going to set up an OpenBSD VM to get to the bottom of this. Without actually testing this for myself I'm not sure what the correct solution is.

    I would however be happy to accept a patch that fixes OpenBSD without breaking anything else.

     
  • Max

    Max - 2016-01-25

    Couldn't one just replace elif defined GWINSZ_IN_SYS_IOCTL with elif defined TIOCGWINSZ in that function? At that point, it shouldn't matter where that constant comes from, right?

    I just tried that on OpenBSD and it works. Tomorrow, I'll check if it breaks anything on Linux Mint. If not, I'll send a diff to the dev mailinglist. Ok?

     
  • Erik

    Erik - 2016-01-25

    If you have a patch that works on OpenBSD, please post it. I can test on Linux.

     
  • Erik

    Erik - 2016-01-26
    • status: open --> closed-fixed
     
  • Erik

    Erik - 2016-01-26

    Ok, got an OpenBSD VM set up. The suggested fix works for Linux and OpenBSD.

    Commit is:

    commit 3ff49e606dfc67864eb61e55fa9a6ff4722d88a4
    Author: Erik de Castro Lopo <erikd@mega-nerd.com>
    Date:   Tue Jan 26 12:50:44 2016 +1100
    
    src/flac/utils.c: Fix for OpenBSD
    
    OpenBSD defineds `TIOCGWINSZ` in `termios.h` which is already being
    included, so this fix should work on most POSIX systems.
    
    Closes: https://sourceforge.net/p/flac/bugs/435/
    
     

Log in to post a comment.