dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / string / strerror.c
blob2541efd847b74b711dac8680bb36b26ed2469ec6
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
25 * Glenn Fowler
26 * AT&T Research
28 * return error message string given errno
31 #include "lclib.h"
33 #include "FEATURE/errno"
35 #undef strerror
37 #if !defined(sys_errlist) && !_def_errno_sys_errlist
38 #if _dat_sys_errlist
39 extern char* sys_errlist[];
40 #else
41 #undef _dat_sys_nerr
42 char* sys_errlist[] = { 0 };
43 #endif
44 #endif
46 #if !defined(sys_nerr) && !_def_errno_sys_nerr
47 #if _dat_sys_nerr
48 extern int sys_nerr;
49 #else
50 #undef _dat_sys_nerr
51 int sys_nerr = 0;
52 #endif
53 #endif
55 #if _lib_strerror
56 extern char* strerror(int);
57 #endif
59 #if _PACKAGE_astsa
61 #define fmtbuf(n) ((n),tmp)
63 static char tmp[32];
65 #endif
67 char*
68 _ast_strerror(int err)
70 char* msg;
71 int z;
73 #if _lib_strerror
74 z = errno;
75 msg = strerror(err);
76 errno = z;
77 #else
78 if (err > 0 && err <= sys_nerr)
79 msg = (char*)sys_errlist[err];
80 else
81 msg = 0;
82 #endif
83 if (msg)
85 #if !_PACKAGE_astsa
86 if (ERROR_translating())
88 #if _lib_strerror
89 static int sys;
91 if (!sys)
93 char* s;
94 char* t;
95 char* p;
97 #if _lib_strerror
99 * stash the pending strerror() msg
102 msg = strcpy(fmtbuf(strlen(msg) + 1), msg);
103 #endif
106 * make sure that strerror() translates
109 if (!(s = strerror(1)))
110 sys = -1;
111 else
113 t = fmtbuf(z = strlen(s) + 1);
114 strcpy(t, s);
115 ast.locale.set |= AST_LC_internal;
116 p = setlocale(LC_MESSAGES, NiL);
117 setlocale(LC_MESSAGES, "C");
118 sys = (s = strerror(1)) && strcmp(s, t) ? 1 : -1;
119 setlocale(LC_MESSAGES, p);
120 ast.locale.set &= ~AST_LC_internal;
123 if (sys > 0)
124 return msg;
125 #endif
126 return ERROR_translate(NiL, NiL, "errlist", msg);
128 #endif
129 return msg;
131 msg = fmtbuf(z = 32);
132 sfsprintf(msg, z, ERROR_translate(NiL, NiL, "errlist", "Error %d"), err);
133 return msg;
136 #if !_lib_strerror
138 #if defined(__EXPORT__)
139 #define extern __EXPORT__
140 #endif
142 extern char*
143 strerror(int err)
145 return _ast_strerror(err);
148 #endif