Deleted Added
full compact
strsignal.c (92889) strsignal.c (142667)
1/*
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/lib/libc/string/strsignal.c 92889 2002-03-21 18:49:23Z obrien $");
38__FBSDID("$FreeBSD: head/lib/libc/string/strsignal.c 142667 2005-02-27 16:58:28Z phantom $");
39
39
40#include <stdio.h>
40#if defined(NLS)
41#include <limits.h>
42#include <nl_types.h>
43#endif
44
45#include <errno.h>
41#include <string.h>
42#include <signal.h>
43
46#include <string.h>
47#include <signal.h>
48
49#define UPREFIX "Unknown signal"
50
51/* XXX: negative 'num' ? (REGR) */
44char *
52char *
45strsignal(num)
46 int num;
53strsignal(int num)
47{
54{
48#define UPREFIX "Unknown signal: "
49 static char ebuf[40] = UPREFIX; /* 64-bit number + slop */
50 unsigned int signum;
51 char *p, *t;
52 char tmp[40];
55 static char ebuf[NL_TEXTMAX];
56 char tmp[20];
57 int signum, n;
58 char *t, *p;
53
59
54 signum = num; /* convert to unsigned */
55 if (signum < sys_nsig)
56 return ((char *)sys_siglist[signum]);
60#if defined(NLS)
61 int saved_errno = errno;
62 nl_catd catd;
63 catd = catopen("libc", NL_CAT_LOCALE);
64#endif
57
65
58 /* Do this by hand, so we don't link to stdio(3). */
59 t = tmp;
66 if (num > 0 && num < sys_nsig) {
67 strlcpy(ebuf,
68#if defined(NLS)
69 catgets(catd, 2, num, sys_siglist[num]),
70#else
71 sys_siglist[num],
72#endif
73 sizeof(ebuf));
74 } else {
75 n = strlcpy(ebuf,
76#if defined(NLS)
77 catgets(catd, 2, 0xffff, UPREFIX),
78#else
79 UPREFIX,
80#endif
81 sizeof(ebuf));
82 }
83
84 signum = num;
60 if (num < 0)
61 signum = -signum;
85 if (num < 0)
86 signum = -signum;
87
88 t = tmp;
62 do {
63 *t++ = "0123456789"[signum % 10];
64 } while (signum /= 10);
65 if (num < 0)
66 *t++ = '-';
89 do {
90 *t++ = "0123456789"[signum % 10];
91 } while (signum /= 10);
92 if (num < 0)
93 *t++ = '-';
67 for (p = ebuf + sizeof(UPREFIX) - 1;;) {
94
95 p = (ebuf + n);
96 *p++ = ':';
97 *p++ = ' ';
98
99 for (;;) {
68 *p++ = *--t;
69 if (t <= tmp)
70 break;
71 }
72 *p = '\0';
100 *p++ = *--t;
101 if (t <= tmp)
102 break;
103 }
104 *p = '\0';
105
106#if defined(NLS)
107 catclose(catd);
108 errno = saved_errno;
109#endif
73 return (ebuf);
74}
110 return (ebuf);
111}