use of com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer in project graal by oracle.
the class WindowsSystemPropertiesFeature method userHomeValue.
@Override
protected String userHomeValue() {
WinBase.LPHANDLE tokenHandle = StackValue.get(WinBase.LPHANDLE.class);
if (Process.NoTransitions.OpenProcessToken(Process.NoTransitions.GetCurrentProcess(), Process.TOKEN_QUERY(), tokenHandle) == 0) {
// matches openjdk
return "C:\\";
}
int initialLen = WinBase.MAX_PATH + 1;
CIntPointer buffLenPointer = StackValue.get(CIntPointer.class);
buffLenPointer.write(initialLen);
WCharPointer userHome = StackValue.get(initialLen, WCharPointer.class);
// The following call does not support retry on failures if the content does not fit in the
// buffer.
// For now this is the intended implementation as it simplifies it and it will be revised in
// the future
int result = WinBase.GetUserProfileDirectoryW(tokenHandle.read(), userHome, buffLenPointer);
WinBase.CloseHandle(tokenHandle.read());
if (result == 0) {
// matches openjdk
return "C:\\";
}
return toJavaString(userHome, buffLenPointer.read() - 1);
}
Aggregations