6153N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3901N/A/* Access APIs for WinXP and above */ 1575N/A * GetFinalPathNameByHandle is available on Windows Vista and newer 3901N/A // GetFinalPathNameByHandle requires Windows Vista or newer 0N/A/* -- Path operations -- */ 1575N/A * Retrieves the fully resolved (final) path for the given path or NULL 1575N/A /* Need Windows Vista or newer to get the final path */ 1575N/A * Allocate a buffer for the resolved path. For a long path we may need 1575N/A * to allocate a larger buffer. 1575N/A /* retry with a buffer of the right size */ 1575N/A * Strip prefix (should be \\?\ or \\?\UNC) 1575N/A /* actual result length (includes terminator) */ 1575N/A /* copy result without prefix into new buffer */ 1575N/A /* unable to get final path */ 1575N/A * Retrieves file information for the specified file. If the file is 1575N/A * symbolic link then the information on fully resolved target is 1575N/A * If the given attributes are the attributes of a reparse point, then 6153N/A * read and return the attributes of the special cases. 6153N/A * Take special cases into account when retrieving the attributes 0N/A /*we estimate the max length of memory needed as 0N/A "currentDir. length + pathname.length" 0N/A/* -- Attribute accessors -- */ 0N/A/* Check whether or not the file name in "path" is a Windows reserved 0N/A device name (CON, PRN, AUX, NUL, COM[1-9], LPT[1-9]) based on the 0N/A returned result from GetFullPathName, which should be in thr form of 0N/A "\\.\[ReservedDeviceName]" if the path represents a reserved device 0N/A Note1: GetFullPathName doesn't think "CLOCK$" (which is no longer 0N/A important anyway) is a device name, so we don't check it here. 0N/A GetFileAttributesEx will catch it later by returning 0 on NT/XP/ 0N/A Note2: Theoretically the implementation could just lookup the table 0N/A below linearly if the first 4 characters of the fullpath returned 0N/A from GetFullPathName are "\\.\". The current implementation should 0N/A achieve the same result. If Microsoft add more names into their 0N/A reserved device name repository in the future, which probably will 0N/A never happen, we will need to revisit the lookup implementation. 0N/Astatic WCHAR* ReservedDEviceNames[] = { 0N/A L"CON", L"PRN", L"AUX", L"NUL", 0N/A L"COM1", L"COM2", L"COM3", L"COM4", L"COM5", L"COM6", L"COM7", L"COM8", L"COM9", 0N/A L"LPT1", L"LPT2", L"LPT3", L"LPT4", L"LPT5", L"LPT6", L"LPT7", L"LPT8", L"LPT9", 357N/A /* Read-only attribute ignored on directories */ 1575N/A /* if reparse point, get final target */ 0N/A /* Device query access */ 0N/A /* No security attributes */ 0N/A /* Open existing or fail */ 0N/A /* Backup semantics for directories */ 0N/A /* No template file */ 1575N/A /* file is a reparse point so read attributes of final target */ 0N/A /* The error is "share violation", which means the file/dir 0N/A must exists. Try _wstati64, we know this at least works 0N/A/* -- File operations -- */ 1575N/A // return false rather than throwing an exception when there is 0N/A /* Returns 0 on success */ 0N/A /* Remove trailing space chars from directory name */ 0N/A /* Append "*", or possibly "\\*", to path */ 0N/A /* No '\\' needed for cases like "\" or "Z:" or "Z:\" */ 0N/A /* Open handle to the first file */ 0N/A // No files found - return an empty array 0N/A /* Allocate an initial String array */ 0N/A if (
rv ==
NULL)
// Couldn't allocate an array 0N/A /* Scan the directory */ 0N/A /* Copy the final results into an appropriately-sized array */ 0N/A /* Exception is pending */ 1575N/A /* if reparse point, get final target */ 0N/A/* -- Filesystem interface -- */