aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support/string_win32.c
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-04-15 04:53:54 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-04-15 07:39:26 +0200
commitc4b18a50de3ab04b189c9f0e2b56cb08a9f15542 (patch)
tree8344a28cc49a7689d31a3c760bda74e51de327a1 /src/core/lib/support/string_win32.c
parentbcd49994e239e4d15bf4bc2fbed62eb2b914cc28 (diff)
Adding support for msys.
Diffstat (limited to 'src/core/lib/support/string_win32.c')
-rw-r--r--src/core/lib/support/string_win32.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/core/lib/support/string_win32.c b/src/core/lib/support/string_win32.c
index a2f9857356..8382cde15a 100644
--- a/src/core/lib/support/string_win32.c
+++ b/src/core/lib/support/string_win32.c
@@ -31,23 +31,28 @@
*
*/
-/* Posix code for gpr snprintf support. */
+/* Windows code for gpr snprintf support. */
#include <grpc/support/port_platform.h>
-#ifdef GPR_WIN32
+#ifdef GPR_WIN32_STRING
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <wchar.h>
+#include <strsafe.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
int gpr_asprintf(char **strp, const char *format, ...) {
va_list args;
int ret;
+
+ HRESULT success;
size_t strp_buflen;
/* Determine the length. */
@@ -68,9 +73,9 @@ int gpr_asprintf(char **strp, const char *format, ...) {
/* Print to the buffer. */
va_start(args, format);
- ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args);
+ success = StringCbVPrintfA(*strp, strp_buflen, format, args);
va_end(args);
- if ((size_t)ret == strp_buflen - 1) {
+ if (success == S_OK) {
return ret;
}
@@ -80,30 +85,4 @@ int gpr_asprintf(char **strp, const char *format, ...) {
return -1;
}
-#if defined UNICODE || defined _UNICODE
-LPTSTR
-gpr_char_to_tchar(LPCSTR input) {
- LPTSTR ret;
- int needed = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
- if (needed <= 0) return NULL;
- ret = gpr_malloc((unsigned)needed * sizeof(TCHAR));
- MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed);
- return ret;
-}
-
-LPSTR
-gpr_tchar_to_char(LPCTSTR input) {
- LPSTR ret;
- int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
- if (needed <= 0) return NULL;
- ret = gpr_malloc((unsigned)needed);
- WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL);
- return ret;
-}
-#else
-char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); }
-
-char *gpr_char_to_tchar(LPTSTR input) { return gpr_strdup(input); }
-#endif
-
-#endif /* GPR_WIN32 */
+#endif /* GPR_WIN32_STRING */