]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add win32/wstring.h
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 16 Nov 2022 08:50:14 +0000 (10:50 +0200)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 22 Mar 2023 14:34:52 +0000 (14:34 +0000)
Windows APIs heavily use wchar. ceph-dokan and rbd-wnbd
have some duplicated helpers that convert wstrings to/from
utf8 strings.

To avoid duplication and allow reusing those helpers, we're moving
them to common/win32/wstring.h.

We're using the "win32" subfolder because it's unlikely that this
will ever be used on other platforms.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/CMakeLists.txt
src/common/win32/wstring.cc [new file with mode: 0644]
src/common/win32/wstring.h [new file with mode: 0644]
src/dokan/ceph_dokan.cc
src/dokan/options.cc
src/dokan/utils.cc
src/dokan/utils.h
src/tools/rbd_wnbd/rbd_wnbd.cc

index 498b2662868af98ebec9ce39736bf16c5c8583fb..1297df32405aae00f2ed7f1c9742065d48fb25bc 100644 (file)
@@ -173,6 +173,7 @@ elseif(AIX)
   list(APPEND common_srcs aix_errno.cc)
 elseif(WIN32)
   list(APPEND common_srcs win32/errno.cc)
+  list(APPEND common_srcs win32/wstring.cc)
 endif()
 
 if(WITH_EVENTTRACE)
diff --git a/src/common/win32/wstring.cc b/src/common/win32/wstring.cc
new file mode 100644 (file)
index 0000000..1f9b49a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2022 Cloudbase Solutions
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "wstring.h"
+
+#include <boost/locale/encoding_utf.hpp>
+
+using boost::locale::conv::utf_to_utf;
+
+std::wstring to_wstring(const std::string& str)
+{
+  return utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
+}
+
+std::string to_string(const std::wstring& str)
+{
+  return utf_to_utf<char>(str.c_str(), str.c_str() + str.size());
+}
diff --git a/src/common/win32/wstring.h b/src/common/win32/wstring.h
new file mode 100644 (file)
index 0000000..cb308c7
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2022 Cloudbase Solutions
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#pragma once
+
+#include <string>
+
+std::wstring to_wstring(const std::string& str);
+std::string to_string(const std::wstring& wstr);
index 4738d096ac4ba18abcadfed7a28f2c71bb0a5827..9e115222cab2f3def2ecba578521efd485a78c67 100644 (file)
@@ -35,6 +35,7 @@
 #include "common/dout.h"
 #include "common/errno.h"
 #include "common/version.h"
+#include "common/win32/wstring.h"
 
 #include "global/global_init.h"
 
index 4cfe08cdbe2cae30a4f82fbcd3c4f4cf36739413..4c968e13af5d6c0fe45d5fa7275ba6f46a5f4a11 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "common/ceph_argparse.h"
 #include "common/config.h"
+#include "common/win32/wstring.h"
 
 #include "global/global_init.h"
 
index 4705359c4d032a1db1693541ea602c9b68a6f641..576cceb9916e4a38cbb2ad3411017ce9eb55b8be 100644 (file)
 
 #include "utils.h"
 
-#include <boost/locale/encoding_utf.hpp>
-
-using boost::locale::conv::utf_to_utf;
-
-std::wstring to_wstring(const std::string& str)
-{
-  return utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
-}
-
-std::string to_string(const std::wstring& str)
-{
-  return utf_to_utf<char>(str.c_str(), str.c_str() + str.size());
-}
-
 void to_filetime(time_t t, LPFILETIME pft)
 {
   // Note that LONGLONG is a 64-bit value
index aa52b4d3a3c7beb3d7133c35b112ea48cbfa4be9..f6a6a8e6a5c5fab8cc4c9162db3f658ce33bf1d4 100644 (file)
@@ -12,8 +12,5 @@
 
 #include "include/compat.h"
 
-std::wstring to_wstring(const std::string& str);
-std::string to_string(const std::wstring& str);
-
 void to_filetime(time_t t, LPFILETIME pft);
 void to_unix_time(FILETIME ft, time_t *t);
index a2a772c94030210c0b90077101fce20d886efba2..b6a0e6bbd46d30d4322d923bdadebdc58e47f948 100644 (file)
@@ -20,8 +20,6 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
-#include <boost/locale/encoding_utf.hpp>
-
 #include "wnbd_handler.h"
 #include "rbd_wnbd.h"
 
@@ -38,6 +36,7 @@
 #include "common/errno.h"
 #include "common/version.h"
 #include "common/win32/service.h"
+#include "common/win32/wstring.h"
 #include "common/admin_socket_client.h"
 
 #include "global/global_init.h"
 #define dout_prefix *_dout << "rbd-wnbd: "
 
 using namespace std;
-using boost::locale::conv::utf_to_utf;
-
-std::wstring to_wstring(const std::string& str)
-{
-  return utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
-}
-
-std::string to_string(const std::wstring& str)
-{
-  return utf_to_utf<char>(str.c_str(), str.c_str() + str.size());
-}
 
 bool is_process_running(DWORD pid)
 {