fix includes
[m6w6/libmemcached] / src / libmemcached / windows.hpp
index 40564b1d46f752e8be0388dab850e0e4e4a04c53..b867a6d4718025242f26160335acbf10de10e016 100644 (file)
 /*
- * Libmemcached library
- *
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- *     * 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.
- *
- *     * The names of its contributors may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS 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 COPYRIGHT
- * OWNER OR 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.
- *
- */
+    +--------------------------------------------------------------------+
+    | libmemcached - C/C++ Client Library for memcached                  |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted under the terms of the BSD license.    |
+    | You should have received a copy of the license in a bundled file   |
+    | named LICENSE; in case you did not receive a copy you can review   |
+    | the terms online at: https://opensource.org/licenses/BSD-3-Clause  |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2006-2014 Brian Aker   https://datadifferential.com/ |
+    | Copyright (c) 2020 Michael Wallner   <mike@php.net>                |
+    +--------------------------------------------------------------------+
+*/
 
 #pragma once
 
 #ifdef __cplusplus
-# include <cerrno>
+#  include <cerrno>
 #else
-# include <errno.h>
+#  include <errno.h>
 #endif
 
 #ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
+#  define WIN32_LEAN_AND_MEAN
 #endif
 
-#ifndef _WIN32_WINNT
-# define _WIN32_WINNT 0x0501
-#endif
-
-#ifdef __MINGW32__
-# if(_WIN32_WINNT >= 0x0501)
-# else
-#  undef _WIN32_WINNT
-#  define _WIN32_WINNT 0x0501
-# endif /* _WIN32_WINNT >= 0x0501 */
-#endif /* __MINGW32__ */
-
 #if defined(HAVE_WINSOCK2_H) && HAVE_WINSOCK2_H
-# include <winsock2.h>
+#  include <winsock2.h>
 #endif
 
 #if defined(HAVE_WS2TCPIP_H) && HAVE_WS2TCPIP_H
-# include <ws2tcpip.h>
+#  include <ws2tcpip.h>
 #endif
 
 #if defined(HAVE_IO_H) && HAVE_IO_H
-# include <io.h>
+#  include <io.h>
 #endif
 
-struct sockaddr_un
-{
+struct sockaddr_un {
   short int sun_family;
   char sun_path[108];
 };
 
-static inline int translate_windows_error()
-{
-  int local_errno= WSAGetLastError();
+static inline int translate_windows_error() {
+  int local_errno = WSAGetLastError();
 
-  switch(local_errno) {
+  switch (local_errno) {
   case WSAEINVAL:
-    local_errno= EINPROGRESS;
+    local_errno = EINPROGRESS;
     break;
   case WSAEALREADY:
   case WSAEWOULDBLOCK:
-    local_errno= EAGAIN;
+    local_errno = EAGAIN;
     break;
 
   case WSAECONNREFUSED:
-    local_errno= ECONNREFUSED;
+    local_errno = ECONNREFUSED;
     break;
 
   case WSAENETUNREACH:
-    local_errno= ENETUNREACH;
+    local_errno = ENETUNREACH;
     break;
 
   case WSAETIMEDOUT:
-    local_errno= ETIMEDOUT;
+    local_errno = ETIMEDOUT;
     break;
 
   case WSAECONNRESET:
-    local_errno= ECONNRESET;
+    local_errno = ECONNRESET;
     break;
 
   case WSAEADDRINUSE:
-    local_errno= EADDRINUSE;
+    local_errno = EADDRINUSE;
     break;
 
   case WSAEOPNOTSUPP:
-    local_errno= EOPNOTSUPP;
+    local_errno = EOPNOTSUPP;
     break;
 
   case WSAENOPROTOOPT:
-    local_errno= ENOPROTOOPT;
+    local_errno = ENOPROTOOPT;
     break;
 
   default:
@@ -123,3 +88,14 @@ static inline int translate_windows_error()
 
   return local_errno;
 }
+
+static inline char *basename(const char *filename) {
+  static char base[MAX_PATH * 2], ext[MAX_PATH], *ptr;
+  (void) _splitpath_s(filename, NULL, 0, NULL, 0, base, MAX_PATH, ext, MAX_PATH);
+  strcat_s(base, MAX_PATH * 2 - 1, ext);
+  return base;
+}
+
+static inline char *realpath(const char *path, char real[MAX_PATH]) {
+  return _fullpath(real, path, MAX_PATH);
+}
\ No newline at end of file