Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libc/port/gen/str2sig.c
+++ new/usr/src/lib/libc/port/gen/str2sig.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 * Copyright 2015, Joyent, Inc.
26 26 */
27 27
28 28 /* Copyright (c) 1988 AT&T */
29 29 /* All Rights Reserved */
30 30
31 31 #include "lint.h"
32 32 #include <string.h>
33 33 #include <stdlib.h>
34 34 #include <signal.h>
35 35 #include <sys/types.h>
36 36 #include <errno.h>
37 37
38 38 typedef struct signame {
39 39 const char *sigstr;
40 40 const int signum;
41 41 } signame_t;
42 42
43 43 static signame_t signames[] = {
44 44 { "EXIT", 0 },
45 45 { "HUP", SIGHUP },
46 46 { "INT", SIGINT },
47 47 { "QUIT", SIGQUIT },
48 48 { "ILL", SIGILL },
49 49 { "TRAP", SIGTRAP },
50 50 { "ABRT", SIGABRT },
51 51 { "IOT", SIGIOT },
52 52 { "EMT", SIGEMT },
53 53 { "FPE", SIGFPE },
54 54 { "KILL", SIGKILL },
55 55 { "BUS", SIGBUS },
56 56 { "SEGV", SIGSEGV },
57 57 { "SYS", SIGSYS },
58 58 { "PIPE", SIGPIPE },
59 59 { "ALRM", SIGALRM },
60 60 { "TERM", SIGTERM },
61 61 { "USR1", SIGUSR1 },
62 62 { "USR2", SIGUSR2 },
63 63 { "CLD", SIGCLD },
64 64 { "CHLD", SIGCHLD },
65 65 { "PWR", SIGPWR },
66 66 { "WINCH", SIGWINCH },
67 67 { "URG", SIGURG },
68 68 { "POLL", SIGPOLL },
69 69 { "IO", SIGPOLL },
70 70 { "STOP", SIGSTOP },
71 71 { "TSTP", SIGTSTP },
72 72 { "CONT", SIGCONT },
73 73 { "TTIN", SIGTTIN },
74 74 { "TTOU", SIGTTOU },
75 75 { "VTALRM", SIGVTALRM },
76 76 { "PROF", SIGPROF },
77 77 { "XCPU", SIGXCPU },
78 78 { "XFSZ", SIGXFSZ },
79 79 { "WAITING", SIGWAITING },
80 80 { "LWP", SIGLWP },
81 81 { "FREEZE", SIGFREEZE },
82 82 { "THAW", SIGTHAW },
83 83 { "CANCEL", SIGCANCEL },
84 84 { "LOST", SIGLOST },
85 85 { "XRES", SIGXRES },
86 86 { "JVM1", SIGJVM1 },
87 87 { "JVM2", SIGJVM2 },
88 88 { "INFO", SIGINFO },
89 89 { "RTMIN", _SIGRTMIN },
90 90 { "RTMIN+1", _SIGRTMIN+1 },
91 91 { "RTMIN+2", _SIGRTMIN+2 },
92 92 { "RTMIN+3", _SIGRTMIN+3 },
93 93 { "RTMIN+4", _SIGRTMIN+4 },
94 94 { "RTMIN+5", _SIGRTMIN+5 },
95 95 { "RTMIN+6", _SIGRTMIN+6 },
96 96 { "RTMIN+7", _SIGRTMIN+7 },
97 97 { "RTMIN+8", _SIGRTMIN+8 },
98 98 { "RTMIN+9", _SIGRTMIN+9 },
99 99 { "RTMIN+10", _SIGRTMIN+10 },
100 100 { "RTMIN+11", _SIGRTMIN+11 },
101 101 { "RTMIN+12", _SIGRTMIN+12 },
102 102 { "RTMIN+13", _SIGRTMIN+13 },
103 103 { "RTMIN+14", _SIGRTMIN+14 },
104 104 { "RTMIN+15", _SIGRTMIN+15 },
105 105 { "RTMIN+16", _SIGRTMIN+16 },
106 106 { "RTMAX-15", _SIGRTMAX-15 },
107 107 { "RTMAX-14", _SIGRTMAX-14 },
108 108 { "RTMAX-13", _SIGRTMAX-13 },
109 109 { "RTMAX-12", _SIGRTMAX-12 },
110 110 { "RTMAX-11", _SIGRTMAX-11 },
111 111 { "RTMAX-10", _SIGRTMAX-10 },
112 112 { "RTMAX-9", _SIGRTMAX-9 },
113 113 { "RTMAX-8", _SIGRTMAX-8 },
114 114 { "RTMAX-7", _SIGRTMAX-7 },
115 115 { "RTMAX-6", _SIGRTMAX-6 },
116 116 { "RTMAX-5", _SIGRTMAX-5 },
117 117 { "RTMAX-4", _SIGRTMAX-4 },
118 118 { "RTMAX-3", _SIGRTMAX-3 },
119 119 { "RTMAX-2", _SIGRTMAX-2 },
120 120 { "RTMAX-1", _SIGRTMAX-1 },
121 121 { "RTMAX", _SIGRTMAX },
122 122 };
123 123
124 124 #define SIGCNT (sizeof (signames) / sizeof (struct signame))
125 125
126 126 static int str2long(const char *, long *);
127 127
128 128 static int
129 129 str2long(const char *p, long *val)
130 130 {
131 131 char *q;
132 132 int error;
133 133 int saved_errno = errno;
134 134
135 135 errno = 0;
136 136 *val = strtol(p, &q, 10);
137 137
138 138 error = ((errno != 0 || q == p || *q != '\0') ? -1 : 0);
139 139 errno = saved_errno;
140 140
141 141 return (error);
142 142 }
143 143
144 144 int
145 145 str2sig(const char *s, int *sigp)
146 146 {
147 147 const struct signame *sp;
148 148
149 149 if (*s >= '0' && *s <= '9') {
150 150 long val;
151 151
152 152 if (str2long(s, &val) == -1)
153 153 return (-1);
154 154
155 155 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
156 156 if (sp->signum == val) {
157 157 *sigp = sp->signum;
158 158 return (0);
159 159 }
160 160 }
161 161 return (-1);
162 162 } else {
163 163 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
164 164 if (strcmp(sp->sigstr, s) == 0) {
165 165 *sigp = sp->signum;
166 166 return (0);
167 167 }
168 168 }
169 169 return (-1);
170 170 }
171 171 }
172 172
173 173 int
174 174 sig2str(int i, char *s)
175 175 {
176 176 const struct signame *sp;
177 177
178 178 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
179 179 if (sp->signum == i) {
180 180 (void) strcpy(s, sp->sigstr);
181 181 return (0);
182 182 }
183 183 }
184 184 return (-1);
185 185 }
|
↓ open down ↓ |
185 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX