]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Extend win32 compatbility layer
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 19 Dec 2019 11:30:05 +0000 (11:30 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Mon, 12 Oct 2020 09:28:42 +0000 (09:28 +0000)
For Windows compatibility, we're defining the following:

* random
* get_page_size
* setenv
* unsetenv
* _putenv_s - defined by Windows headers but not exposed by Mingw
              when _POSIX is set

* EDQUOT
* uint

While at it, we're going to avoid importing sys/resourcectl.h on
Windows.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/compat.cc
src/include/compat.h
src/include/coredumpctl.h

index 01c502313ad721521765ca1938ba38b291b51976..f78822ef1566cc972f2c818295c73a70a81b065c 100644 (file)
@@ -23,6 +23,8 @@
 #include <thread>
 #ifndef _WIN32
 #include <sys/mount.h>
+#else
+#include <stdlib.h>
 #endif
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -279,6 +281,10 @@ long int lrand48(void) {
   return val;
 }
 
+int random() {
+  return rand();
+}
+
 int fsync(int fd) {
   HANDLE handle = (HANDLE*)_get_osfhandle(fd);
   if (handle == INVALID_HANDLE_VALUE)
@@ -457,4 +463,23 @@ int win_socketpair(int socks[2])
     return SOCKET_ERROR;
 }
 
+unsigned get_page_size() {
+  SYSTEM_INFO system_info;
+  GetSystemInfo(&system_info);
+  return system_info.dwPageSize;
+}
+
+int setenv(const char *name, const char *value, int overwrite) {
+  if (!overwrite && getenv(name)) {
+    return 0;
+  }
+  return _putenv_s(name, value);
+}
+
+#else
+
+unsigned get_page_size() {
+  return sysconf(_SC_PAGESIZE);
+}
+
 #endif /* _WIN32 */
index 766067c86722c16c693df1903617aa55f1147a8f..f1eb0701daeeddd7369e39827b98d80355ca84e7 100644 (file)
@@ -200,6 +200,7 @@ extern "C" {
 
 int pipe_cloexec(int pipefd[2], int flags);
 char *ceph_strerror_r(int errnum, char *buf, size_t buflen);
+unsigned get_page_size();
 
 #ifdef __cplusplus
 }
@@ -221,6 +222,10 @@ char *ceph_strerror_r(int errnum, char *buf, size_t buflen);
 #define WIN32_ERROR 0
 #undef ERROR
 
+#ifndef uint
+typedef unsigned int uint;
+#endif
+
 typedef _sigset_t sigset_t;
 
 typedef int uid_t;
@@ -262,6 +267,10 @@ struct iovec {
 #define ENODATA 120
 #endif
 
+#ifndef EDQUOT
+#define EDQUOT ENOSPC
+#endif
+
 #define ESHUTDOWN ECONNABORTED
 #define ESTALE 256
 #define EREMOTEIO 257
@@ -280,6 +289,7 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset);
 ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
 
 long int lrand48(void);
+int random();
 
 int pipe(int pipefd[2]);
 
@@ -290,9 +300,15 @@ char *strptime(const char *s, const char *format, struct tm *tm);
 int chown(const char *path, uid_t owner, gid_t group);
 int fchown(int fd, uid_t owner, gid_t group);
 int lchown(const char *path, uid_t owner, gid_t group);
+int setenv(const char *name, const char *value, int overwrite);
+#define unsetenv(name) _putenv_s(name, "")
 
 int win_socketpair(int socks[2]);
 
+#ifdef __MINGW32__
+extern _CRTIMP errno_t __cdecl _putenv_s(const char *_Name,const char *_Value);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 60fab43236744dc9a2daba2d0ae5f46301e59bcb..60b91e999034b1885ee4f493ebb4240c9ff4178b 100644 (file)
@@ -49,8 +49,8 @@ public:
 };
 
 #else
-#include <sys/resource.h>
 #ifdef RLIMIT_CORE
+#include <sys/resource.h>
 #include <iostream>
 #include <sys/resource.h>
 #include "common/errno.h"