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
  2. tty_destroy_winch_pipe

   1 /*
   2    Internal stuff of the terminal controlling library.
   3 
   4    Copyright (C) 2019-2024
   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 <glib-unix.h>
  40 
  41 #include "tty-internal.h"
  42 
  43 /*** global variables ****************************************************************************/
  44 
  45 /* pipe to handle SIGWINCH */
  46 int sigwinch_pipe[2];
  47 
  48 /*** file scope macro definitions ****************************************************************/
  49 
  50 /*** global variables ****************************************************************************/
  51 
  52 /*** file scope type declarations ****************************************************************/
  53 
  54 /*** file scope variables ************************************************************************/
  55 
  56 /* --------------------------------------------------------------------------------------------- */
  57 /*** file scope functions ************************************************************************/
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 /*** public functions ****************************************************************************/
  62 /* --------------------------------------------------------------------------------------------- */
  63 
  64 void
  65 tty_create_winch_pipe (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  66 {
  67     GError *mcerror = NULL;
  68 
  69     if (!g_unix_open_pipe (sigwinch_pipe, FD_CLOEXEC, &mcerror))
  70     {
  71         fprintf (stderr, _("\nCannot create pipe for SIGWINCH: %s (%d)\n"),
  72                  mcerror->message, mcerror->code);
  73         g_error_free (mcerror);
  74         exit (EXIT_FAILURE);
  75     }
  76 
  77     /* If we read from an empty pipe, then read(2) will block until data is available.
  78      * If we write to a full pipe, then write(2) blocks until sufficient data has been read
  79      * from the pipe to allow the write to complete..
  80      * Therefore, use nonblocking I/O.
  81      */
  82     if (!g_unix_set_fd_nonblocking (sigwinch_pipe[0], TRUE, &mcerror))
  83     {
  84         fprintf (stderr, _("\nCannot configure write end of SIGWINCH pipe: %s (%d)\n"),
  85                  mcerror->message, mcerror->code);
  86         g_error_free (mcerror);
  87         tty_destroy_winch_pipe ();
  88         exit (EXIT_FAILURE);
  89     }
  90 
  91     if (!g_unix_set_fd_nonblocking (sigwinch_pipe[1], TRUE, &mcerror))
  92     {
  93         fprintf (stderr, _("\nCannot configure read end of SIGWINCH pipe: %s (%d)\n"),
  94                  mcerror->message, mcerror->code);
  95         g_error_free (mcerror);
  96         tty_destroy_winch_pipe ();
  97         exit (EXIT_FAILURE);
  98     }
  99 }
 100 
 101 /* --------------------------------------------------------------------------------------------- */
 102 
 103 void
 104 tty_destroy_winch_pipe (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 105 {
 106     (void) close (sigwinch_pipe[0]);
 107     (void) close (sigwinch_pipe[1]);
 108 }
 109 
 110 /* --------------------------------------------------------------------------------------------- */

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