netutil.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Network utilities for the Midnight Commander Virtual File System.
  3. Copyright (C) 1995-2017
  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. /*** file scope variables ************************************************************************/
  32. /*** file scope functions ************************************************************************/
  33. /* --------------------------------------------------------------------------------------------- */
  34. static void
  35. sig_pipe (int unused)
  36. {
  37. (void) unused;
  38. got_sigpipe = 1;
  39. }
  40. /* --------------------------------------------------------------------------------------------- */
  41. /*** public functions ****************************************************************************/
  42. /* --------------------------------------------------------------------------------------------- */
  43. void
  44. tcp_init (void)
  45. {
  46. static gboolean initialized = FALSE;
  47. struct sigaction sa;
  48. if (initialized)
  49. return;
  50. got_sigpipe = 0;
  51. memset (&sa, 0, sizeof (sa));
  52. sa.sa_handler = sig_pipe;
  53. sigemptyset (&sa.sa_mask);
  54. sigaction (SIGPIPE, &sa, NULL);
  55. initialized = TRUE;
  56. }
  57. /* --------------------------------------------------------------------------------------------- */