6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / lib / libc / port / gen / str2sig.c
blobf899f1395ea531f9ae235ddad69008d53010fa65
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include "lint.h"
33 #include <string.h>
34 #include <stdlib.h>
35 #include <signal.h>
36 #include <sys/types.h>
37 #include <errno.h>
39 typedef struct signame {
40 const char *sigstr;
41 const int signum;
42 } signame_t;
44 static signame_t signames[] = {
45 { "EXIT", 0 },
46 { "HUP", SIGHUP },
47 { "INT", SIGINT },
48 { "QUIT", SIGQUIT },
49 { "ILL", SIGILL },
50 { "TRAP", SIGTRAP },
51 { "ABRT", SIGABRT },
52 { "IOT", SIGIOT },
53 { "EMT", SIGEMT },
54 { "FPE", SIGFPE },
55 { "KILL", SIGKILL },
56 { "BUS", SIGBUS },
57 { "SEGV", SIGSEGV },
58 { "SYS", SIGSYS },
59 { "PIPE", SIGPIPE },
60 { "ALRM", SIGALRM },
61 { "TERM", SIGTERM },
62 { "USR1", SIGUSR1 },
63 { "USR2", SIGUSR2 },
64 { "CLD", SIGCLD },
65 { "CHLD", SIGCHLD },
66 { "PWR", SIGPWR },
67 { "WINCH", SIGWINCH },
68 { "URG", SIGURG },
69 { "POLL", SIGPOLL },
70 { "IO", SIGPOLL },
71 { "STOP", SIGSTOP },
72 { "TSTP", SIGTSTP },
73 { "CONT", SIGCONT },
74 { "TTIN", SIGTTIN },
75 { "TTOU", SIGTTOU },
76 { "VTALRM", SIGVTALRM },
77 { "PROF", SIGPROF },
78 { "XCPU", SIGXCPU },
79 { "XFSZ", SIGXFSZ },
80 { "WAITING", SIGWAITING },
81 { "LWP", SIGLWP },
82 { "FREEZE", SIGFREEZE },
83 { "THAW", SIGTHAW },
84 { "CANCEL", SIGCANCEL },
85 { "LOST", SIGLOST },
86 { "XRES", SIGXRES },
87 { "JVM1", SIGJVM1 },
88 { "JVM2", SIGJVM2 },
89 { "RTMIN", _SIGRTMIN },
90 { "RTMIN+1", _SIGRTMIN+1 },
91 { "RTMIN+2", _SIGRTMIN+2 },
92 { "RTMIN+3", _SIGRTMIN+3 },
93 { "RTMAX-3", _SIGRTMAX-3 },
94 { "RTMAX-2", _SIGRTMAX-2 },
95 { "RTMAX-1", _SIGRTMAX-1 },
96 { "RTMAX", _SIGRTMAX },
99 #define SIGCNT (sizeof (signames) / sizeof (struct signame))
101 static int str2long(const char *, long *);
103 static int
104 str2long(const char *p, long *val)
106 char *q;
107 int error;
108 int saved_errno = errno;
110 errno = 0;
111 *val = strtol(p, &q, 10);
113 error = ((errno != 0 || q == p || *q != '\0') ? -1 : 0);
114 errno = saved_errno;
116 return (error);
120 str2sig(const char *s, int *sigp)
122 const struct signame *sp;
124 if (*s >= '0' && *s <= '9') {
125 long val;
127 if (str2long(s, &val) == -1)
128 return (-1);
130 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
131 if (sp->signum == val) {
132 *sigp = sp->signum;
133 return (0);
136 return (-1);
137 } else {
138 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
139 if (strcmp(sp->sigstr, s) == 0) {
140 *sigp = sp->signum;
141 return (0);
144 return (-1);
149 sig2str(int i, char *s)
151 const struct signame *sp;
153 for (sp = signames; sp < &signames[SIGCNT]; sp++) {
154 if (sp->signum == i) {
155 (void) strcpy(s, sp->sigstr);
156 return (0);
159 return (-1);