annotate src/java.instrument/windows/native/libinstrument/EncodingSupport_md.c @ 55934:79a7fc6c9bc7

8225590: Shenandoah: Refactor ShenandoahClassLoaderDataRoots API Reviewed-by: rkennke
author zgu
date Thu, 20 Jun 2019 18:29:34 -0400
parents 3317bb8137f4
children
rev   line source
duke@2 1 /*
ohair@5506 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
duke@2 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@2 4 *
duke@2 5 * This code is free software; you can redistribute it and/or modify it
duke@2 6 * under the terms of the GNU General Public License version 2 only, as
ohair@5506 7 * published by the Free Software Foundation. Oracle designates this
duke@2 8 * particular file as subject to the "Classpath" exception as provided
ohair@5506 9 * by Oracle in the LICENSE file that accompanied this code.
duke@2 10 *
duke@2 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@2 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@2 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@2 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@2 15 * accompanied this code).
duke@2 16 *
duke@2 17 * You should have received a copy of the GNU General Public License version
duke@2 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@2 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@2 20 *
ohair@5506 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@5506 22 * or visit www.oracle.com if you need additional information or have any
ohair@5506 23 * questions.
duke@2 24 */
duke@2 25 #include <windows.h>
duke@2 26 #include <stdlib.h>
duke@2 27 #include <stdio.h>
duke@2 28
duke@2 29
duke@2 30 /*
duke@2 31 * Convert UTF-8 to a platform string
duke@2 32 */
duke@2 33 int
duke@2 34 convertUft8ToPlatformString(char* utf8_str, int utf8_len, char* platform_str, int platform_len) {
duke@2 35 LANGID langID;
duke@2 36 LCID localeID;
duke@2 37 TCHAR strCodePage[7]; // ANSI code page id
duke@2 38 UINT codePage;
duke@2 39 int wlen, plen;
duke@2 40 WCHAR* wstr;
duke@2 41
duke@2 42 /*
duke@2 43 * Get the code page for this locale
duke@2 44 */
duke@2 45 langID = LANGIDFROMLCID(GetUserDefaultLCID());
duke@2 46 localeID = MAKELCID(langID, SORT_DEFAULT);
duke@2 47 if (GetLocaleInfo(localeID, LOCALE_IDEFAULTANSICODEPAGE,
duke@2 48 strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 ) {
duke@2 49 codePage = atoi(strCodePage);
duke@2 50 } else {
duke@2 51 codePage = GetACP();
duke@2 52 }
duke@2 53
duke@2 54 /*
duke@2 55 * To convert the string to platform encoding we must first convert
duke@2 56 * to unicode, and then convert to the platform encoding
duke@2 57 */
duke@2 58 plen = -1;
duke@2 59 wlen = MultiByteToWideChar(CP_UTF8, 0, utf8_str, utf8_len, NULL, 0);
duke@2 60 if (wlen > 0) {
duke@2 61 wstr = (WCHAR*)malloc(wlen * sizeof(WCHAR));
duke@2 62 if (wstr != NULL) {
duke@2 63 if (MultiByteToWideChar(CP_UTF8,
duke@2 64 0,
duke@2 65 utf8_str,
duke@2 66 utf8_len,
duke@2 67 wstr, wlen) > 0) {
duke@2 68 plen = WideCharToMultiByte(codePage,
duke@2 69 0,
duke@2 70 wstr,
duke@2 71 wlen,
duke@2 72 platform_str,
duke@2 73 platform_len,
duke@2 74 NULL,
duke@2 75 NULL);
duke@2 76 if (plen >= 0) {
duke@2 77 platform_str[plen] = '\0';
duke@2 78 }
duke@2 79 free(wstr);
duke@2 80 }
duke@2 81 }
duke@2 82 }
duke@2 83 return plen;
duke@2 84 }