Path: blob/master/src/java.base/share/native/libjli/jli_util.h
67707 views
/*1* Copyright (c) 2005, 2020, 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#ifndef _JLI_UTIL_H26#define _JLI_UTIL_H2728#include <stdlib.h>29#include <string.h>30#include <stdio.h>3132#ifndef NO_JNI33#include <jni.h>34#else35#define jboolean int36#define JNI_TRUE 137#define JNI_FALSE 038#endif3940#define JLDEBUG_ENV_ENTRY "_JAVA_LAUNCHER_DEBUG"4142JNIEXPORT void * JNICALL43JLI_MemAlloc(size_t size);4445void *JLI_MemRealloc(void *ptr, size_t size);4647JNIEXPORT char * JNICALL48JLI_StringDup(const char *s1);4950JNIEXPORT void JNICALL51JLI_MemFree(void *ptr);5253int JLI_StrCCmp(const char *s1, const char *s2);54jboolean JLI_HasSuffix(const char *s1, const char *s2);5556typedef struct {57char *arg;58jboolean has_wildcard;59} StdArg;6061JNIEXPORT StdArg * JNICALL62JLI_GetStdArgs();6364JNIEXPORT int JNICALL65JLI_GetStdArgc();6667JNIEXPORT int JNICALL68JLI_GetAppArgIndex();6970#define JLI_StrLen(p1) strlen((p1))71#define JLI_StrChr(p1, p2) strchr((p1), (p2))72#define JLI_StrRChr(p1, p2) strrchr((p1), (p2))73#define JLI_StrCmp(p1, p2) strcmp((p1), (p2))74#define JLI_StrNCmp(p1, p2, p3) strncmp((p1), (p2), (p3))75#define JLI_StrCat(p1, p2) strcat((p1), (p2))76#define JLI_StrCpy(p1, p2) strcpy((p1), (p2))77#define JLI_StrNCpy(p1, p2, p3) strncpy((p1), (p2), (p3))78#define JLI_StrStr(p1, p2) strstr((p1), (p2))79#define JLI_StrSpn(p1, p2) strspn((p1), (p2))80#define JLI_StrCSpn(p1, p2) strcspn((p1), (p2))81#define JLI_StrPBrk(p1, p2) strpbrk((p1), (p2))8283/* On Windows lseek() is in io.h rather than the location dictated by POSIX. */84#ifdef _WIN3285#include <windows.h>86#include <io.h>87#include <process.h>88#define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2))89#define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3))90int JLI_Snprintf(char *buffer, size_t size, const char *format, ...);91int JLI_Open(const char* name, int flags);92JNIEXPORT void JNICALL93JLI_CmdToArgs(char *cmdline);94#define JLI_Lseek _lseeki6495#else /* NIXES */96#include <unistd.h>97#include <strings.h>98#define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2))99#define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3))100#define JLI_Snprintf snprintf101#define JLI_Open open102#ifdef __linux__103#define _LARGFILE64_SOURCE104#define JLI_Lseek lseek64105#endif106#ifdef MACOSX107#define JLI_Lseek lseek108#endif109#ifdef _AIX110#define JLI_Lseek lseek111#endif112#endif /* _WIN32 */113114/*115* Make launcher spit debug output.116*/117void JLI_TraceLauncher(const char* fmt, ...);118119JNIEXPORT void JNICALL120JLI_SetTraceLauncher();121122jboolean JLI_IsTraceLauncher();123124/*125* JLI_List - a dynamic list of char*126*/127struct JLI_List_128{129char **elements;130size_t size;131size_t capacity;132};133typedef struct JLI_List_ *JLI_List;134135JNIEXPORT JLI_List JNICALL136JLI_List_new(size_t capacity);137138void JLI_List_free(JLI_List l);139void JLI_List_ensureCapacity(JLI_List l, size_t capacity);140141/* e must be JLI_MemFree-able */142JNIEXPORT void JNICALL143JLI_List_add(JLI_List l, char *e);144145/* a copy is made out of beg */146void JLI_List_addSubstring(JLI_List l, const char *beg, size_t len);147char *JLI_List_combine(JLI_List sl);148char *JLI_List_join(JLI_List l, char sep);149JLI_List JLI_List_split(const char *str, char sep);150151JNIEXPORT void JNICALL152JLI_InitArgProcessing(jboolean hasJavaArgs, jboolean disableArgFile);153154JNIEXPORT JLI_List JNICALL155JLI_PreprocessArg(const char *arg, jboolean expandSourceOpt);156157JNIEXPORT jboolean JNICALL158JLI_AddArgsFromEnvVar(JLI_List args, const char *var_name);159160#endif /* _JLI_UTIL_H */161162163