From bef9f6d6412d6c2491610c0735e384f22a2a0d8f Mon Sep 17 00:00:00 2001 From: Steven Murray <steven.murray@cern.ch> Date: Mon, 24 Mar 2014 11:00:04 +0100 Subject: [PATCH] Improved the comments surrounding strerror_r_wrapper() --- mediachanger/castorrmc/common/strerror_r_wrapper.cpp | 10 ++++++++++ mediachanger/castorrmc/h/strerror_r_wrapper.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/mediachanger/castorrmc/common/strerror_r_wrapper.cpp b/mediachanger/castorrmc/common/strerror_r_wrapper.cpp index 09273390d9..1a149b2269 100644 --- a/mediachanger/castorrmc/common/strerror_r_wrapper.cpp +++ b/mediachanger/castorrmc/common/strerror_r_wrapper.cpp @@ -39,5 +39,15 @@ * strerror_r_wrapper ******************************************************************************/ extern "C" int strerror_r_wrapper(int errnum, char *buf, size_t buflen) { + /* This function should be compiled using a C++ compiler and not a C compiler. + * + * C++ compilers are better at spotting whether the GNU version or the + * XSI complicant version of sterror_() is being used. This is because the + * difference between the two versions is their return types. The GNU + * version returns a 'char *' whereas the XSI compliant version returns an + * 'int'. A C compiler may allow the strerror_r() function to return a + * 'char *' and have that 'char *' assigned to an 'int'. A C++ compiler + * usually gives an error if this is tried. + */ return strerror_r(errnum, buf, buflen); } diff --git a/mediachanger/castorrmc/h/strerror_r_wrapper.h b/mediachanger/castorrmc/h/strerror_r_wrapper.h index 059bd065ef..aa474841a1 100644 --- a/mediachanger/castorrmc/h/strerror_r_wrapper.h +++ b/mediachanger/castorrmc/h/strerror_r_wrapper.h @@ -44,6 +44,16 @@ * This function wraps the XSI compliant version of strerror_r() and therefore * writes the string representation of the specified error number to the * specified buffer. + * + * This function should be compiled using a C++ compiler and not a C compiler. + * + * C++ compilers are better at spotting whether the GNU version or the + * XSI complicant version of sterror_() is being used. This is because the + * difference between the two versions is their return types. The GNU + * version returns a 'char *' whereas the XSI compliant version returns an + * 'int'. A C compiler may allow the strerror_r() function to return a + * 'char *' and have that 'char *' assigned to an 'int'. A C++ compiler + * usually gives an error if this is tried. * * @param errnum The error number. * @param buf The buffer. -- GitLab