oracle / odpi

ODPI-C: Oracle Database Programming Interface for Drivers and Applications
https://oracle.github.io/odpi/
Other
264 stars 75 forks source link

strerror_r on cygwin #138

Closed kubo closed 3 years ago

kubo commented 4 years ago

ODPI-C version: 4.0.1 OS: Cygwin on Windows Compiler: gcc

Cygwin declares GNU-version strerror_r when _GNU_SOURCE is defined. However the POSIX version is used in the following code.

#if defined(__GLIBC__)
    message = strerror_r(err, buffer, sizeof(buffer));
#else
    message = (strerror_r(err, buffer, sizeof(buffer)) == 0) ? buffer : NULL;
#endif

No warnings by accident when compiling ODPI-C. That's because comparison with a pointer and literal zero is compilable without warnings.

When the above code is changed as follows,

#if defined(__GLIBC__)
    message = strerror_r(err, buffer, sizeof(buffer));
#else
    int rv = strerror_r(err, buffer, sizeof(buffer));
    message = (rv == 0) ? buffer : NULL;
#endif

gcc prints the following warning.

gcc -c -Iinclude -O2 -g -Wall -Wextra -fPIC src/dpiError.c -o build/dpiError.o
src/dpiError.c: In function 'dpiError__setFromOS':
src/dpiError.c:262:14: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
     int rv = strerror_r(err, buffer, sizeof(buffer));
              ^~~~~~~~~~

This implies that the strerror_r isn't the POSIX version returning int. It is the GNU version returning char *.

The following code in place of #if defined(__GLIBC__) fixes the issue.

#if defined(__GLIBC__) || defined(__CYGWIN__)
cjbj commented 4 years ago

Thanks @kubo

anthony-tuininga commented 4 years ago

I've marked this for version 4.1 but if a patch release (4.0.2) is created I'll include it in there, too.

anthony-tuininga commented 4 years ago

Let me know if the creation of a patch release would be helpful to you, @kubo.

anthony-tuininga commented 3 years ago

This was included in 4.0.2 released on August 31, 2020.