Commit 568100ea authored by Steven Murray's avatar Steven Murray Committed by Steven Murray
Browse files

sstrerror_r() now calls strerror_r_wrapper()

parent f53fe3d4
......@@ -3,16 +3,10 @@
* All rights reserved
*/
/*
* Undefine _GNU_SOURCE and set _XOPEN_SOURCE to 600 so that the POSIX
* version of strerror_r() will be used
*/
#undef _GNU_SOURCE
#define _XOPEN_SOURCE 600
/* serror.c Global error reporting routines */
#include "h/serrno.h" /* special error numbers and codes */
#include "h/Cglobals.h"
#include "h/strerror_r_wrapper.h"
#include <stdio.h> /* standard input/output */
#include <errno.h> /* error numbers and codes */
......@@ -591,15 +585,11 @@ int sstrerror_r(const int n, char *const buf, const size_t buflen) {
) {
/*
* SYSTEM error messages
*
* Note: Explicitly store the result of strerror_r into an integer in order
* to make sure the XSI-compliant version is being used. The GNU version
* returns a pointer to char.
*/
const int strerror_r_rc =
strerror_r(n, strerror_r_buf, sizeof(strerror_r_buf));
if(strerror_r_rc) {
tmpstr = "Unknown error because call to strerror_r failed";
const int strerror_r_wrapper_rc =
strerror_r_wrapper(n, strerror_r_buf, sizeof(strerror_r_buf));
if(strerror_r_wrapper_rc) {
tmpstr = "Unknown error because call to strerror_r_wrapper() failed";
} else {
tmpstr = strerror_r_buf;
}
......@@ -612,7 +602,8 @@ int sstrerror_r(const int n, char *const buf, const size_t buflen) {
/*
* Unknown error message
*/
sprintf(buf, "%*s: %10d", (int)buflen-14, sys_serrlist[SEMAXERR+1-SEBASEOFF], n);
sprintf(buf, "%*s: %10d", (int)buflen-14,
sys_serrlist[SEMAXERR+1-SEBASEOFF], n);
}
return 0;
}
......
......@@ -22,9 +22,13 @@
* @author Steven.Murray@cern.ch
*****************************************************************************/
#include "h/strerror_r_wrapper.hpp"
#include "h/strerror_r_wrapper.h"
#if defined(linux)
/*
* Undefine _GNU_SOURCE and define _XOPEN_SOURCE as being 600 so that the
* XSI compliant version of strerror_r() will be used
*/
#undef _GNU_SOURCE
#define _XOPEN_SOURCE 600
#endif
......@@ -34,6 +38,6 @@
/*******************************************************************************
* strerror_r_wrapper
******************************************************************************/
int strerror_r_wrapper(int errnum, char *buf, unsigned int buflen) {
extern "C" int strerror_r_wrapper(int errnum, char *buf, unsigned int buflen) {
return strerror_r(errnum, buf, buflen);
}
......@@ -27,22 +27,6 @@
#include <stddef.h>
/* The following EXTERN_C marco has been intentionally copied from */
/* h/osdep.h instead of just including h/osdep.h. The reason for this is */
/* this header file must include the minimum number of header files because */
/* the implementation file common/strerror_r_wrapper.cpp will undefine */
/* _GNU_SOURCE and define _XOPEN_SOURCE as being 600. */
/* */
/* Macros for externalization (UNIX) (J.-D.Durand) */
#ifdef EXTERN_C
#undef EXTERN_C
#endif
#if defined(__cplusplus)
#define EXTERN_C extern "C"
#else
#define EXTERN_C extern
#endif
/**
* This function wraps the XSI compliant version of strerror_r() and therefore
* writes the string representation of the specified error number to the
......@@ -52,6 +36,6 @@
* @param buf The buffer.
* @param buflen The length of the buffer.
*/
EXTERN_C int strerror_r_wrapper(int errnum, char *buf, size_t buflen);
int strerror_r_wrapper(int errnum, char *buf, size_t buflen);
#endif /* H_STRERROR_R_WRAPPER_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment