Author: mturk Date: Sun Apr 19 07:41:43 2009 New Revision: 766434 URL: http://svn.apache.org/viewvc?rev=766434&view=rev Log: Add win32/File skeleton
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (with props) Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=766434&r1=766433&r2=766434&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Sun Apr 19 07:41:43 2009 @@ -16,9 +16,10 @@ package org.apache.commons.runtime.io; +import java.io.IOException; + /** File extends the {...@code java.io.File} object. */ - public class File extends java.io.File { private static native int ftype0(String pathname); @@ -32,7 +33,9 @@ } public FileType getFileType() + throws IOException { return FileType.valueOf(ftype0(getPath())); } + } Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=766434&r1=766433&r2=766434&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sun Apr 19 07:41:43 2009 @@ -70,6 +70,7 @@ $(SRCDIR)/shared/version.$(OBJ) WINDOWS_OBJS= \ + $(SRCDIR)/os/win32/file.$(OBJ) \ $(SRCDIR)/os/win32/main.$(OBJ) \ $(SRCDIR)/os/win32/os.$(OBJ) \ $(SRCDIR)/os/win32/syslog.$(OBJ) \ Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=766434&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Sun Apr 19 07:41:43 2009 @@ -0,0 +1,96 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_error.h" +#include "acr_file.h" + +/** + * Win32 file functions + * + */ + +ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const wchar_t *fname) +{ + WIN32_FILE_ATTRIBUTE_DATA info; + + memset(&info, 0, sizeof(WIN32_FILE_ATTRIBUTE_DATA)); + + if (GetFileAttributesExW(fname, GetFileExInfoStandard, &info)) { + int type = ACR_FT_REG; + if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) + type = ACR_FT_LNK; + else if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + type = ACR_FT_DIR; + else if (info.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) + type = ACR_FT_CHR; + else if (!info.ftLastWriteTime.dwLowDateTime && + !info.ftLastWriteTime.dwHighDateTime && + !(info.nFileSizeLow | info.nFileSizeHigh)) { + /* XXX: Use malloc and 32K instead APR's 8K limit? + */ + wchar_t tmpname[ACR_HBUFF_SIZ]; + wchar_t *tmpoff = NULL; + if (GetFullPathNameW(fname, ACR_HBUFF_LEN, + tmpname, &tmpoff)) { + if (!wcsncmp(tmpname, L"\\\\.\\", 4)) { + if (tmpoff == tmpname + 4) { + type = ACR_FT_CHR; + } + /* For WHATEVER reason, CHR devices such as \\.\con + * or \\.\lpt1 *may*not* update tmpoff; in fact the + * resulting tmpoff is set to NULL. Guard against + * either case. + */ + else if (!tmpoff) { + tmpoff = tmpname + 4; + while (*tmpoff) { + if (*tmpoff == L'\\' || *tmpoff == L'/') { + break; + } + ++tmpoff; + } + if (!*tmpoff) { + type = ACR_FT_CHR; + } + } + } + } + else + type = ACR_FT_UNKFILE; + } + return type; + } + else if (_E) { + /* Throw exception */ + ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ACR_GET_OS_ERROR()); + } + return -1; +} + +ACR_JNI_EXPORT_DECLARE(int, io_File, ftype0)(ACR_JNISTDARGS, jstring pathname) +{ + int type; + WSTR_DECLARE(pathname); + + UNREFERENCED_O; + WPTR_DECLARE(pathname); + type = ACR_FileTypeGet(_E, J2W(pathname)); + WSTR_RELEASE(pathname); + + return type; +} Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=766434&r1=766433&r2=766434&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Sun Apr 19 07:41:43 2009 @@ -536,7 +536,10 @@ throws Throwable { File f = test029(0); - assertEquals("Pathname", "/tmp/foo", f.getPath()); + if (OS.IS_UNIX) + assertEquals("Pathname", "/tmp/foo", f.getPath()); + else + assertEquals("Pathname", "\\tmp\\foo", f.getPath()); assertEquals("Name", "foo", f.getName()); }