root/lib/tty/tty-internal.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. tty_create_winch_pipe

   1 /*
   2    Internal stuff of the terminal controlling library.
   3 
   4    Copyright (C) 2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Andrew Borodin <aborodin@vmail.ru>, 2019.
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 /** \file
  27  *  \brief Source: internal stuff of the terminal controlling library.
  28  */
  29 
  30 #include <config.h>
  31 
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <unistd.h>
  35 #include <fcntl.h>
  36 
  37 #include "lib/global.h"
  38 
  39 #include "tty-internal.h"
  40 
  41 /*** global variables ****************************************************************************/
  42 
  43 /* pipe to handle SIGWINCH */
  44 int sigwinch_pipe[2];
  45 
  46 /*** file scope macro definitions ****************************************************************/
  47 
  48 /*** global variables ****************************************************************************/
  49 
  50 /*** file scope type declarations ****************************************************************/
  51 
  52 /*** file scope variables ************************************************************************/
  53 
  54 /* --------------------------------------------------------------------------------------------- */
  55 /*** file scope functions ************************************************************************/
  56 /* --------------------------------------------------------------------------------------------- */
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 /*** public functions ****************************************************************************/
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 void
  63 tty_create_winch_pipe (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     int fd_flags;
  66 
  67     if (pipe (sigwinch_pipe) == -1)
  68     {
  69         perror (_("Cannot create pipe for SIGWINCH"));
  70         exit (EXIT_FAILURE);
  71     }
  72 
  73     /* If we read from an empty pipe, then read(2) will block until data is available.
  74      * If we write to a full pipe, then write(2) blocks until sufficient data has been read
  75      * from the pipe to allow the write to complete..
  76      * Therefore, use nonblocking I/O.
  77      */
  78 
  79     fd_flags = fcntl (sigwinch_pipe[0], F_GETFL, NULL);
  80     if (fd_flags != -1)
  81     {
  82         fd_flags |= O_NONBLOCK | O_CLOEXEC;
  83         fd_flags = fcntl (sigwinch_pipe[0], F_SETFL, fd_flags);
  84     }
  85     if (fd_flags == -1)
  86     {
  87         perror (_("Cannot configure write end of SIGWINCH pipe"));
  88         exit (EXIT_FAILURE);
  89     }
  90 
  91     fd_flags = fcntl (sigwinch_pipe[1], F_GETFL, NULL);
  92     if (fd_flags != -1)
  93     {
  94         fd_flags |= O_NONBLOCK | O_CLOEXEC;
  95         fd_flags = fcntl (sigwinch_pipe[1], F_SETFL, fd_flags);
  96     }
  97     if (fd_flags == -1)
  98     {
  99         perror (_("Cannot configure read end of SIGWINCH pipe"));
 100         exit (EXIT_FAILURE);
 101     }
 102 }
 103 
 104 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */