Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/npt/npt.c
38767 views
/*1* Copyright (c) 2004, 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 <stdio.h>26#include <string.h>27#include <stdlib.h>2829#include "jni.h"3031#include "npt.h"3233#include "utf.h"3435static int36version_check(char *version)37{38if ( version==NULL || strcmp(version, NPT_VERSION)!=0 ) {39return 1;40}41return 0;42}4344JNIEXPORT void JNICALL45nptInitialize(NptEnv **pnpt, char *nptVersion, char *options)46{47NptEnv *npt;4849(*pnpt) = NULL;5051if ( version_check(nptVersion) ) {52NPT_ERROR("NPT version doesn't match");53return;54}5556npt = (NptEnv*)calloc(sizeof(NptEnv), 1);57if ( npt == NULL ) {58NPT_ERROR("Cannot allocate calloc space for NptEnv*");59return;60}6162if ( options != NULL ) {63npt->options = strdup(options);64}65npt->utfInitialize = &utfInitialize;66npt->utfTerminate = &utfTerminate;67npt->utf8ToPlatform = &utf8ToPlatform;68npt->utf8FromPlatform = &utf8FromPlatform;69npt->utf8ToUtf16 = &utf8ToUtf16;70npt->utf16ToUtf8m = &utf16ToUtf8m;71npt->utf16ToUtf8s = &utf16ToUtf8s;72npt->utf8sToUtf8mLength = &utf8sToUtf8mLength;73npt->utf8sToUtf8m = &utf8sToUtf8m;74npt->utf8mToUtf8sLength = &utf8mToUtf8sLength;75npt->utf8mToUtf8s = &utf8mToUtf8s;7677(*pnpt) = npt;78}7980JNIEXPORT void JNICALL81nptTerminate(NptEnv* npt, char *options)82{8384/* FIXUP: options? Check memory or something? */85if ( npt->options != NULL ) {86(void)free(npt->options);87}88(void)free(npt);89}909192