]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/compat: Add missing win32 type and constant definitions
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Mon, 4 Nov 2019 08:49:31 +0000 (08:49 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 4 Jun 2020 15:51:40 +0000 (15:51 +0000)
The following types and constants are not defined on Windows, for
which reason we're going to include them in compat.h.

* uid_t, gid_t
* sigset_t
* HOST_NAME_MAX
* O_CLOEXEC, which we're going to define as a no-op. By default,
  handles are not inherited by subprocesses.
* SHUT_* flags
* loff_t
* __STRING
* EBADE, ENODATA, ESHUTDOWN, ESTALE, EREMOTEIO
* suseconds_t
* SIGKILL, SIGINT - we're mostly going to stub signal handling
on Windows

Also, we'll have to make sure that pipe_cloexec uses C style linking,
which would otherwise be affected as the include order changes.

timeval.tv_sec is defined as long instead of time_t on Windows[1], which
we'll have to take into account.

[1] https://docs.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-timeval

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/ceph_context.h
src/crush/CrushCompiler.cc
src/include/ceph_assert.h
src/include/compat.h
src/include/statlite.h
src/log/LogClock.h

index 187cd3d165a7ab0e8406d129645f1d397d664e0a..3d1cff123c7e00543d372d05f0f44a69f2bde977 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "include/any.h"
 #include "include/common_fwd.h"
+#include "include/compat.h"
 
 #include "common/cmdparse.h"
 #include "common/code_environment.h"
index eafda63afa7535635d9f9cc7fba21546ea1849ed..9b4153f2563dbef188d059cf47a6274e0e6dcf82 100644 (file)
@@ -7,6 +7,10 @@
 #define EBADE ECORRUPT
 #endif
 
+#if defined(_WIN32)
+#define EBADE EINVAL
+#endif
+
 #ifndef EBADE
 #define EBADE EFTYPE
 #endif
index c0df90ce1450ae156540580e611fd5e8c18a6c08..0627894ea6e07d5d4451d3be29f9ab09b75cc6d7 100644 (file)
@@ -4,13 +4,13 @@
 #include <cstdlib>
 #include <string>
 
-#if defined(__linux__)
-#include <features.h>
-
 #ifndef __STRING
 # define __STRING(x) #x
 #endif
 
+#if defined(__linux__)
+#include <features.h>
+
 #elif defined(__FreeBSD__)
 #include <sys/cdefs.h>
 #define        __GNUC_PREREQ(minor, major)     __GNUC_PREREQ__(minor, major)
index bfb12579d692c5282cdaf6ec6dc1a47c6eb10ed1..ceb55896a47b4ad31a83d33e13cf079371a71ef4 100644 (file)
@@ -103,15 +103,15 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize,
 #define XATTR_CREATE 1
 #endif
 
+#endif /* __APPLE__ */
+
 #ifndef HOST_NAME_MAX
 #ifdef MAXHOSTNAMELEN 
 #define HOST_NAME_MAX MAXHOSTNAMELEN 
 #else
 #define HOST_NAME_MAX 255
 #endif
-#endif
-
-#endif /* __APPLE__ */
+#endif /* HOST_NAME_MAX */
 
 /* O_LARGEFILE is not defined/required on OSX/FreeBSD */
 #ifndef O_LARGEFILE
@@ -193,16 +193,56 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize,
 
 int ceph_posix_fallocate(int fd, off_t offset, off_t len);
 
-int pipe_cloexec(int pipefd[2], int flags);
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+int pipe_cloexec(int pipefd[2], int flags);
 char *ceph_strerror_r(int errnum, char *buf, size_t buflen);
 
 #ifdef __cplusplus
 }
 #endif
 
+#if defined(_WIN32)
+
+typedef _sigset_t sigset_t;
+
+typedef int uid_t;
+typedef int gid_t;
+
+typedef long blksize_t;
+typedef long blkcnt_t;
+typedef long nlink_t;
+
+typedef long long loff_t;
+
+#define SHUT_RD SD_RECEIVE
+#define SHUT_WR SD_SEND
+#define SHUT_RDWR SD_BOTH
+
+#ifndef SIGINT
+#define SIGINT 2
+#endif
+
+#ifndef SIGKILL
+#define SIGKILL 9
+#endif
+
+#ifndef ENODATA
+// mingw doesn't define this, the Windows SDK does.
+#define ENODATA 120
+#endif
+
+#define ESHUTDOWN ECONNABORTED
+#define ESTALE 256
+#define EREMOTEIO 257
+
+// O_CLOEXEC is not defined on Windows. Since handles aren't inherited
+// with subprocesses unless explicitly requested, we'll define this
+// flag as a no-op.
+#define O_CLOEXEC 0
+
+#endif /* WIN32 */
+
 #endif /* !CEPH_COMPAT_H */
index 2ab3a940687d51675e22636cbd912569d7c3ee85..0ff4b04e71d08c04b2aec7cea0b9da22928d3bfd 100644 (file)
@@ -11,6 +11,8 @@ extern "C" {
 #include <unistd.h>
 #include <dirent.h>
 
+#include "include/compat.h"
+
 struct statlite {
   dev_t         st_dev;      /* device */
   ino_t         st_ino;      /* inode */
index 98d8c17f7ed7365ed187943f51643d194b45513c..6648f44f0b7072f02f4907782ff5cd69d131e3c9 100644 (file)
 #include "include/ceph_assert.h"
 #include "common/ceph_time.h"
 
+#ifndef suseconds_t
+typedef long suseconds_t;
+#endif
+
 namespace ceph {
 namespace logging {
 namespace _logclock {
@@ -130,7 +134,7 @@ inline int append_time(const log_time& t, char *out, int outlen) {
   bool coarse = t.time_since_epoch().count().coarse;
   auto tv = log_clock::to_timeval(t);
   std::tm bdt;
-  localtime_r(&tv.tv_sec, &bdt);
+  localtime_r((time_t*)&tv.tv_sec, &bdt);
   char tz[32] = { 0 };
   strftime(tz, sizeof(tz), "%z", &bdt);