2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2014-01-13 16:32:18 -08:00
|
|
|
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
2010-05-25 15:58:33 -07:00
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
2007-12-01 00:00:00 +00:00
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
2010-05-25 15:58:33 -07:00
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:58:33 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <jni.h>
|
2014-01-14 15:15:45 +00:00
|
|
|
#include <jni_util.h>
|
2007-12-01 00:00:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <jvm.h>
|
|
|
|
|
2016-01-06 17:40:48 +00:00
|
|
|
#include "java_lang_StringCoding.h"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
printToFile(JNIEnv *env, jstring s, FILE *file)
|
|
|
|
{
|
|
|
|
char *sConverted;
|
2014-01-13 16:32:18 -08:00
|
|
|
int length = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
int i;
|
|
|
|
const jchar *sAsArray;
|
|
|
|
|
2009-06-25 17:01:56 -04:00
|
|
|
if (s == NULL) {
|
2016-01-06 17:40:48 +00:00
|
|
|
JNU_ThrowNullPointerException(env, NULL);
|
|
|
|
return;
|
2009-06-25 17:01:56 -04:00
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
sAsArray = (*env)->GetStringChars(env, s, NULL);
|
2014-01-13 16:32:18 -08:00
|
|
|
if (!sAsArray)
|
|
|
|
return;
|
2007-12-01 00:00:00 +00:00
|
|
|
length = (*env)->GetStringLength(env, s);
|
2014-01-13 16:32:18 -08:00
|
|
|
if (length == 0) {
|
|
|
|
(*env)->ReleaseStringChars(env, s, sAsArray);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
sConverted = (char *) malloc(length + 1);
|
2014-01-13 16:32:18 -08:00
|
|
|
if (!sConverted) {
|
|
|
|
(*env)->ReleaseStringChars(env, s, sAsArray);
|
|
|
|
JNU_ThrowOutOfMemoryError(env, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
for(i = 0; i < length; i++) {
|
|
|
|
sConverted[i] = (0x7f & sAsArray[i]);
|
|
|
|
}
|
|
|
|
sConverted[length] = '\0';
|
|
|
|
jio_fprintf(file, "%s", sConverted);
|
|
|
|
(*env)->ReleaseStringChars(env, s, sAsArray);
|
|
|
|
free(sConverted);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2016-01-06 17:40:48 +00:00
|
|
|
Java_java_lang_StringCoding_err(JNIEnv *env, jclass cls, jstring s)
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
|
|
|
printToFile(env, s, stderr);
|
|
|
|
}
|