netutil.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "lib/util.h"
  27. #include "netutil.h"
  28. /*** global variables ****************************************************************************/
  29. SIG_ATOMIC_VOLATILE_T got_sigpipe = 0;
  30. /*** file scope macro definitions ****************************************************************/
  31. /*** file scope type declarations ****************************************************************/
  32. /*** forward declarations (file scope functions) *************************************************/
  33. /*** file scope variables ************************************************************************/
  34. /* --------------------------------------------------------------------------------------------- */
  35. /*** file scope functions ************************************************************************/
  36. /* --------------------------------------------------------------------------------------------- */
  37. static void
  38. sig_pipe (int unused)
  39. {
  40. (void) unused;
  41. got_sigpipe = 1;
  42. }
  43. /* --------------------------------------------------------------------------------------------- */
  44. /*** public functions ****************************************************************************/
  45. /* --------------------------------------------------------------------------------------------- */
  46. void
  47. tcp_init (void)
  48. {
  49. static gboolean initialized = FALSE;
  50. struct sigaction sa;
  51. if (initialized)
  52. return;
  53. got_sigpipe = 0;
  54. memset (&sa, 0, sizeof (sa));
  55. sa.sa_handler = sig_pipe;
  56. sigemptyset (&sa.sa_mask);
  57. my_sigaction (SIGPIPE, &sa, NULL);
  58. initialized = TRUE;
  59. }
  60. /* --------------------------------------------------------------------------------------------- */