From: Lucian Petrut Date: Thu, 19 Dec 2019 11:30:05 +0000 (+0000) Subject: common: Extend win32 compatbility layer X-Git-Tag: v16.1.0~652^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=78bbf804e98f238e19793028996d86f3e38ab3c2;p=ceph.git common: Extend win32 compatbility layer 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 --- diff --git a/src/common/compat.cc b/src/common/compat.cc index 01c502313ad7..f78822ef1566 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -23,6 +23,8 @@ #include #ifndef _WIN32 #include +#else +#include #endif #include #include @@ -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 */ diff --git a/src/include/compat.h b/src/include/compat.h index 766067c86722..f1eb0701daee 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -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 diff --git a/src/include/coredumpctl.h b/src/include/coredumpctl.h index 60fab4323674..60b91e999034 100644 --- a/src/include/coredumpctl.h +++ b/src/include/coredumpctl.h @@ -49,8 +49,8 @@ public: }; #else -#include #ifdef RLIMIT_CORE +#include #include #include #include "common/errno.h"