Update hints translations from Transifex
[midnight-commander.git] / lib / tty / tty-internal.c
blobc79301db989a61cc18e5ed9a74ce0533190658f8
1 /*
2 Internal stuff of the terminal controlling library.
4 Copyright (C) 2019-2023
5 Free Software Foundation, Inc.
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 2019.
10 This file is part of the Midnight Commander.
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.
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.
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/>.
26 /** \file
27 * \brief Source: internal stuff of the terminal controlling library.
30 #include <config.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <fcntl.h>
37 #include "lib/global.h"
39 #include <glib-unix.h>
41 #include "tty-internal.h"
43 /*** global variables ****************************************************************************/
45 /* pipe to handle SIGWINCH */
46 int sigwinch_pipe[2];
48 /*** file scope macro definitions ****************************************************************/
50 /*** global variables ****************************************************************************/
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 /* --------------------------------------------------------------------------------------------- */
57 /*** file scope functions ************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
60 /* --------------------------------------------------------------------------------------------- */
61 /*** public functions ****************************************************************************/
62 /* --------------------------------------------------------------------------------------------- */
64 void
65 tty_create_winch_pipe (void)
67 GError *mcerror = NULL;
69 if (!g_unix_open_pipe (sigwinch_pipe, FD_CLOEXEC, &mcerror))
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);
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.
82 if (!g_unix_set_fd_nonblocking (sigwinch_pipe[0], TRUE, &mcerror))
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);
91 if (!g_unix_set_fd_nonblocking (sigwinch_pipe[1], TRUE, &mcerror))
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);
101 /* --------------------------------------------------------------------------------------------- */
103 void
104 tty_destroy_winch_pipe (void)
106 (void) close (sigwinch_pipe[0]);
107 (void) close (sigwinch_pipe[1]);
110 /* --------------------------------------------------------------------------------------------- */