jdk/src/jdk.jdwp.agent/share/native/libjdwp/utf_util.c
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 39466 838ae1e90961
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     1
/*
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     4
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    10
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    15
 * accompanied this code).
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    16
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    20
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    23
 * questions.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    24
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    25
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    26
#include <stdlib.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    27
#include <ctype.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    28
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    29
#include "jni.h"
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    30
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    31
#include "utf_util.h"
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    32
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    33
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    34
/* Error and assert macros */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    35
#define UTF_ERROR(m) utfError(__FILE__, __LINE__,  m)
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    36
#define UTF_ASSERT(x) ( (x)==0 ? UTF_ERROR("ASSERT ERROR " #x) : (void)0 )
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    37
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    38
// Platform independed part
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    39
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    40
static void utfError(char *file, int line, char *message) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    41
    (void)fprintf(stderr, "UTF ERROR [\"%s\":%d]: %s\n", file, line, message);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    42
    abort();
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    43
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    44
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    45
/* Determine length of this Standard UTF-8 in Modified UTF-8.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    46
 *    Validation is done of the basic UTF encoding rules, returns
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    47
 *    length (no change) when errors are detected in the UTF encoding.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    48
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    49
 *    Note: Accepts Modified UTF-8 also, no verification on the
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    50
 *          correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    51
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    52
int JNICALL utf8sToUtf8mLength(jbyte *string, int length) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    53
  int newLength;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    54
  int i;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    55
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    56
  newLength = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    57
  for ( i = 0 ; i < length ; i++ ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    58
    unsigned byte;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    59
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    60
    byte = (unsigned char)string[i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    61
    if ( (byte & 0x80) == 0 ) { /* 1byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    62
      newLength++;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    63
      if ( byte == 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    64
        newLength++; /* We gain one byte in length on NULL bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    65
      }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    66
    } else if ( (byte & 0xE0) == 0xC0 ) { /* 2byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    67
      /* Check encoding of following bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    68
      if ( (i+1) >= length || (string[i+1] & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    69
        break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    70
      }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    71
      i++; /* Skip next byte */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    72
      newLength += 2;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    73
    } else if ( (byte & 0xF0) == 0xE0 ) { /* 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    74
      /* Check encoding of following bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    75
      if ( (i+2) >= length || (string[i+1] & 0xC0) != 0x80
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    76
        || (string[i+2] & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    77
        break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    78
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    79
        i += 2; /* Skip next two bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    80
        newLength += 3;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    81
    } else if ( (byte & 0xF8) == 0xF0 ) { /* 4byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    82
      /* Check encoding of following bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    83
      if ( (i+3) >= length || (string[i+1] & 0xC0) != 0x80
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    84
        || (string[i+2] & 0xC0) != 0x80
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    85
        || (string[i+3] & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    86
        break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    87
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    88
        i += 3; /* Skip next 3 bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    89
        newLength += 6; /* 4byte encoding turns into 2 3byte ones */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    90
    } else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    91
      break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    92
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    93
  }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    94
  if ( i != length ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    95
    /* Error in finding new length, return old length so no conversion */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    96
    /* FIXUP: ERROR_MESSAGE? */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    97
    return length;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    98
  }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
    99
  return newLength;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   100
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   101
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   102
/* Convert Standard UTF-8 to Modified UTF-8.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   103
 *    Assumes the UTF-8 encoding was validated by utf8mLength() above.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   104
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   105
 *    Note: Accepts Modified UTF-8 also, no verification on the
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   106
 *          correctness of Standard UTF-8 is done. e,g, 0xC080 input is ok.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   107
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   108
void JNICALL utf8sToUtf8m(jbyte *string, int length, jbyte *newString, int newLength) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   109
    int i;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   110
    int j;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   111
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   112
    j = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   113
    for ( i = 0 ; i < length ; i++ ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   114
        unsigned byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   115
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   116
        byte1 = (unsigned char)string[i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   117
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   118
        /* NULL bytes and bytes starting with 11110xxx are special */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   119
        if ( (byte1 & 0x80) == 0 ) { /* 1byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   120
            if ( byte1 == 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   121
                /* Bits out: 11000000 10000000 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   122
                newString[j++] = (jbyte)0xC0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   123
                newString[j++] = (jbyte)0x80;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   124
            } else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   125
                /* Single byte */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   126
                newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   127
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   128
        } else if ( (byte1 & 0xE0) == 0xC0 ) { /* 2byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   129
            newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   130
            newString[j++] = string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   131
        } else if ( (byte1 & 0xF0) == 0xE0 ) { /* 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   132
            newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   133
            newString[j++] = string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   134
            newString[j++] = string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   135
        } else if ( (byte1 & 0xF8) == 0xF0 ) { /* 4byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   136
            /* Beginning of 4byte encoding, turn into 2 3byte encodings */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   137
            unsigned byte2, byte3, byte4, u21;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   138
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   139
            /* Bits in: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   140
            byte2 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   141
            byte3 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   142
            byte4 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   143
            /* Reconstruct full 21bit value */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   144
            u21  = (byte1 & 0x07) << 18;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   145
            u21 += (byte2 & 0x3F) << 12;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   146
            u21 += (byte3 & 0x3F) << 6;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   147
            u21 += (byte4 & 0x3F);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   148
            /* Bits out: 11101101 1010xxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   149
            newString[j++] = (jbyte)0xED;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   150
            newString[j++] = (jbyte)(0xA0 + (((u21 >> 16) - 1) & 0x0F));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   151
            newString[j++] = (jbyte)(0x80 + ((u21 >> 10) & 0x3F));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   152
            /* Bits out: 11101101 1011xxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   153
            newString[j++] = (jbyte)0xED;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   154
            newString[j++] = (jbyte)(0xB0 + ((u21 >>  6) & 0x0F));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   155
            newString[j++] = byte4;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   156
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   157
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   158
    UTF_ASSERT(i==length);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   159
    UTF_ASSERT(j==newLength);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   160
    newString[j] = (jbyte)0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   161
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   162
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   163
/* Given a Modified UTF-8 string, calculate the Standard UTF-8 length.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   164
 *   Basic validation of the UTF encoding rules is done, and length is
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   165
 *   returned (no change) when errors are detected.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   166
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   167
 *   Note: No validation is made that this is indeed Modified UTF-8 coming in.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   168
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   169
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   170
int JNICALL utf8mToUtf8sLength(jbyte *string, int length) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   171
    int newLength;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   172
    int i;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   173
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   174
    newLength = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   175
    for ( i = 0 ; i < length ; i++ ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   176
        unsigned byte1, byte2, byte3, byte4, byte5, byte6;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   177
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   178
        byte1 = (unsigned char)string[i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   179
        if ( (byte1 & 0x80) == 0 ) { /* 1byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   180
            newLength++;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   181
        } else if ( (byte1 & 0xE0) == 0xC0 ) { /* 2byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   182
            /* Check encoding of following bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   183
            if ( (i+1) >= length || (string[i+1] & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   184
                break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   185
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   186
            byte2 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   187
            if ( byte1 != 0xC0 || byte2 != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   188
                newLength += 2; /* Normal 2byte encoding, not 0xC080 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   189
            } else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   190
                newLength++;    /* We will turn 0xC080 into 0 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   191
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   192
        } else if ( (byte1 & 0xF0) == 0xE0 ) { /* 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   193
            /* Check encoding of following bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   194
            if ( (i+2) >= length || (string[i+1] & 0xC0) != 0x80
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   195
                                 || (string[i+2] & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   196
                break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   197
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   198
            byte2 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   199
            byte3 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   200
            newLength += 3;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   201
            /* Possible process a second 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   202
            if ( (i+3) < length && byte1 == 0xED && (byte2 & 0xF0) == 0xA0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   203
                /* See if this is a pair of 3byte encodings */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   204
                byte4 = (unsigned char)string[i+1];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   205
                byte5 = (unsigned char)string[i+2];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   206
                byte6 = (unsigned char)string[i+3];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   207
                if ( byte4 == 0xED && (byte5 & 0xF0) == 0xB0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   208
                    /* Check encoding of 3rd byte */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   209
                    if ( (byte6 & 0xC0) != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   210
                        break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   211
                    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   212
                    newLength++; /* New string will have 4byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   213
                    i += 3;       /* Skip next 3 bytes */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   214
                }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   215
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   216
        } else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   217
            break; /* Error condition */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   218
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   219
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   220
    if ( i != length ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   221
        /* Error in UTF encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   222
        /*  FIXUP: ERROR_MESSAGE()? */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   223
        return length;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   224
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   225
    return newLength;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   226
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   227
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   228
/* Convert a Modified UTF-8 string into a Standard UTF-8 string
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   229
 *   It is assumed that this string has been validated in terms of the
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   230
 *   basic UTF encoding rules by utf8Length() above.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   231
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   232
 *   Note: No validation is made that this is indeed Modified UTF-8 coming in.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   233
 *
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   234
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   235
void JNICALL utf8mToUtf8s(jbyte *string, int length, jbyte *newString, int newLength) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   236
    int i;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   237
    int j;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   238
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   239
    j = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   240
    for ( i = 0 ; i < length ; i++ ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   241
        unsigned byte1, byte2, byte3, byte4, byte5, byte6;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   242
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   243
        byte1 = (unsigned char)string[i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   244
        if ( (byte1 & 0x80) == 0 ) { /* 1byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   245
            /* Single byte */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   246
            newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   247
        } else if ( (byte1 & 0xE0) == 0xC0 ) { /* 2byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   248
            byte2 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   249
            if ( byte1 != 0xC0 || byte2 != 0x80 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   250
                newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   251
                newString[j++] = byte2;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   252
            } else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   253
                newString[j++] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   254
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   255
        } else if ( (byte1 & 0xF0) == 0xE0 ) { /* 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   256
            byte2 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   257
            byte3 = (unsigned char)string[++i];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   258
            if ( i+3 < length && byte1 == 0xED && (byte2 & 0xF0) == 0xA0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   259
                /* See if this is a pair of 3byte encodings */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   260
                byte4 = (unsigned char)string[i+1];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   261
                byte5 = (unsigned char)string[i+2];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   262
                byte6 = (unsigned char)string[i+3];
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   263
                if ( byte4 == 0xED && (byte5 & 0xF0) == 0xB0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   264
                    unsigned u21;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   265
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   266
                    /* Bits in: 11101101 1010xxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   267
                    /* Bits in: 11101101 1011xxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   268
                    i += 3;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   269
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   270
                    /* Reconstruct 21 bit code */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   271
                    u21  = ((byte2 & 0x0F) + 1) << 16;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   272
                    u21 += (byte3 & 0x3F) << 10;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   273
                    u21 += (byte5 & 0x0F) << 6;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   274
                    u21 += (byte6 & 0x3F);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   275
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   276
                    /* Bits out: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   277
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   278
                    /* Convert to 4byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   279
                    newString[j++] = 0xF0 + ((u21 >> 18) & 0x07);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   280
                    newString[j++] = 0x80 + ((u21 >> 12) & 0x3F);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   281
                    newString[j++] = 0x80 + ((u21 >>  6) & 0x3F);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   282
                    newString[j++] = 0x80 + (u21 & 0x3F);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   283
                    continue;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   284
                }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   285
            }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   286
            /* Normal 3byte encoding */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   287
            newString[j++] = byte1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   288
            newString[j++] = byte2;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   289
            newString[j++] = byte3;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   290
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   291
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   292
    UTF_ASSERT(i==length);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   293
    UTF_ASSERT(j==newLength);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   294
    newString[j] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   295
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   296
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   297
#ifdef _WIN32
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   298
// Microsoft Windows specific part
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   299
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   300
#include <windows.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   301
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   302
static UINT getCodepage() {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   303
    LANGID langID;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   304
    LCID localeID;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   305
    TCHAR strCodePage[7];       // ANSI code page id
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   306
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   307
    static UINT intCodePage = -1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   308
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   309
    if (intCodePage == -1) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   310
        // Firts call, get codepage from the os
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   311
        langID = LANGIDFROMLCID(GetUserDefaultLCID());
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   312
        localeID = MAKELCID(langID, SORT_DEFAULT);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   313
        if (GetLocaleInfo(localeID, LOCALE_IDEFAULTANSICODEPAGE,
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   314
                         strCodePage, sizeof(strCodePage)/sizeof(TCHAR)) > 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   315
            intCodePage = atoi(strCodePage);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   316
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   317
        else {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   318
            intCodePage = GetACP();
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   319
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   320
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   321
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   322
    return intCodePage;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   323
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   324
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   325
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   326
 * Get wide string  (assumes len>0)
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   327
 */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   328
static WCHAR* getWideString(UINT codePage, char* str, int len, int *pwlen) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   329
    int wlen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   330
    WCHAR* wstr;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   331
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   332
    /* Convert the string to WIDE string */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   333
    wlen = MultiByteToWideChar(codePage, 0, str, len, NULL, 0);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   334
    *pwlen = wlen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   335
    if (wlen <= 0) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   336
        UTF_ERROR(("Can't get WIDE string length"));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   337
        return NULL;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   338
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   339
    wstr = (WCHAR*)malloc(wlen * sizeof(WCHAR));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   340
    if (wstr == NULL) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   341
        UTF_ERROR(("Can't malloc() any space"));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   342
        return NULL;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   343
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   344
    if (MultiByteToWideChar(codePage, 0, str, len, wstr, wlen) == 0) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   345
        UTF_ERROR(("Can't get WIDE string"));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   346
        return NULL;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   347
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   348
    return wstr;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   349
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   350
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   351
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   352
 * Convert UTF-8 to a platform string
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   353
 * NOTE: outputBufSize includes the space for the trailing 0.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   354
 */
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   355
int JNICALL utf8ToPlatform(jbyte *utf8, int len, char* output, int outputBufSize) {
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   356
    int wlen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   357
    int plen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   358
    WCHAR* wstr;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   359
    UINT codepage;
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   360
    int outputMaxLen;
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   361
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   362
    UTF_ASSERT(utf8);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   363
    UTF_ASSERT(output);
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   364
    UTF_ASSERT(len >= 0);
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   365
    UTF_ASSERT(outputBufSize > len);
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   366
    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   367
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   368
    /* Zero length is ok, but we don't need to do much */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   369
    if ( len == 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   370
        output[0] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   371
        return 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   372
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   373
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   374
    /* Get WIDE string version (assumes len>0) */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   375
    wstr = getWideString(CP_UTF8, (char*)utf8, len, &wlen);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   376
    if ( wstr == NULL ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   377
        // Can't allocate WIDE string
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   378
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   379
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   380
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   381
    /* Convert WIDE string to MultiByte string */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   382
    codepage = getCodepage();
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   383
    plen = WideCharToMultiByte(codepage, 0, wstr, wlen,
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   384
                               output, outputMaxLen, NULL, NULL);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   385
    free(wstr);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   386
    if (plen <= 0) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   387
        // Can't convert WIDE string to multi-byte
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   388
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   389
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   390
    output[plen] = '\0';
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   391
    return plen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   392
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   393
just_copy_bytes:
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   394
    (void)memcpy(output, utf8, len);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   395
    output[len] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   396
    return len;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   397
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   398
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   399
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   400
 * Convert Platform Encoding to UTF-8.
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   401
 * NOTE: outputBufSize includes the space for the trailing 0.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   402
 */
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   403
int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputBufSize) {
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   404
    int wlen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   405
    int plen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   406
    WCHAR* wstr;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   407
    UINT codepage;
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   408
    int outputMaxLen;
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   409
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   410
    UTF_ASSERT(str);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   411
    UTF_ASSERT(output);
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   412
    UTF_ASSERT(len >= 0);
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   413
    UTF_ASSERT(outputBufSize > len);
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   414
    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   415
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   416
    /* Zero length is ok, but we don't need to do much */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   417
    if ( len == 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   418
        output[0] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   419
        return 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   420
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   421
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   422
    /* Get WIDE string version (assumes len>0) */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   423
    codepage = getCodepage();
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   424
    wstr = getWideString(codepage, str, len, &wlen);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   425
    if ( wstr == NULL ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   426
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   427
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   428
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   429
    /* Convert WIDE string to UTF-8 string */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   430
    plen = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen,
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   431
                               (char*)output, outputMaxLen, NULL, NULL);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   432
    free(wstr);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   433
    if (plen <= 0) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   434
        UTF_ERROR(("Can't convert WIDE string to multi-byte"));
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   435
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   436
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   437
    output[plen] = '\0';
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   438
    return plen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   439
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   440
just_copy_bytes:
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   441
    (void)memcpy(output, str, len);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   442
    output[len] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   443
    return len;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   444
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   445
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   446
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   447
#else
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   448
// *NIX specific part
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   449
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   450
#include <iconv.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   451
#include <locale.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   452
#include <langinfo.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   453
#include <string.h>
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   454
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   455
typedef enum {TO_UTF8, FROM_UTF8} conv_direction;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   456
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   457
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   458
 * Do iconv() conversion.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   459
 *    Returns length or -1 if output overflows.
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   460
 * NOTE: outputBufSize includes the space for the trailing 0.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   461
 */
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   462
static int iconvConvert(conv_direction drn, char *bytes, size_t len, char *output, size_t outputBufSize) {
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   463
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   464
    static char *codeset = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   465
    iconv_t func;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   466
    size_t bytes_converted;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   467
    size_t inLeft, outLeft;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   468
    char *inbuf, *outbuf;
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   469
    int outputMaxLen;
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   470
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   471
    UTF_ASSERT(bytes);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   472
    UTF_ASSERT(output);
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   473
    UTF_ASSERT(outputBufSize > len);
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   474
    outputMaxLen = outputBufSize - 1; // leave space for trailing 0
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   475
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   476
    /* Zero length is ok, but we don't need to do much */
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   477
    if ( len == 0 ) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   478
        output[0] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   479
        return 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   480
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   481
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   482
    if (codeset == NULL && codeset != (char *) -1) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   483
        // locale is not initialized, do it now
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   484
        if (setlocale(LC_ALL, "") != NULL) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   485
            // nl_langinfo returns ANSI_X3.4-1968 by default
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   486
            codeset = (char*)nl_langinfo(CODESET);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   487
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   488
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   489
        if (codeset == NULL) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   490
           // Not able to intialize process locale from platform one.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   491
           codeset = (char *) -1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   492
        }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   493
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   494
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   495
    if (codeset == (char *) -1) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   496
      // There was an error during initialization, so just bail out
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   497
      goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   498
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   499
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   500
    func = (drn == TO_UTF8) ? iconv_open(codeset, "UTF-8") : iconv_open("UTF-8", codeset);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   501
    if (func == (iconv_t) -1) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   502
        // Requested charset combination is not supported, conversion couldn't be done.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   503
        // make sure we will not try it again
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   504
        codeset = (char *) -1;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   505
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   506
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   507
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   508
    // perform conversion
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   509
    inbuf = bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   510
    outbuf = output;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   511
    inLeft = len;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   512
    outLeft = outputMaxLen;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   513
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   514
    bytes_converted = iconv(func, (void*)&inbuf, &inLeft, &outbuf, &outLeft);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   515
    if (bytes_converted == (size_t) -1 || bytes_converted == 0 || inLeft != 0) {
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   516
        // Input string is invalid, not able to convert entire string
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   517
        // or some other iconv error happens.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   518
        iconv_close(func);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   519
        goto just_copy_bytes;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   520
    }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   521
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   522
    iconv_close(func);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   523
    // Overwrite bytes_converted with value of actually stored bytes
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   524
    bytes_converted = outputMaxLen-outLeft;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   525
    output[bytes_converted] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   526
    return bytes_converted;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   527
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   528
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   529
just_copy_bytes:
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   530
    (void)memcpy(output, bytes, len);
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   531
    output[len] = 0;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   532
    return len;
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   533
 }
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   534
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   535
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   536
 * Convert UTF-8 to Platform Encoding.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   537
 *    Returns length or -1 if output overflows.
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   538
 * NOTE: outputBufSize includes the space for the trailing 0.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   539
 */
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   540
int JNICALL utf8ToPlatform(jbyte *utf8, int len, char *output, int outputBufSize) {
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   541
    return iconvConvert(FROM_UTF8, (char*)utf8, len, output, outputBufSize);
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   542
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   543
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   544
/*
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   545
 * Convert Platform Encoding to UTF-8.
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   546
 *    Returns length or -1 if output overflows.
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   547
 * NOTE: outputBufSize includes the space for the trailing 0.
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   548
 */
39466
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   549
int JNICALL utf8FromPlatform(char *str, int len, jbyte *output, int outputBufSize) {
838ae1e90961 8154820: JDWP: -agentlib:jdwp=help assertion error
iklam
parents: 25859
diff changeset
   550
    return iconvConvert(TO_UTF8, str, len, (char*) output, outputBufSize);
24967
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   551
}
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   552
582420f5ab6c 8041498: Remove npt library
dsamersoff
parents:
diff changeset
   553
#endif