Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/bin/jli_util.c
38767 views
/*1* Copyright (c) 2005, 2012, 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 <jni.h>2829#include "jli_util.h"3031/*32* Returns a pointer to a block of at least 'size' bytes of memory.33* Prints error message and exits if the memory could not be allocated.34*/35void *36JLI_MemAlloc(size_t size)37{38void *p = malloc(size);39if (p == 0) {40perror("malloc");41exit(1);42}43return p;44}4546/*47* Equivalent to realloc(size).48* Prints error message and exits if the memory could not be reallocated.49*/50void *51JLI_MemRealloc(void *ptr, size_t size)52{53void *p = realloc(ptr, size);54if (p == 0) {55perror("realloc");56exit(1);57}58return p;59}6061/*62* Wrapper over strdup(3C) which prints an error message and exits if memory63* could not be allocated.64*/65char *66JLI_StringDup(const char *s1)67{68char *s = strdup(s1);69if (s == NULL) {70perror("strdup");71exit(1);72}73return s;74}7576/*77* Very equivalent to free(ptr).78* Here to maintain pairing with the above routines.79*/80void81JLI_MemFree(void *ptr)82{83free(ptr);84}8586/*87* debug helpers we use88*/89static jboolean _launcher_debug = JNI_FALSE;9091void92JLI_TraceLauncher(const char* fmt, ...)93{94va_list vl;95if (_launcher_debug != JNI_TRUE) return;96va_start(vl, fmt);97vprintf(fmt,vl);98va_end(vl);99}100101void102JLI_SetTraceLauncher()103{104if (getenv(JLDEBUG_ENV_ENTRY) != 0) {105_launcher_debug = JNI_TRUE;106JLI_TraceLauncher("----%s----\n", JLDEBUG_ENV_ENTRY);107}108}109110jboolean111JLI_IsTraceLauncher()112{113return _launcher_debug;114}115116int117JLI_StrCCmp(const char *s1, const char* s2)118{119return JLI_StrNCmp(s1, s2, JLI_StrLen(s2));120}121122123