FileSystemSupport_md.c revision 0
0N/A * Copyright 2004 Sun Microsystems, Inc. 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 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun 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. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * Windows implementation of file system support functions 0N/A return (c ==
'\\') || (c ==
'/');
0N/A return ((c >=
'a') && (c <=
'z')) || ((c >=
'A') && (c <=
'Z'));
0N/A/* filename are case insensitive on windows */ 0N/A/* A normal Win32 pathname contains no duplicate slashes, except possibly 0N/A * for a UNC prefix, and does not end with a slash. It may be the empty 0N/A * string. Normalized Win32 pathnames have the convenient property that 0N/A * the length of the prefix almost uniquely identifies the type of the path 0N/A * and whether it is absolute or relative: 0N/A * 0 relative to both drive and directory 0N/A * 1 drive-relative (begins with '\\') 0N/A * 2 absolute UNC (if first char is '\\'), 0N/A * else directory-relative (has form "z:foo") 0N/A * 3 absolute local pathname (begins with "z:\\") 0N/A /* Remove leading slashes if followed by drive specifier. 0N/A This hack is necessary to support file URLs containing drive 0N/A specifiers (e.g., "file://c:/path"). As a side effect, 0N/A "/c:/path" can be used as an alternative to "c:/path". */ 0N/A /* UNC pathname: Retain first slash; leave src pointed at 0N/A second slash so that further slashes will be collapsed 0N/A into the second slash. The result will be a pathname 0N/A beginning with "\\\\" followed (most likely) by a host 0N/A * Normalize the given pathname, whose length is len, starting at the given 0N/A * offset; everything before this offset is already normal. 0N/A if (
off <
3)
off = 0;
/* Avoid fencepost cases with UNC pathnames */ 0N/A /* Complete normalization, including prefix */ 0N/A /* Partial normalization */ 0N/A /* Remove redundant slashes from the remainder of the path, forcing all 0N/A slashes into the preferred slash */ 0N/A /* Check for trailing separator */ 0N/A /* "\\\\" is not collapsed to "\\" because "\\\\" marks 0N/A the beginning of a UNC pathname. Even though it is 0N/A not, by itself, a valid UNC pathname, we leave it as 0N/A is in order to be consistent with the win32 APIs, 0N/A which treat this case as an invalid UNC pathname 0N/A rather than as an alias for the root directory of 0N/A the current drive. */ 0N/A /* Path does not denote a root directory, so do not append 0N/A * Check that the given pathname is normal. If not, invoke the real 0N/A * normalizer on the part of the pathname that requires normalization. 0N/A * This way we iterate through the whole pathname string only once. 0N/A for (i = 0; i < n; i++) {
0N/A if ((c ==
':') && (i >
1))
0N/A /* Drop prefix when child is a UNC pathname */ 0N/A /* Drop prefix when child is drive-relative */ 0N/A if (n == 0)
return 0;
0N/A if (
c1 ==
slash)
return 2;
/* Absolute UNC pathname "\\\\foo" */ 0N/A return 1;
/* Drive-relative "\\foo" */ 0N/A return 3;
/* Absolute local pathname "z:\\foo" */ 0N/A return 2;
/* Directory-relative "z:foo" */ 0N/A return 0;
/* Completely relative */ 0N/A // "/c:/foo" --> "c:/foo" 0N/A // "c:/foo/" --> "c:/foo", but "c:/" --> "c:/" 0N/A // "/foo/" --> "/foo"