apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/misc/unix errorcodes.c
Date Mon, 12 Nov 2001 01:16:01 GMT
trawick     01/11/11 17:16:01

  Modified:    .        CHANGES acconfig.h configure.in
               build    apr_common.m4
               misc/unix errorcodes.c
  Log:
  Use strerror_r() where available, since strerror() isn't always
  thread-safe.  Example systems where strerror() isn't thread-safe:
  Linux+glibc, AIX
  
  Revision  Changes    Path
  1.179     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.178
  retrieving revision 1.179
  diff -u -r1.178 -r1.179
  --- CHANGES	2001/11/11 05:51:00	1.178
  +++ CHANGES	2001/11/12 01:16:00	1.179
  @@ -1,5 +1,9 @@
   Changes with APR b1  
   
  +  *) Use strerror_r() where available, since strerror() isn't always
  +     thread-safe.  Example systems where strerror() isn't thread-safe:
  +     Linux+glibc, AIX  [Jeff Trawick]
  +
     *) Fix some file cleanup problems in apr_proc_create() which could
        result in the pipes for stdin/stdout/stderr being closed
        immediately.  [Jeff Trawick]
  
  
  
  1.52      +1 -0      apr/acconfig.h
  
  Index: acconfig.h
  ===================================================================
  RCS file: /home/cvs/apr/acconfig.h,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- acconfig.h	2001/08/16 06:29:48	1.51
  +++ acconfig.h	2001/11/12 01:16:00	1.52
  @@ -26,6 +26,7 @@
   #undef READDIR_IS_THREAD_SAFE
   #undef GETHOSTBYNAME_IS_THREAD_SAFE
   #undef GETHOSTBYADDR_IS_THREAD_SAFE
  +#undef STRERROR_R_RC_INT
   
   #undef NEED_RLIM_T
   #undef USEBCOPY
  
  
  
  1.373     +4 -0      apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.372
  retrieving revision 1.373
  diff -u -r1.372 -r1.373
  --- configure.in	2001/10/27 23:48:25	1.372
  +++ configure.in	2001/11/12 01:16:00	1.373
  @@ -588,6 +588,10 @@
   AC_SUBST(apr_inaddr_none)
   AC_CHECK_FUNC(_getch)
   AC_CHECK_FUNCS(gmtime_r localtime_r)
  +AC_CHECK_FUNCS(strerror_r, [ strerror_r="1" ], [ strerror_r="0" ])
  +if test "$strerror_r" = "1"; then
  +  APR_CHECK_STRERROR_R_RC
  +fi
   AC_CHECK_FUNCS(iconv, [ iconv="1" ], [ iconv="0" ])
   if test "$iconv" = "1"; then
     APR_CHECK_ICONV_INBUF
  
  
  
  1.22      +35 -1     apr/build/apr_common.m4
  
  Index: apr_common.m4
  ===================================================================
  RCS file: /home/cvs/apr/build/apr_common.m4,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- apr_common.m4	2001/07/24 10:05:36	1.21
  +++ apr_common.m4	2001/11/12 01:16:00	1.22
  @@ -420,7 +420,41 @@
   rm -f conftest*
   ])dnl
   
  -
  +dnl
  +dnl APR_CHECK_STRERROR_R_RC
  +dnl
  +dnl  Decide which style of retcode is used by this system's 
  +dnl  strerror_r().  It either returns int (0 for success, -1
  +dnl  for failure), or it returns a pointer to the error 
  +dnl  string.
  +dnl
  +dnl
  +AC_DEFUN(APR_CHECK_STRERROR_R_RC,[
  +AC_MSG_CHECKING(for type of return code from strerror_r)
  +AC_TRY_RUN([
  +#include <errno.h>
  +#include <stdio.h>
  +main()
  +{
  +  char buf[1024];
  +  if (strerror_r(ERANGE, buf, sizeof buf) < 1) {
  +    exit(0);
  +  }
  +  else {
  +    exit(1);
  +  }
  +}], [
  +    ac_cv_strerror_r_rc_int=yes ], [
  +    ac_cv_strerror_r_rc_int=no ], [
  +    ac_cv_strerror_r_rc_int=no ] )
  +if test "x$ac_cv_strerror_r_rc_int" = xyes; then
  +  AC_DEFINE(STRERROR_R_RC_INT)
  +  msg="int"
  +else
  +  msg="pointer"
  +fi
  +AC_MSG_RESULT([$msg])
  +] )
   dnl
   dnl APR_CHECK_ICONV_INBUF
   dnl
  
  
  
  1.44      +41 -1     apr/misc/unix/errorcodes.c
  
  Index: errorcodes.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/errorcodes.c,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- errorcodes.c	2001/09/04 21:20:57	1.43
  +++ errorcodes.c	2001/11/12 01:16:00	1.44
  @@ -357,11 +357,51 @@
   }
   #endif
   
  +#if defined(HAVE_STRERROR_R) && defined(STRERROR_R_RC_INT)
  +/* AIX and Tru64 style */
  +static char *native_strerror(apr_status_t statcode, char *buf,
  +                             apr_size_t bufsize)
  +{
  +    if (strerror_r(statcode, buf, bufsize) < 0) {
  +        return stuffbuffer(buf, bufsize, 
  +                           "APR does not understand this error code");
  +    }
  +    else {
  +        return buf;
  +    }
  +}
  +#elif defined(HAVE_STRERROR_R)
  +/* glibc style */
  +static char *native_strerror(apr_status_t statcode, char *buf,
  +                             apr_size_t bufsize)
  +{
  +    const char *msg;
  +
  +    buf[0] = '\0';
  +    msg = strerror_r(statcode, buf, bufsize);
  +    if (buf[0] == '\0') { /* libc didn't use our buffer */
  +        return stuffbuffer(buf, bufsize, msg);
  +    }
  +    else {
  +        return buf;
  +    }
  +}
  +#else
  +/* plain old strerror(); 
  + * thread-safe on some platforms (e.g., Solaris, OS/390)
  + */
  +static char *native_strerror(apr_status_t statcode, char *buf,
  +                             apr_size_t bufsize)
  +{
  +    return stuffbuffer(buf, bufsize, strerror(statcode));
  +}
  +#endif
  +
   APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
                                    apr_size_t bufsize)
   {
       if (statcode < APR_OS_START_ERROR) {
  -        return stuffbuffer(buf, bufsize, strerror(statcode));
  +        return native_strerror(statcode, buf, bufsize);
       }
       else if (statcode < APR_OS_START_USEERR) {
           return stuffbuffer(buf, bufsize, apr_error_string(statcode));
  
  
  

Mime
View raw message