1/* Generic errno.h */
2/* $OpenLDAP$ */
3/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 1998-2011 The OpenLDAP Foundation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
11 *
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
15 */
16
17#ifndef _AC_ERRNO_H
18#define _AC_ERRNO_H
19
20#if defined( HAVE_ERRNO_H )
21# include <errno.h>
22#elif defined( HAVE_SYS_ERRNO_H )
23# include <sys/errno.h>
24#endif
25
26#ifndef HAVE_SYS_ERRLIST
27	/* no sys_errlist */
28#	define		sys_nerr	0
29#	define		sys_errlist	((char **)0)
30#elif defined( DECL_SYS_ERRLIST )
31	/* have sys_errlist but need declaration */
32	LDAP_LIBC_V(int)      sys_nerr;
33	LDAP_LIBC_V(char)    *sys_errlist[];
34#endif
35
36#undef _AC_ERRNO_UNKNOWN
37#define _AC_ERRNO_UNKNOWN "unknown error"
38
39#ifdef HAVE_SYS_ERRLIST
40	/* this is thread safe */
41#	define	STRERROR(e) ( (e) > -1 && (e) < sys_nerr \
42			? sys_errlist[(e)] : _AC_ERRNO_UNKNOWN )
43
44#elif defined( HAVE_STRERROR )
45	/* this may not be thread safe */
46	/* and, yes, some implementations of strerror may return NULL */
47#	define	STRERROR(e) ( strerror(e) \
48		? strerror(e) : _AC_ERRNO_UNKNOWN )
49
50#else
51	/* this is thread safe */
52#	define	STRERROR(e) ( _AC_ERRNO_UNKNOWN )
53#endif
54
55#endif /* _AC_ERRNO_H */
56