# define sys_errlist ((char **)0)
#elif DECL_SYS_ERRLIST
/* have sys_errlist but need declaration */
- LDAP_LIBC_V (int) sys_nerr;
- LDAP_LIBC_V (char) *sys_errlist[];
+ LDAP_LIBC_V(int) sys_nerr;
+ LDAP_LIBC_V(char) *sys_errlist[];
#endif
-#ifdef HAVE_STRERROR
-#define STRERROR(err) strerror(err)
+#undef _AC_ERRNO_UNKNOWN
+#define _AC_ERRNO_UNKNOWN "unknown error"
+
+#ifdef HAVE_SYS_ERRLIST
+ /* this is thread safe */
+# define STRERROR(e) ( (e) > -1 && (e) < sys_nerr \
+ ? sys_errlist[(e)] : _AC_ERRNO_UNKNOWN )
+
+#elif defined( HAVE_STRERROR )
+ /* this may not be thread safe */
+ /* and, yes, some implementations of strerror may return NULL */
+# define STRERROR(e) ( strerror(e) \
+ ? strerror(e) : _AC_ERRNO_UNKNOWN )
+
#else
-#define STRERROR(err) \
- ((err) > -1 && (err) < sys_nerr ? sys_errlist[(err)] : "unknown")
+ /* this is thread safe */
+# define STRERROR(e) ( _AC_ERRNO_UNKNOWN )
#endif
#endif /* _AC_ERRNO_H */
if ( ret < 0 ) {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
- (long)len, strerror( errno ) );
+ (long)len, STRERROR( errno ) );
}
else {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%swrite: want=%ld error=%s\n",
(char *)sbiod->sbiod_pvt, (long)len,
- strerror( errno ) );
+ STRERROR( errno ) );
}
else {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
if ( err ) {
char error[BUFSIZ];
- if ( err < 0 ) {
- sprintf( error, "%ld\n", (long) err );
- } else {
- sprintf( error, "%s\n", strerror( err ));
- }
+ sprintf( error, "%s (%d)\n", STRERROR( err ), err );
+
#ifdef LDAP_SYSLOG
syslog( LOG_INFO,
"ldbm_initialize(): FATAL error in db_appinit() : %s\n",
{
char error[BUFSIZ];
- if ( err < 0 ) {
- sprintf( error, "%ld\n", (long) err );
- } else {
- sprintf( error, "%s\n", strerror( err ));
- }
+ sprintf( error, "%s (%d)\n", STRERROR( err ), err );
+
#ifdef LDAP_SYSLOG
syslog( LOG_INFO,
"ldbm_initialize(): FATAL error in db_appinit() : %s\n",
{
char error[BUFSIZ];
- if ( err < 0 ) {
- sprintf( error, "%ld\n", (long) err );
- } else {
- sprintf( error, "%s\n", strerror( err ));
- }
+ sprintf( error, "%s (%d)\n", STRERROR( err ), err );
+
(void)ret->close(ret, 0);
return NULL;
}
{
char error[BUFSIZ];
- if ( err < 0 ) {
- sprintf( error, "%ld\n", (long) err );
- } else {
- sprintf( error, "%s\n", strerror( err ));
- }
+ sprintf( error, "%s (%d)\n", STRERROR( err ), err );
+
(void)ret->close(ret, 0);
return NULL;
}
{
char error[BUFSIZ];
- if ( rc < 0 ) {
- sprintf( error, "%ld\n", (long) rc );
- } else {
- sprintf( error, "%s\n", strerror( rc ));
- }
+ sprintf( error, "%s (%d)\n", STRERROR( rc ), rc );
}
- rc = (-1) * rc;
+ rc = (-1) * rc;
#elif DB_VERSION_MAJOR >= 2
rc = (*ldbm->put)( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );