source: trunk/athena/etc/newsyslog/signames.c @ 13769

Revision 13769, 2.2 KB checked in by danw, 25 years ago (diff)
compile with warnings
Line 
1/*
2 *      signals.c -- deal with concerting signal names to numbers and back.
3 *
4 *      $Id: signames.c,v 1.5 1999-10-19 20:22:28 danw Exp $
5 */
6
7static const char rcsid[] = "$Id: signames.c,v 1.5 1999-10-19 20:22:28 danw Exp $";
8
9#include <string.h>
10#include <signal.h>
11#include "config.h"
12#include "signames.h"
13
14struct signal_map {
15  char *name;
16  int number;
17};
18
19/*  Note: this contains only the signals described in the POSIX.1
20 *  programmer's guide, because right now I don't care about any others.
21 *  If someone else decides they do, they can add them themselves. =)
22 */
23
24static const
25struct signal_map signals[] = {
26#ifdef SIGHUP
27  {"HUP",       SIGHUP},
28#endif
29#ifdef SIGINT
30  {"INT",       SIGINT},
31#endif
32#ifdef SIGQUIT
33  {"QUIT",      SIGQUIT},
34#endif
35#ifdef SIGILL
36  {"ILL",       SIGILL},
37#endif
38#ifdef SIGABRT
39  {"ABRT",      SIGABRT},
40#endif
41#ifdef SIGFPE
42  {"FPE",       SIGFPE},
43#endif
44#ifdef SIGKILL
45  {"KILL",      SIGKILL},
46#endif
47#ifdef SIGBUS
48  {"BUS",       SIGBUS},
49#endif
50#ifdef SIGSEGV
51  {"SEGV",      SIGSEGV},
52#endif
53#ifdef SIGPIPE
54  {"PIPE",      SIGPIPE},
55#endif
56#ifdef SIGALRM
57  {"ALRM",      SIGALRM},
58#endif
59#ifdef SIGTERM
60  {"TERM",      SIGTERM},
61#endif
62#ifdef SIGUSR1
63  {"USR1",      SIGUSR1},
64#endif
65#ifdef SIGUSR2
66  {"USR2",      SIGUSR2},
67#endif
68#ifdef SIGCHLD
69  {"CHLD",      SIGCHLD},
70#endif
71#ifdef SIGPWR
72  {"PWR",       SIGPWR},    /* this is not POSIX.1, but I like it. =) */
73#endif
74#ifdef SIGSTOP
75  {"STOP",      SIGSTOP},
76#endif
77#ifdef SIGTSTP
78  {"TSTP",      SIGTSTP},
79#endif
80#ifdef SIGCONT
81  {"CONT",      SIGCONT},
82#endif
83#ifdef SIGTTIN
84  {"TTIN",      SIGTTIN},
85#endif
86#ifdef SIGTTOU
87  {"TTOU",      SIGTTOU},
88#endif
89  {NULL,        0}
90};
91
92/* signal_name() returns the name for a given signal, or NULL if unknown. */
93char* signal_name (int signum)
94{
95  int i;
96
97  for (i=0; signals[i].name; i++) {
98    if (signum == signals[i].number)
99      return signals[i].name;
100  }
101  return NULL;
102}
103
104/* signal_number() returns the number for a given signal, or 0 if unknown. */
105int signal_number (char* name)
106{
107  int i;
108
109  for (i=0; signals[i].name; i++) {
110    if (!strcasecmp(name, signals[i].name))
111      return signals[i].number;
112  }
113  return 0;
114}
115
116/* fprint_signal_name() prints out the signal name, or "signal ##". */
117void fprint_signal_name(FILE *f, int signum)
118{
119  char *name = signal_name(signum);
120
121  if (name)
122    fprintf(f, name);
123  else
124    fprintf(f, "signal %d", signum);
125}
Note: See TracBrowser for help on using the repository browser.