3a46a8ce850aac4239deecf0e317281fc61032c7
[gnulib.git] / lib / sig2str.h
1 /* sig2str.h -- convert between signal names and numbers
2
3    Copyright (C) 2002 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program 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
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 /* Written by Paul Eggert.  */
20
21 /* Include <signal.h> before including this file.  */
22
23 /* Don't override system declarations of SIG2STR_MAX, sig2str, str2sig.  */
24 #ifndef SIG2STR_MAX
25
26 /* Upper bound on the string length of an integer converted to string.
27    302 / 1000 is ceil (log10 (2.0)).  Subtract 1 for the sign bit;
28    add 1 for integer division truncation; add 1 more for a minus sign.  */
29 # define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
30
31 /* Size of a buffer needed to hold a signal name like "HUP".  */
32 # define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1)
33
34 int sig2str (int, char *);
35 int str2sig (char const *, int *);
36
37 #endif
38
39 /* An upper bound on signal numbers allowed by the system.  */
40
41 #if defined _sys_nsig
42 # define SIGNUM_BOUND (_sys_nsig - 1)
43 #elif defined NSIG
44 # define SIGNUM_BOUND (NSIG - 1)
45 #elif defined WTERMSIG
46 # define SIGNUM_BOUND WTERMSIG (~ 0)
47 #else
48 # define SIGNUM_BOUND 127
49 #endif