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