httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/misc/win32 common.c canonerr.c errorcodes.c getopt.c misc.h start.c
Date Wed, 17 May 2000 22:31:17 GMT
rbb         00/05/17 15:31:15

  Modified:    src/lib/apr/misc/unix canonerr.c errorcodes.c getopt.c
                        misc.h start.c
  Added:       src/lib/apr/misc/win32 common.c
  Removed:     src/lib/apr/misc/win32 canonerr.c errorcodes.c getopt.c
                        misc.h start.c
  Log:
  Merging windows and Unix common misc files.
  
  Revision  Changes    Path
  1.4       +1 -1      apache-2.0/src/lib/apr/misc/unix/canonerr.c
  
  Index: canonerr.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/canonerr.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- canonerr.c	2000/04/23 13:22:05	1.3
  +++ canonerr.c	2000/05/17 22:30:49	1.4
  @@ -58,7 +58,7 @@
   
   int ap_canonical_error(ap_status_t errcode)
   {
  -#if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK)
  +#if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK)
&& !defined(WIN32)
       if (errcode == EWOULDBLOCK) {
           errcode = EAGAIN;
       }
  
  
  
  1.14      +50 -2     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- errorcodes.c	2000/04/28 23:20:38	1.13
  +++ errorcodes.c	2000/05/17 22:30:49	1.14
  @@ -189,8 +189,46 @@
      */
     return stuffbuffer(buf, bufsize, result);  
   }
  -#else
   
  +#elif defined(WIN32)
  +
  +static char *apr_os_strerror(char *buf, ap_size_t bufsize, ap_status_t errcode)
  +{
  +    DWORD len;
  +    DWORD i;
  +
  +    len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  +                        NULL,
  +                        errcode,
  +                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language
*/
  +                        (LPTSTR) buf,
  +                        bufsize,
  +                        NULL);
  +
  +    if (len) {
  +        /* FormatMessage put the message in the buffer, but it may
  +         * have embedded a newline (\r\n), and possible more than one.
  +         * Remove the newlines replacing them with a space. This is not
  +         * as visually perfect as moving all the remaining message over,
  +         * but more efficient.
  +         */
  +        i = len;
  +        while (i) {
  +            i--;
  +            if ((buf[i] == '\r') || (buf[i] == '\n'))
  +                buf[i] = ' ';
  +        }
  +    }
  +    else {
  +        /* Windows didn't provide us with a message.  Even stuff like                 
  * WSAECONNREFUSED won't get a message.
  +         */
  +        ap_cpystrn(buf, "Unrecognized error code", bufsize);
  +    }
  +
  +    return buf;
  +}
  +
  +#else
   /* On Unix, apr_os_strerror() handles error codes from the resolver 
    * (h_errno). 
    e*/
  @@ -228,7 +266,17 @@
   char *ap_strerror(ap_status_t statcode, char *buf, ap_size_t bufsize)
   {
       if (statcode < APR_OS_START_ERROR) {
  +#ifdef WIN32
  +        /* XXX This is just plain wrong.  We started discussing this one
  +         * day, and then it dropped, but doing this here is a symptom of a
  +         * problem with the design that will keep us from safely sharing 
  +         * Windows code with any other platform.  This needs to be changed, 
  +         * Windows is NOT a special platform when it comes to APR. rbb
  +         */
  +        return apr_os_strerror(buf, bufsize, statcode);
  +#else
           return stuffbuffer(buf, bufsize, strerror(statcode));
  +#endif
       }
       else if (statcode < APR_OS_START_USEERR) {
           return stuffbuffer(buf, bufsize, apr_error_string(statcode));
  @@ -237,7 +285,7 @@
           return stuffbuffer(buf, bufsize, "APR does not understand this error code");
       }
       else {
  -	return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
  +        return apr_os_strerror(buf, bufsize, statcode - APR_OS_START_SYSERR);
       }
   }
   
  
  
  
  1.11      +3 -2      apache-2.0/src/lib/apr/misc/unix/getopt.c
  
  Index: getopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/getopt.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- getopt.c	2000/05/16 17:04:09	1.10
  +++ getopt.c	2000/05/17 22:30:50	1.11
  @@ -33,11 +33,12 @@
   
   #include "misc.h"
   
  -int ap_opterr = 1,                      /* if error message should be printed */
  +API_VAR_EXPORT int
  +    ap_opterr = 1,                      /* if error message should be printed */
       ap_optind = 1,                      /* index into parent argv vector */
       ap_optopt,                          /* character checked for validity */
       ap_optreset;                        /* reset getopt */
  -char *ap_optarg = "";                   /* argument associated with option */
  +API_VAR_EXPORT char *ap_optarg = "";    /* argument associated with option */
   
   #define EMSG    ""
   
  
  
  
  1.17      +76 -0     apache-2.0/src/lib/apr/misc/unix/misc.h
  
  Index: misc.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/misc.h,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- misc.h	2000/05/16 17:04:09	1.16
  +++ misc.h	2000/05/17 22:30:50	1.17
  @@ -61,7 +61,9 @@
   #include "apr_pools.h"
   #include "apr_getopt.h"
   #include "apr_thread_proc.h"
  +#include "apr_file_io.h"
   #include "apr_errno.h"
  +#include "apr_getopt.h"
   #ifdef HAVE_STDLIB_H
   #include <stdlib.h>
   #endif
  @@ -96,6 +98,80 @@
       int write_fd;
   };
   
  +#ifdef WIN32
  +#define WSAHighByte 2
  +#define WSALowByte 0
  +/* Platform specific designation of run time os version.
  + * Gaps allow for specific service pack levels that
  + * export new kernel or winsock functions or behavior.
  + */
  +typedef enum {
  +        APR_WIN_95 = 0,
  +        APR_WIN_98 = 4,
  +        APR_WIN_NT = 8,
  +        APR_WIN_NT_4 = 12,
  +        APR_WIN_NT_4_SP2 = 14,
  +        APR_WIN_NT_4_SP3 = 15,
  +        APR_WIN_NT_4_SP4 = 16,
  +        APR_WIN_NT_4_SP6 = 18,
  +        APR_WIN_2000 = 24
  +} ap_oslevel_e;
  +
  +
  +typedef enum {
  +    DLL_WINBASEAPI = 0,    // kernel32 From WinBase.h
  +    DLL_WINADVAPI = 1,     // advapi32 From WinBase.h
  +    DLL_WINSOCKAPI = 2,    // mswsock  From WinSock.h
  +    DLL_WINSOCK2API = 3,   // ws2_32   From WinSock2.h
  +    DLL_defined = 4        // must define as last idx_ + 1
  +} ap_dlltoken_e;
  +
  +FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char *fnName, int ordinal);
  +
  +/* The ap_load_dll_func call WILL fault if the function cannot be loaded */
  +
  +#define AP_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \
  +    typedef rettype (calltype *ap_winapi_fpt_##fn) args; \
  +    static ap_winapi_fpt_##fn ap_winapi_pfn_##fn = NULL; \
  +    __inline rettype ap_winapi_##fn args \
  +    {   if (!ap_winapi_pfn_##fn) \
  +            ap_winapi_pfn_##fn = (ap_winapi_fpt_##fn) ap_load_dll_func(lib, #fn, ord);
\
  +        return (*(ap_winapi_pfn_##fn)) names; }; \
  +
  +/* Provide late bound declarations of every API function missing from
  + * one or more supported releases of the Win32 API
  + *
  + * lib is the enumerated token from ap_dlltoken_e, and must correspond
  + * to the string table entry in start.c used by the ap_load_dll_func().
  + * Token names (attempt to) follow Windows.h declarations prefixed by DLL_
  + * in order to facilitate comparison.  Use the exact declaration syntax
  + * and names from Windows.h to prevent ambigutity and bugs.
  + *
  + * rettype and calltype follow the original declaration in Windows.h
  + * fn is the true function name - beware Ansi/Unicode #defined macros
  + * ord is the ordinal within the library, use 0 if it varies between versions
  + * args is the parameter list following the original declaration, in parens
  + * names is the parameter list sans data types, enclosed in parens
  + *
  + * #undef/re#define the Ansi/Unicode generic name to abate confusion
  + * In the case of non-text functions, simply #define the original name
  + */
  +
  +AP_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, GetFileAttributesExA, 0, (
  +    IN LPCSTR lpFileName,
  +    IN GET_FILEEX_INFO_LEVELS fInfoLevelId,
  +    OUT LPVOID lpFileInformation),
  +    (lpFileName, fInfoLevelId, lpFileInformation));
  +#undef GetFileAttributesEx
  +#define GetFileAttributesEx ap_winapi_GetFileAttributesExA
  +
  +AP_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, (
  +    IN HANDLE hFile),
  +    (hFile));
  +#define CancelIo ap_winapi_CancelIo
  +
  +ap_status_t ap_get_oslevel(struct ap_pool_t *, ap_oslevel_e *);
  +#endif /* WIN32 */
   
   #endif  /* ! MISC_H */
   
  
  
  
  1.32      +16 -1     apache-2.0/src/lib/apr/misc/unix/start.c
  
  Index: start.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/start.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- start.c	2000/04/30 21:17:56	1.31
  +++ start.c	2000/05/17 22:30:51	1.32
  @@ -140,8 +140,23 @@
   ap_status_t ap_initialize(void)
   {
       ap_status_t status;
  -#if !defined(BEOS) && !defined(OS2)
  +#if !defined(BEOS) && !defined(OS2) && !defined(WIN32)
       ap_unix_setup_lock();
  +#elif defined WIN32
  +    int iVersionRequested;
  +    WSADATA wsaData;
  +    int err;
  +
  +    iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
  +    err = WSAStartup((WORD) iVersionRequested, &wsaData);
  +    if (err) {
  +        return err;
  +    }
  +    if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
  +        HIBYTE(wsaData.wVersion) != WSALowByte) {
  +        WSACleanup();
  +        return APR_EEXIST;
  +    }
   #endif
       status = ap_init_alloc();
       return status;
  
  
  
  1.1                  apache-2.0/src/lib/apr/misc/win32/common.c
  
  Index: common.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "../unix/canonerr.c"
  
  #include "../unix/getopt.c"
  
  #include "../unix/errorcodes.c"
  
  #include "../unix/start.c"
  
  
  

Mime
View raw message