1 /***********************************************************************
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 *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
28 * return error message string given errno
33 #include "FEATURE/errno"
37 #if !defined(sys_errlist) && !_def_errno_sys_errlist
39 extern char* sys_errlist
[];
42 char* sys_errlist
[] = { 0 };
46 #if !defined(sys_nerr) && !_def_errno_sys_nerr
56 extern char* strerror(int);
61 #define fmtbuf(n) ((n),tmp)
68 _ast_strerror(int err
)
78 if (err
> 0 && err
<= sys_nerr
)
79 msg
= (char*)sys_errlist
[err
];
86 if (ERROR_translating())
99 * stash the pending strerror() msg
102 msg
= strcpy(fmtbuf(strlen(msg
) + 1), msg
);
106 * make sure that strerror() translates
109 if (!(s
= strerror(1)))
113 t
= fmtbuf(z
= strlen(s
) + 1);
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
;
126 return ERROR_translate(NiL
, NiL
, "errlist", msg
);
131 msg
= fmtbuf(z
= 32);
132 sfsprintf(msg
, z
, ERROR_translate(NiL
, NiL
, "errlist", "Error %d"), err
);
138 #if defined(__EXPORT__)
139 #define extern __EXPORT__
145 return _ast_strerror(err
);