maint.mk: fix "release" target to build _version
[gnulib.git] / lib / sigprocmask.c
index d5ce8f0..8de3777 100644 (file)
@@ -1,5 +1,5 @@
 /* POSIX compatible signal blocking.
 /* POSIX compatible signal blocking.
-   Copyright (C) 2006-2009 Free Software Foundation, Inc.
+   Copyright (C) 2006-2013 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
 #include <stdint.h>
 #include <stdlib.h>
 
 #include <stdint.h>
 #include <stdlib.h>
 
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
 /* We assume that a platform without POSIX signal blocking functions
    also does not have the POSIX sigaction() function, only the
    signal() function.  We also assume signal() has SysV semantics,
    where any handler is uninstalled prior to being invoked.  This is
 /* We assume that a platform without POSIX signal blocking functions
    also does not have the POSIX sigaction() function, only the
    signal() function.  We also assume signal() has SysV semantics,
    where any handler is uninstalled prior to being invoked.  This is
-   true for Woe32 platforms.  */
+   true for native Windows platforms.  */
 
 /* We use raw signal(), but also provide a wrapper rpl_signal() so
    that applications can query or change a blocked signal.  */
 
 /* We use raw signal(), but also provide a wrapper rpl_signal() so
    that applications can query or change a blocked signal.  */
 
 typedef void (*handler_t) (int);
 
 
 typedef void (*handler_t) (int);
 
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static handler_t
+signal_nothrow (int sig, handler_t handler)
+{
+  handler_t result;
+
+  TRY_MSVC_INVAL
+    {
+      result = signal (sig, handler);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = SIG_ERR;
+      errno = EINVAL;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+# define signal signal_nothrow
+#endif
+
 /* Handling of gnulib defined signals.  */
 
 #if GNULIB_defined_SIGPIPE
 /* Handling of gnulib defined signals.  */
 
 #if GNULIB_defined_SIGPIPE
@@ -80,6 +106,7 @@ ext_signal (int sig, handler_t handler)
       return signal (sig, handler);
     }
 }
       return signal (sig, handler);
     }
 }
+# undef signal
 # define signal ext_signal
 #endif
 
 # define signal ext_signal
 #endif
 
@@ -303,27 +330,20 @@ rpl_signal (int sig, handler_t handler)
 }
 
 #if GNULIB_defined_SIGPIPE
 }
 
 #if GNULIB_defined_SIGPIPE
-/* Raise the signal SIG.  */
+/* Raise the signal SIGPIPE.  */
 int
 int
-rpl_raise (int sig)
-# undef raise
+_gl_raise_SIGPIPE (void)
 {
 {
-  switch (sig)
+  if (blocked_set & (1U << SIGPIPE))
+    pending_array[SIGPIPE] = 1;
+  else
     {
     {
-    case SIGPIPE:
-      if (blocked_set & (1U << sig))
-        pending_array[sig] = 1;
-      else
-        {
-          handler_t handler = SIGPIPE_handler;
-          if (handler == SIG_DFL)
-            exit (128 + SIGPIPE);
-          else if (handler != SIG_IGN)
-            (*handler) (sig);
-        }
-      return 0;
-    default: /* System defined signal */
-      return raise (sig);
+      handler_t handler = SIGPIPE_handler;
+      if (handler == SIG_DFL)
+        exit (128 + SIGPIPE);
+      else if (handler != SIG_IGN)
+        (*handler) (SIGPIPE);
     }
     }
+  return 0;
 }
 #endif
 }
 #endif