Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/misc/MessageUtils.c
38829 views
/*1* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdlib.h>26#include <jni.h>27#include <jlong.h>28#include <stdio.h>29#include <jvm.h>3031#include "sun_misc_MessageUtils.h"3233static void34printToFile(JNIEnv *env, jstring s, FILE *file)35{36char *sConverted;37int length;38int i;39const jchar *sAsArray;4041if (s == NULL) {42s = (*env)->NewStringUTF(env, "null");43if (s == NULL) return;44}4546sAsArray = (*env)->GetStringChars(env, s, NULL);47length = (*env)->GetStringLength(env, s);48sConverted = (char *) malloc(length + 1);49for(i = 0; i < length; i++) {50sConverted[i] = (0x7f & sAsArray[i]);51}52sConverted[length] = '\0';53jio_fprintf(file, "%s", sConverted);54(*env)->ReleaseStringChars(env, s, sAsArray);55free(sConverted);56}5758JNIEXPORT void JNICALL59Java_sun_misc_MessageUtils_toStderr(JNIEnv *env, jclass cls, jstring s)60{61printToFile(env, s, stderr);62}6364JNIEXPORT void JNICALL65Java_sun_misc_MessageUtils_toStdout(JNIEnv *env, jclass cls, jstring s)66{67printToFile(env, s, stdout);68}697071