[vlc-devel] [vlc-commits] help: use direct ioctl() rather than spawning stty to get console width

Rafaël Carré funman at videolan.org
Sat Oct 26 12:02:30 CEST 2013


Hello,

2013/10/25 Rémi Denis-Courmont <git at videolan.org>:
> vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Oct 25 18:49:27 2013 +0300| [c8d46da15aeb0a1d7120de31017b81de869dcdd9] | committer: Rémi Denis-Courmont
>
> help: use direct ioctl() rather than spawning stty to get console width
>
>> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c8d46da15aeb0a1d7120de31017b81de869dcdd9
> ---
>
>  src/config/help.c |   56 ++++++++++++++++++++++++++---------------------------
>  1 file changed, 27 insertions(+), 29 deletions(-)
>
> diff --git a/src/config/help.c b/src/config/help.c
> index 02f07bb..55cca4b 100644
> --- a/src/config/help.c
> +++ b/src/config/help.c
> @@ -41,13 +41,39 @@ static void PauseConsole (void);
>  # define ShowConsole() (void)0
>  # define PauseConsole() (void)0
>  # include <unistd.h>
> +# include <sys/ioctl.h>
>  #endif
>
>  static void Help (vlc_object_t *, const char *);
>  static void Usage (vlc_object_t *, const char *);
>  static void Version (void);
>  static void ListModules (vlc_object_t *, bool);
> -static int ConsoleWidth (void);
> +
> +/**
> + * Returns the console width or a best guess.
> + */
> +static unsigned ConsoleWidth(void)
> +{
> +#ifdef TIOCGWINSZ
> +    struct winsize ws;

This breaks on android:
../../src/config/help.c:61:20: error: storage size of 'ws' isn't known

http://buildbot.videolan.org/builders/android-bin-armv7/builds/106/steps/Build%20Contribs/logs/stdio

Please fix, the struct is in termio.h although you might want to use
another interface:

       Use of ioctl makes for nonportable programs.  Use the POSIX interface
       described in termios(3) whenever possible.

> +
> +    if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
> +        return ws.ws_col;
> +#endif

-- 
Rafaël Carré



More information about the vlc-devel mailing list