本文整理汇总了C++中JLI_StrLen函数的典型用法代码示例。如果您正苦于以下问题:C++ JLI_StrLen函数的具体用法?C++ JLI_StrLen怎么用?C++ JLI_StrLen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JLI_StrLen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetApplicationHome
/*
* If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
* "/foo" into buf.
*/
jboolean
GetApplicationHome(char *buf, jint bufsize)
{
const char *execname = GetExecName();
if (execname != NULL) {
JLI_Snprintf(buf, bufsize, "%s", execname);
buf[bufsize-1] = '\0';
} else {
return JNI_FALSE;
}
if (JLI_StrRChr(buf, '/') == 0) {
buf[0] = '\0';
return JNI_FALSE;
}
*(JLI_StrRChr(buf, '/')) = '\0'; /* executable file */
if (JLI_StrLen(buf) < 4 || JLI_StrRChr(buf, '/') == 0) {
buf[0] = '\0';
return JNI_FALSE;
}
if (JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0)
*(JLI_StrRChr(buf, '/')) = '\0'; /* sparcv9 or amd64 */
if (JLI_StrLen(buf) < 4 || JLI_StrCmp("/bin", buf + JLI_StrLen(buf) - 4) != 0) {
buf[0] = '\0';
return JNI_FALSE;
}
*(JLI_StrRChr(buf, '/')) = '\0'; /* bin */
return JNI_TRUE;
}
示例2: wildcardConcat
static char *
wildcardConcat(const char *wildcard, const char *basename)
{
int wildlen = (int)JLI_StrLen(wildcard);
int baselen = (int)JLI_StrLen(basename);
char *filename = (char *) JLI_MemAlloc(wildlen + baselen);
/* Replace the trailing '*' with basename */
memcpy(filename, wildcard, wildlen-1);
memcpy(filename+wildlen-1, basename, baselen+1);
return filename;
}
示例3: valid_simple_element
/*
* Return true if this is a valid simple-element (as defined in JSR 56).
*
* The official grammar for a simple-element is:
*
* simple-element ::= version-id | version-id modifier
* modifier ::= '+' | '*'
* version-id ::= string ( separator string )*
* string ::= char ( char )*
* char ::= Any ASCII character except a space, an
* ampersand, a separator or a modifier
* separator ::= '.' | '-' | '_'
*
* However, for efficiency, it is time to abandon the top down parser
* implementation. After deleting the potential trailing modifier, we
* are left with a version-id.
*
* Note that a valid version-id has three simple properties:
*
* 1) Doesn't contain a space, an ampersand or a modifier.
*
* 2) Doesn't begin or end with a separator.
*
* 3) Doesn't contain two adjacent separators.
*
* Any other line noise constitutes a valid version-id.
*/
static int
valid_simple_element(char *simple_element)
{
char *last;
size_t len;
if ((simple_element == NULL) || ((len = JLI_StrLen(simple_element)) == 0))
return (0);
last = simple_element + len - 1;
if (*last == '*' || *last == '+') {
if (--len == 0)
return (0);
*last-- = '\0';
}
if (JLI_StrPBrk(simple_element, " &+*") != NULL) /* Property #1 */
return (0);
if ((JLI_StrChr(".-_", *simple_element) != NULL) || /* Property #2 */
(JLI_StrChr(".-_", *last) != NULL))
return (0);
for (; simple_element != last; simple_element++) /* Property #3 */
if ((JLI_StrChr(".-_", *simple_element) != NULL) &&
(JLI_StrChr(".-_", *(simple_element + 1)) != NULL))
return (0);
return (1);
}
示例4: unquote
/*
* Local helper routine to return a string equivalent to the input string
* s, but with quotes removed so the result is a string as would be found
* in argv[]. The returned string should be freed by a call to JLI_MemFree().
*
* The rules for quoting (and escaped quotes) are:
*
* 1 A double quotation mark preceded by a backslash, \", is interpreted as a
* literal double quotation mark (").
*
* 2 Backslashes are interpreted literally, unless they immediately precede a
* double quotation mark.
*
* 3 If an even number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\), and the double quotation mark (") is interpreted as a
* string delimiter.
*
* 4 If an odd number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\) and the double quotation mark is interpreted as an
* escape sequence by the remaining backslash, causing a literal double
* quotation mark (") to be placed in argv.
*/
static char*
unquote(const char *s) {
const char *p = s; /* Pointer to the tail of the original string */
char *un = (char*)JLI_MemAlloc(JLI_StrLen(s) + 1); /* Ptr to unquoted string */
char *pun = un; /* Pointer to the tail of the unquoted string */
while (*p != '\0') {
if (*p == '"') {
p++;
} else if (*p == '\\') {
const char *q = p + JLI_StrSpn(p,"\\");
if (*q == '"')
do {
*pun++ = '\\';
p += 2;
} while (*p == '\\' && p < q);
else
while (p < q)
*pun++ = *p++;
} else {
*pun++ = *p++;
}
}
*pun = '\0';
return un;
}
示例5: return
/*
* Determine if there is an acceptable JRE in the directory dirname.
* Upon locating the "best" one, return a fully qualified path to
* it. "Best" is defined as the most advanced JRE meeting the
* constraints contained in the manifest_info. If no JRE in this
* directory meets the constraints, return NULL.
*
* Note that we don't check for errors in reading the directory
* (which would be done by checking errno). This is because it
* doesn't matter if we get an error reading the directory, or
* we just don't find anything interesting in the directory. We
* just return NULL in either case.
*
* The historical names of j2sdk and j2re were changed to jdk and
* jre respecively as part of the 1.5 rebranding effort. Since the
* former names are legacy on Linux, they must be recognized for
* all time. Fortunately, this is a minor cost.
*/
static char
*ProcessDir(manifest_info *info, char *dirname)
{
DIR *dirp;
struct dirent *dp;
char *best = NULL;
int offset;
int best_offset = 0;
char *ret_str = NULL;
char buffer[PATH_MAX];
if ((dirp = opendir(dirname)) == NULL)
return (NULL);
do {
if ((dp = readdir(dirp)) != NULL) {
offset = 0;
if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) ||
(JLI_StrNCmp(dp->d_name, "jdk", 3) == 0))
offset = 3;
else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0)
offset = 4;
else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0)
offset = 5;
if (offset > 0) {
if ((JLI_AcceptableRelease(dp->d_name + offset,
info->jre_version)) && CheckSanity(dirname, dp->d_name))
if ((best == NULL) || (JLI_ExactVersionId(
dp->d_name + offset, best + best_offset) > 0)) {
if (best != NULL)
JLI_MemFree(best);
best = JLI_StringDup(dp->d_name);
best_offset = offset;
}
}
}
} while (dp != NULL);
(void) closedir(dirp);
if (best == NULL)
return (NULL);
else {
ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2);
sprintf(ret_str, "%s/%s", dirname, best);
JLI_MemFree(best);
return (ret_str);
}
}
示例6: LoadMSVCRT
static jboolean
LoadMSVCRT()
{
// Only do this once
static int loaded = 0;
char crtpath[MAXPATHLEN];
if (!loaded) {
/*
* The Microsoft C Runtime Library needs to be loaded first. A copy is
* assumed to be present in the "JRE path" directory. If it is not found
* there (or "JRE path" fails to resolve), skip the explicit load and let
* nature take its course, which is likely to be a failure to execute.
* This is clearly completely specific to the exact compiler version
* which isn't very nice, but its hardly the only place.
* No attempt to look for compiler versions in between 2003 and 2010
* as we aren't supporting building with those.
*/
#ifdef _MSC_VER
#if _MSC_VER < 1400
#define CRT_DLL "msvcr71.dll"
#endif
#if _MSC_VER >= 1600
#define CRT_DLL "msvcr100.dll"
#endif
#ifdef CRT_DLL
if (GetJREPath(crtpath, MAXPATHLEN)) {
if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +
JLI_StrLen(CRT_DLL) >= MAXPATHLEN) {
JLI_ReportErrorMessage(JRE_ERROR11);
return JNI_FALSE;
}
(void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */
JLI_TraceLauncher("CRT path is %s\n", crtpath);
if (_access(crtpath, 0) == 0) {
if (LoadLibrary(crtpath) == 0) {
JLI_ReportErrorMessage(DLL_ERROR4, crtpath);
return JNI_FALSE;
}
}
}
#endif /* CRT_DLL */
#endif /* _MSC_VER */
loaded = 1;
}
return JNI_TRUE;
}
示例7: RequiresSetenv
/*
* Test whether the environment variable needs to be set, see flowchart.
*/
static jboolean
RequiresSetenv(int wanted, const char *jvmpath) {
char jpath[PATH_MAX + 1];
char *llp;
char *dmllp = NULL;
char *p; /* a utility pointer */
llp = getenv("LD_LIBRARY_PATH");
#ifdef __solaris__
dmllp = (CURRENT_DATA_MODEL == 32)
? getenv("LD_LIBRARY_PATH_32")
: getenv("LD_LIBRARY_PATH_64");
#endif /* __solaris__ */
/* no environment variable is a good environment variable */
if (llp == NULL && dmllp == NULL) {
return JNI_FALSE;
}
#ifdef __linux
/*
* On linux, if a binary is running as sgid or suid, glibc sets
* LD_LIBRARY_PATH to the empty string for security purposes. (In contrast,
* on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not
* lose its settings; but the dynamic linker does apply more scrutiny to the
* path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec
* loop, here and further downstream. Therefore, if we are running sgid or
* suid, this function's setting of LD_LIBRARY_PATH will be ineffective and
* we should case a return from the calling function. Getting the right
* libraries will be handled by the RPATH. In reality, this check is
* redundant, as the previous check for a non-null LD_LIBRARY_PATH will
* return back to the calling function forthwith, it is left here to safe
* guard against any changes, in the glibc's existing security policy.
*/
if ((getgid() != getegid()) || (getuid() != geteuid())) {
return JNI_FALSE;
}
#endif /* __linux */
/*
* Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by
* previous versions of the JRE, thus it is the only path that matters here.
* So we check to see if the desired JRE is set.
*/
JLI_StrNCpy(jpath, jvmpath, PATH_MAX);
p = JLI_StrRChr(jpath, '/');
*p = '\0';
if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) {
return JNI_FALSE;
}
/* scrutinize all the paths further */
if (llp != NULL && ContainsLibJVM(wanted, llp)) {
return JNI_TRUE;
}
if (dmllp != NULL && ContainsLibJVM(wanted, dmllp)) {
return JNI_TRUE;
}
return JNI_FALSE;
}
示例8: isWildcard
static int
isWildcard(const char *filename)
{
int len = (int)JLI_StrLen(filename);
return (len > 0) &&
(filename[len - 1] == '*') &&
(len == 1 || IS_FILE_SEPARATOR(filename[len - 2])) &&
(! exists(filename));
}
示例9: SetJavaLauncherPlatformProps
void SetJavaLauncherPlatformProps() {
/* Linux only */
#ifdef __linux__
const char *substr = "-Dsun.java.launcher.pid=";
char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1);
sprintf(pid_prop_str, "%s%d", substr, getpid());
AddOption(pid_prop_str, NULL);
#endif
}
示例10: UnsetEnv
/*
* Wrapper for platform dependent unsetenv function.
*/
int
UnsetEnv(char *name)
{
int ret;
char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);
buf = JLI_StrCat(JLI_StrCpy(buf, name), "=");
ret = _putenv(buf);
JLI_MemFree(buf);
return (ret);
}
示例11: GetParamValue
/* Extracts value of a parameter with the specified name
* from command line argument (returns pointer in the argument).
* Returns NULL if the argument does not contains the parameter.
* e.g.:
* GetParamValue("theParam", "theParam=value") returns pointer to "value".
*/
const char * GetParamValue(const char *paramName, const char *arg) {
int nameLen = JLI_StrLen(paramName);
if (JLI_StrNCmp(paramName, arg, nameLen) == 0) {
/* arg[nameLen] is valid (may contain final NULL) */
if (arg[nameLen] == '=') {
return arg + nameLen + 1;
}
}
return NULL;
}
示例12: GetJREPath
/*
* Find path to JRE based on .exe's location or registry settings.
*/
static jboolean
GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
{
char libjava[MAXPATHLEN];
if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
return JNI_TRUE;
}
/* ensure storage for path + /jre + NULL */
if ((JLI_StrLen(path) + 4 + 1) > pathsize) {
JLI_TraceLauncher("Insufficient space to store JRE path\n");
return JNI_FALSE;
}
/* Does the app ship a private JRE in <apphome>/jre directory? */
JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
if (access(libjava, F_OK) == 0) {
JLI_StrCat(path, "/jre");
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
}
}
/* try to find ourselves instead */
Dl_info selfInfo;
dladdr(&GetJREPath, &selfInfo);
char *realPathToSelf = realpath(selfInfo.dli_fname, path);
if (realPathToSelf != path) {
return JNI_FALSE;
}
size_t pathLen = strlen(realPathToSelf);
if (pathLen == 0) {
return JNI_FALSE;
}
const char lastPathComponent[] = "/lib/jli/libjli.dylib";
size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
if (pathLen < sizeOfLastPathComponent) {
return JNI_FALSE;
}
size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
realPathToSelf[indexOfLastPathComponent + 1] = '\0';
return JNI_TRUE;
}
if (!speculative)
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
return JNI_FALSE;
}
示例13: isJarFileName
static int
isJarFileName(const char *filename)
{
int len = (int)JLI_StrLen(filename);
return (len >= 4) &&
(filename[len - 4] == '.') &&
(equal(filename + len - 3, "jar") ||
equal(filename + len - 3, "JAR")) &&
/* Paranoia: Maybe filename is "DIR:foo.jar" */
(JLI_StrChr(filename, PATH_SEPARATOR) == NULL);
}
示例14: SplashProcAddress
void* SplashProcAddress(const char* name) {
char libraryPath[MAXPATHLEN]; /* some extra space for JLI_StrCat'ing SPLASHSCREEN_SO */
if (!GetJREPath(libraryPath, MAXPATHLEN)) {
return NULL;
}
if (JLI_StrLen(libraryPath)+JLI_StrLen(SPLASHSCREEN_SO) >= MAXPATHLEN) {
return NULL;
}
JLI_StrCat(libraryPath, SPLASHSCREEN_SO);
if (!hSplashLib) {
hSplashLib = LoadLibrary(libraryPath);
}
if (hSplashLib) {
return GetProcAddress(hSplashLib, name);
} else {
return NULL;
}
}
示例15: FileList_join
static char *
FileList_join(FileList fl, char sep)
{
int i;
int size;
char *path;
char *p;
for (i = 0, size = 1; i < fl->size; i++)
size += (int)JLI_StrLen(fl->files[i]) + 1;
path = JLI_MemAlloc(size);
for (i = 0, p = path; i < fl->size; i++) {
int len = (int)JLI_StrLen(fl->files[i]);
if (i > 0) *p++ = sep;
memcpy(p, fl->files[i], len);
p += len;
}
*p = '\0';
return path;
}