netutil.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Network utilities for the Midnight Commander Virtual File System.
  3. Copyright (C) 1995-2024
  4. Free Software Foundation, Inc.
  5. This file is part of the Midnight Commander.
  6. The Midnight Commander is free software: you can redistribute it
  7. and/or modify it under the terms of the GNU General Public License as
  8. published by the Free Software Foundation, either version 3 of the License,
  9. or (at your option) any later version.
  10. The Midnight Commander is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file
  19. * \brief Source: Virtual File System: Network utilities
  20. */
  21. #include <config.h>
  22. #include <stdlib.h>
  23. #include <signal.h>
  24. #include <string.h> /* memset() */
  25. #include "lib/global.h"
  26. #include "netutil.h"
  27. /*** global variables ****************************************************************************/
  28. SIG_ATOMIC_VOLATILE_T got_sigpipe = 0;
  29. /*** file scope macro definitions ****************************************************************/
  30. /*** file scope type declarations ****************************************************************/
  31. /*** forward declarations (file scope functions) *************************************************/
  32. /*** file scope variables ************************************************************************/
  33. /* --------------------------------------------------------------------------------------------- */
  34. /*** file scope functions ************************************************************************/
  35. /* --------------------------------------------------------------------------------------------- */
  36. static void
  37. sig_pipe (int unused)
  38. {
  39. (void) unused;
  40. got_sigpipe = 1;
  41. }
  42. /* --------------------------------------------------------------------------------------------- */
  43. /*** public functions ****************************************************************************/
  44. /* --------------------------------------------------------------------------------------------- */
  45. void
  46. tcp_init (void)
  47. {
  48. static gboolean initialized = FALSE;
  49. struct sigaction sa;
  50. if (initialized)
  51. return;
  52. got_sigpipe = 0;
  53. memset (&sa, 0, sizeof (sa));
  54. sa.sa_handler = sig_pipe;
  55. sigemptyset (&sa.sa_mask);
  56. sigaction (SIGPIPE, &sa, NULL);
  57. initialized = TRUE;
  58. }
  59. /* --------------------------------------------------------------------------------------------- */