[rtems-tools commit] record: Windows compatibility

Sebastian Huber sebh at rtems.org
Tue Sep 10 09:01:53 UTC 2019


Module:    rtems-tools
Branch:    master
Commit:    a2e7158792f88d8b2734ecfb3424cb873ff43083
Changeset: http://git.rtems.org/rtems-tools/commit/?id=a2e7158792f88d8b2734ecfb3424cb873ff43083

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Sep 10 10:04:51 2019 +0200

record: Windows compatibility

Update #3665.

---

 trace/record/record-client-base.cc | 19 +++++++++++++++----
 trace/wscript                      |  9 +++++++--
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/trace/record/record-client-base.cc b/trace/record/record-client-base.cc
index 01ed803..ac88eab 100644
--- a/trace/record/record-client-base.cc
+++ b/trace/record/record-client-base.cc
@@ -27,12 +27,18 @@
 
 #include "client.h"
 
+#ifdef _WIN32
+#include <io.h>
+#include <winsock2.h>
+#else
 #include <arpa/inet.h>
-#include <fcntl.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
-#include <sys/stat.h>
 #include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <sys/stat.h>
 
 #include <cassert>
 #include <cstring>
@@ -42,13 +48,18 @@ static ssize_t ReadFile(int fd, void* buf, size_t n) {
 }
 
 static ssize_t ReadSocket(int fd, void* buf, size_t n) {
-  return ::recv(fd, buf, n, 0);
+  // This cast is necessary for Windows
+  return ::recv(fd, static_cast<char*>(buf), n, 0);
 }
 
 void FileDescriptor::Open(const char* file) {
   assert(fd_ == -1);
 
-  fd_ = ::open(file, O_RDONLY);
+  int oflag = O_RDONLY;
+#ifdef _WIN32
+  oflag |= O_BINARY;
+#endif
+  fd_ = ::open(file, oflag);
   if (fd_ < 0) {
     throw ErrnoException(std::string("cannot open file '") + file + "'");
   }
diff --git a/trace/wscript b/trace/wscript
index 9bac9b9..a2124ad 100644
--- a/trace/wscript
+++ b/trace/wscript
@@ -33,6 +33,7 @@ def options(opt):
 def configure(conf):
     conf.load('compiler_c')
     conf.load('compiler_cxx')
+    conf.check_cxx(lib = 'ws2_32', mandatory=False)
 
 def build(bld):
     #
@@ -46,7 +47,10 @@ def build(bld):
     conf['warningflags'] = ['-Wall', '-Wextra', '-pedantic']
     conf['optflags'] = bld.env.C_OPTS
     conf['cflags'] = ['-pipe', '-g'] + conf['optflags']
-    conf['linkflags'] = ['-g']
+    conf['cxxflags'] = ['-std=c++11'] + conf['cflags']
+    conf['lib'] = []
+    if bld.env.LIB_WS2_32:
+        conf['lib'].extend(bld.env.LIB_WS2_32)
 
     #
     # The list of defines
@@ -65,7 +69,8 @@ def build(bld):
                 includes = ['record'],
                 defines = defines,
                 cflags = conf['cflags'] + conf['warningflags'],
-                linkflags = conf['linkflags'])
+                cxxflags = conf['cxxflags'] + conf['warningflags'],
+                lib = conf['lib'])
 
 def tags(ctx):
     ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)



More information about the vc mailing list