1 /*
2 * Copyright (c) 2001, 2013, 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
216 BOOL res = getFileInformation(path, &finfo);
217 a = (res) ? finfo.dwFileAttributes : INVALID_FILE_ATTRIBUTES;
218 }
219 return a;
220 }
221
222 /**
223 * Take special cases into account when retrieving the attributes
224 * of path
225 */
226 DWORD getFinalAttributes(WCHAR *path)
227 {
228 DWORD attr = INVALID_FILE_ATTRIBUTES;
229
230 WIN32_FILE_ATTRIBUTE_DATA wfad;
231 WIN32_FIND_DATAW wfd;
232 HANDLE h;
233
234 if (GetFileAttributesExW(path, GetFileExInfoStandard, &wfad)) {
235 attr = getFinalAttributesIfReparsePoint(path, wfad.dwFileAttributes);
236 } else if (GetLastError() == ERROR_SHARING_VIOLATION &&
237 (h = FindFirstFileW(path, &wfd)) != INVALID_HANDLE_VALUE) {
238 attr = getFinalAttributesIfReparsePoint(path, wfd.dwFileAttributes);
239 FindClose(h);
240 }
241 return attr;
242 }
243
244 JNIEXPORT jstring JNICALL
245 Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
246 jstring pathname)
247 {
248 jstring rv = NULL;
249 WCHAR canonicalPath[MAX_PATH_LENGTH];
250
251 WITH_UNICODE_STRING(env, pathname, path) {
252 /* we estimate the max length of memory needed as
253 "currentDir. length + pathname.length"
254 */
255 int len = (int)wcslen(path);
256 len += currentDirLength(path, len);
257 if (len > MAX_PATH_LENGTH - 1) {
258 WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR));
259 if (cp != NULL) {
|
1 /*
2 * Copyright (c) 2001, 2015, 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
216 BOOL res = getFileInformation(path, &finfo);
217 a = (res) ? finfo.dwFileAttributes : INVALID_FILE_ATTRIBUTES;
218 }
219 return a;
220 }
221
222 /**
223 * Take special cases into account when retrieving the attributes
224 * of path
225 */
226 DWORD getFinalAttributes(WCHAR *path)
227 {
228 DWORD attr = INVALID_FILE_ATTRIBUTES;
229
230 WIN32_FILE_ATTRIBUTE_DATA wfad;
231 WIN32_FIND_DATAW wfd;
232 HANDLE h;
233
234 if (GetFileAttributesExW(path, GetFileExInfoStandard, &wfad)) {
235 attr = getFinalAttributesIfReparsePoint(path, wfad.dwFileAttributes);
236 } else {
237 DWORD lerr = GetLastError();
238 if ((lerr == ERROR_SHARING_VIOLATION || lerr == ERROR_ACCESS_DENIED) &&
239 (h = FindFirstFileW(path, &wfd)) != INVALID_HANDLE_VALUE) {
240 attr = getFinalAttributesIfReparsePoint(path, wfd.dwFileAttributes);
241 FindClose(h);
242 }
243 }
244 return attr;
245 }
246
247 JNIEXPORT jstring JNICALL
248 Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
249 jstring pathname)
250 {
251 jstring rv = NULL;
252 WCHAR canonicalPath[MAX_PATH_LENGTH];
253
254 WITH_UNICODE_STRING(env, pathname, path) {
255 /* we estimate the max length of memory needed as
256 "currentDir. length + pathname.length"
257 */
258 int len = (int)wcslen(path);
259 len += currentDirLength(path, len);
260 if (len > MAX_PATH_LENGTH - 1) {
261 WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR));
262 if (cp != NULL) {
|