Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/windows/native/libjava/jni_util_md.c
41119 views
1
/*
2
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include <stdlib.h>
27
#include <string.h>
28
#include <windows.h>
29
#include <locale.h>
30
31
#include "jni.h"
32
#include "jni_util.h"
33
34
void* getProcessHandle() {
35
return (void*)GetModuleHandle(NULL);
36
}
37
38
/*
39
* Windows symbols can be simple like JNI_OnLoad or __stdcall format
40
* like _JNI_OnLoad@8. We need to handle both.
41
*/
42
void buildJniFunctionName(const char *sym, const char *cname,
43
char *jniEntryName) {
44
if (cname != NULL) {
45
char *p = strrchr(sym, '@');
46
if (p != NULL && p != sym) {
47
// sym == _JNI_OnLoad@8
48
strncpy(jniEntryName, sym, (p - sym));
49
jniEntryName[(p-sym)] = '\0';
50
// jniEntryName == _JNI_OnLoad
51
strcat(jniEntryName, "_");
52
strcat(jniEntryName, cname);
53
strcat(jniEntryName, p);
54
//jniEntryName == _JNI_OnLoad_cname@8
55
} else {
56
strcpy(jniEntryName, sym);
57
strcat(jniEntryName, "_");
58
strcat(jniEntryName, cname);
59
}
60
} else {
61
strcpy(jniEntryName, sym);
62
}
63
return;
64
}
65
66
JNIEXPORT size_t JNICALL
67
getLastErrorString(char *buf, size_t len) {
68
69
DWORD errval;
70
71
if ((errval = GetLastError()) != 0) {
72
// DOS error
73
size_t n = (size_t)FormatMessage(
74
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
75
NULL,
76
errval,
77
0,
78
buf,
79
(DWORD)len,
80
NULL);
81
if (n > 3) {
82
// Drop final '.', CR, LF
83
if (buf[n - 1] == '\n') n--;
84
if (buf[n - 1] == '\r') n--;
85
if (buf[n - 1] == '.') n--;
86
buf[n] = '\0';
87
}
88
return n;
89
}
90
91
// C runtime error that has no corresponding DOS error code
92
if (errno == 0 || len < 1) return 0;
93
return strerror_s(buf, len, errno);
94
}
95
96
JNIEXPORT int JNICALL
97
getErrorString(int err, char *buf, size_t len)
98
{
99
int ret = 0;
100
if (err == 0 || len < 1) return 0;
101
ret = strerror_s(buf, len, err);
102
return ret;
103
}
104
105