1169691Skan/*	$NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $	*/
2169691Skan
3169691Skan/*
4169691Skan * Copyright (c) 1988 Regents of the University of California.
5169691Skan * All rights reserved.
6169691Skan *
7169691Skan * Redistribution and use in source and binary forms, with or without
8169691Skan * modification, are permitted provided that the following conditions
9169691Skan * are met:
10169691Skan * 1. Redistributions of source code must retain the above copyright
11169691Skan *    notice, this list of conditions and the following disclaimer.
12169691Skan * 2. Redistributions in binary form must reproduce the above copyright
13169691Skan *    notice, this list of conditions and the following disclaimer in the
14169691Skan *    documentation and/or other materials provided with the distribution.
15169691Skan * 3. Neither the name of the University nor the names of its contributors
16169691Skan *    may be used to endorse or promote products derived from this software
17169691Skan *    without specific prior written permission.
18169691Skan *
19169691Skan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20169691Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22169691Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23169691Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24169691Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25169691Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27169691Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28169691Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29169691Skan * SUCH DAMAGE.
30169691Skan */
31169691Skan
32169691Skan#include <sys/cdefs.h>
33169691Skan#if defined(LIBC_SCCS) && !defined(lint)
34169691Skan#if 0
35169691Skanstatic char *sccsid = "@(#)strerror.c	5.6 (Berkeley) 5/4/91";
36169691Skan#else
37169691Skan__RCSID("$NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $");
38169691Skan#endif
39169691Skan#endif /* LIBC_SCCS and not lint */
40169691Skan
41169691Skan#include "namespace.h"
42169691Skan#ifdef NLS
43169691Skan#include <limits.h>
44169691Skan#include <nl_types.h>
45169691Skan#endif
46169691Skan
47169691Skan#include <assert.h>
48169691Skan#include <stdio.h>
49169691Skan#include <string.h>
50169691Skan#include "extern.h"
51169691Skan#include <signal.h>
52169691Skan#ifndef SIGRTMIN	/* XXX: Until we remove the #ifdef _KERNEL */
53169691Skan#define SIGRTMIN	33
54169691Skan#define SIGRTMAX	63
55169691Skan#endif
56169691Skan
57169691Skan/* ARGSUSED */
58169691Skanconst char *
59169691Skan__strsignal(int num, char *buf, size_t buflen)
60169691Skan{
61169691Skan#define	UPREFIX	"Unknown signal: %u"
62169691Skan#define RPREFIX "Real time signal %u"
63169691Skan	unsigned int signum;
64169691Skan
65169691Skan#ifdef NLS
66169691Skan	nl_catd catd ;
67169691Skan	catd = catopen("libc", NL_CAT_LOCALE);
68169691Skan#endif
69169691Skan
70169691Skan	_DIAGASSERT(buf != NULL);
71169691Skan
72169691Skan	signum = num;				/* convert to unsigned */
73169691Skan	if (signum < (unsigned int) sys_nsig) {
74169691Skan#ifdef NLS
75169691Skan		(void)strlcpy(buf, catgets(catd, 2, (int)signum,
76169691Skan		    sys_siglist[signum]), buflen);
77169691Skan#else
78169691Skan		return((char *)sys_siglist[signum]);
79169691Skan#endif
80169691Skan	} else if (signum >= SIGRTMIN && signum <= SIGRTMAX) {
81169691Skan#ifdef NLS
82169691Skan		(void)snprintf(buf, buflen,
83169691Skan	            catgets(catd, 2, SIGRTMIN, RPREFIX), signum);
84169691Skan#else
85169691Skan		(void)snprintf(buf, buflen, RPREFIX, signum);
86169691Skan#endif
87169691Skan	} else {
88169691Skan#ifdef NLS
89169691Skan		(void)snprintf(buf, buflen,
90169691Skan	            catgets(catd, 1, 0xffff, UPREFIX), signum);
91169691Skan#else
92169691Skan		(void)snprintf(buf, buflen, UPREFIX, signum);
93169691Skan#endif
94169691Skan	}
95169691Skan
96169691Skan#ifdef NLS
97169691Skan	catclose(catd);
98169691Skan#endif
99169691Skan
100169691Skan	return buf;
101169691Skan}
102169691Skan