httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/misc/win32 errorcodes.c
Date Wed, 26 Apr 2000 15:33:38 GMT
stoddard    00/04/26 08:33:37

  Modified:    src/lib/apr/misc/unix errorcodes.c
               src/lib/apr/misc/win32 errorcodes.c
  Log:
  Fix ap_strerror. It should both fill the user supplied buffer with the
  message string and return a pointer to that same buffer (for convenience).
  
  Revision  Changes    Path
  1.10      +46 -33    apache-2.0/src/lib/apr/misc/unix/errorcodes.c
  
  Index: errorcodes.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/errorcodes.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- errorcodes.c	2000/04/26 02:42:58	1.9
  +++ errorcodes.c	2000/04/26 15:33:36	1.10
  @@ -54,6 +54,20 @@
   
   #include "misc.h"
   
  +/*
  + * stuffbuffer - Stuff contents of string 's' into buffer 'buf' 
  + * w/o overflowing 'buf' then NULL terminate.
  + */
  +static char *stuffbuffer(char *buf, ap_size_t bufsize, const char *s)
  +{
  +    ap_size_t len = strlen(s);
  +    if (len > bufsize)
  +        len = bufsize;
  +    memcpy(buf, s, len);
  +    if (len)
  +        buf[len-1] = '\0';
  +    return buf;
  +}
   
   static char *apr_error_string(ap_status_t statcode)
   {
  @@ -131,38 +145,13 @@
       }
   }
   
  -#ifdef WIN32
  -#error "not implemented yet"
  -#elif OS2
  -static char *apr_os_strerror(int err, char *buf, ap_size_t bufsize);
  -#else
  -#define apr_os_strerror(err, buf, bufsize)	strerror(err)
  -#endif
   
  -char *ap_strerror(ap_status_t statcode, char *buf, ap_size_t bufsize)
  -{
  -    if (statcode < APR_OS_START_ERROR) {
  -        return strerror(statcode);
  -    }
  -    else if (statcode < APR_OS_START_USEERR) {
  -        return apr_error_string(statcode);
  -    }
  -    else if (statcode < APR_OS_START_SYSERR) {
  -        return "APR does not understand this error code";
  -    }
  -    else {
  -	return apr_os_strerror(statcode - APR_OS_START_SYSERR, buf, bufsize);
  -    }
  -}
  -
  -
  -
   #ifdef OS2
   #define INCL_DOS
   #include <os2.h>
   #include <ctype.h>
   
  -static char *apr_os_strerror(int err, char* buf, ap_size_t bufsize)
  +static char *apr_os_strerror(char* buf, ap_size_t bufsize, int err)
   {
     char result[200];
     unsigned char message[HUGE_STRING_LEN];
  @@ -171,7 +160,8 @@
     int c;
     
     if (err >= 10000 && err < 12000) {  /* socket error codes */
  -      return strerror(ap_canonical_error(err+APR_OS_START_SYSERR));
  +      return stuffbuffer(buf, bufsize,
  +                         strerror(ap_canonical_error(err+APR_OS_START_SYSERR)));
     } 
     else if (DosGetMessage(NULL, 0, message, HUGE_STRING_LEN, err,
   			 "OSO001.MSG", &len) == 0) {
  @@ -194,12 +184,35 @@
     else {
         sprintf(result, "OS/2 error %d", err);
     }
  -  
  -  if (len > bufsize)
  -      len = bufsize;
   
  -  memcpy(buf, result, len);
  -
  -  return buf;
  +  /* Stuff the string into the caller supplied buffer, then return 
  +   * a pointer to it.
  +   */
  +  return stuffbuffer(buf, bufsize, result);  
   }
  +#else
  +static char *apr_os_strerror(char* buf, ap_size_t bufsize, int err) 
  +{
  +    	return stuffbuffer(buf, bufsize,strerror(err));
  +}
   #endif
  +
  +char *ap_strerror(ap_status_t statcode, char *buf, ap_size_t bufsize)
  +{
  +    char *msg;
  +    ap_size_t len;
  +
  +    if (statcode < APR_OS_START_ERROR) {
  +        return stuffbuffer(buf, bufsize, strerror(statcode));
  +    }
  +    else if (statcode < APR_OS_START_USEERR) {
  +        return stuffbuffer(buf, bufsize, apr_error_string(statcode));
  +    }
  +    else if (statcode < APR_OS_START_SYSERR) {
  +        return stuffbuffer(buf, bufsize, "APR does not understand this error code");
  +    }
  +    else {
  +	return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
  +    }
  +}
  +
  
  
  
  1.8       +25 -10    apache-2.0/src/lib/apr/misc/win32/errorcodes.c
  
  Index: errorcodes.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/win32/errorcodes.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- errorcodes.c	2000/04/26 02:43:00	1.7
  +++ errorcodes.c	2000/04/26 15:33:37	1.8
  @@ -55,6 +55,24 @@
   #include "apr_lib.h"
   #include "misc.h"
   
  +/* Todo: Merge this code with the code in the misc/unix directory.
  + * Most of it is common
  + */
  +
  +/*
  + * stuffbuffer - Stuff contents of string 's' into buffer 'buf' 
  + * w/o overflowing 'buf' then NULL terminate.
  + */
  +static char *stuffbuffer(char *buf, ap_size_t bufsize, const char *s)
  +{
  +    ap_size_t len = strlen(s);
  +    if (len > bufsize)
  +        len = bufsize;
  +    memcpy(buf, s, len);
  +    if (len)
  +        buf[len-1] = '\0';
  +    return buf;
  +}
   
   static char *apr_error_string(ap_status_t statcode)
   {
  @@ -120,9 +138,8 @@
       case APR_KEYBASED:
           return "Shared memory is implemented using a key system";
       case APR_EINIT:
  -        return
  -	    "There is no error, this value signifies an initialized "
  -	    "error code";
  +        return "There is no error, this value signifies an initialized "
  +              "error code";
       case APR_ENOTIMPL:
           return "This function has not been implemented on this platform";
       case APR_EMISMATCH:
  @@ -132,7 +149,7 @@
       }
   }
   
  -static char *ap_os_format_message(ap_status_t errcode, char *buf, ap_size_t bufsize)
  +static char *apr_os_strerror(char *buf, ap_size_t bufsize, ap_status_t errcode)
   {
       DWORD len;
       DWORD i;
  @@ -165,17 +182,15 @@
   char *ap_strerror(ap_status_t statcode, char* buf, ap_size_t bufsize)
   {
       if (statcode < APR_OS_START_ERROR) {
  -        return ap_os_format_message(statcode, buf, bufsize);
  +        return apr_os_strerror(buf, bufsize, statcode);
       }
       else if (statcode < APR_OS_START_USEERR) {
  -        return apr_error_string(statcode);
  +        return stuffbuffer(buf, bufsize, apr_error_string(statcode));
       }
       else if (statcode < APR_OS_START_SYSERR) {
  -        return "APR does not understand this error code";
  +        return stuffbuffer(buf, bufsize, "APR does not understand this error code");
       }
       else {
  -	return ap_os_format_message(statcode - APR_OS_START_SYSERR, buf, bufsize);
  +	return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
       }
   }
  -
  -
  
  
  

Mime
View raw message