Author: mturk Date: Sat Oct 3 10:51:35 2009 New Revision: 821291 URL: http://svn.apache.org/viewvc?rev=821291&view=rev Log: Add few more file methods
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=821291&r1=821290&r2=821291&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Sat Oct 3 10:51:35 2009 @@ -248,7 +248,7 @@ /** Create temporary unique file. * @param env JNI environment to use. If NULL no exception will be thrown * if stat fails. - * @pamap tmpath Path where to create the file. + * @param tmpath Path where to create the file. * @param prefix File prefix. * @param preserve Non zero to survive file close. * @return File descriptor or -1 o failure. @@ -260,7 +260,7 @@ /** Create temporary unique directory. * @param env JNI environment to use. If NULL no exception will be thrown * if stat fails. - * @pamap tmpath Path where to create the directory. + * @param tmpath Path where to create the directory. * @param prefix Directory prefix. * @return Newly created unique directory path. Use ACR_Free when no longer * needed. Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=821291&r1=821290&r2=821291&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Sat Oct 3 10:51:35 2009 @@ -443,3 +443,31 @@ return attr; } +ACR_IO_EXPORT_DECLARE(jstring, File, tmpdir0)(ACR_JNISTDARGS, jstring path, + jstring prefix) +{ + int rc = 0; + char *tmpd = NULL; + + UNREFERENCED_O; + + WITH_ZCSTR(path) { + WITH_ZCSTR(prefix) { + /* Provide INVALID_HANDLE_VALUE for JNIEnv + * so that in case of failure, exception doesn't get thrown + */ + tmpd = ACR_TempDirMake(INVALID_HANDLE_VALUE, J2S(path), J2S(prefix)); + if (!tmpd) + rc = ACR_GET_OS_ERROR(); + } END_WITH_CSTR(prefix); + } END_WITH_CSTR(path); + if (rc) { + ACR_THROW_IO_IF_ERR(rc); + return NULL; + } + else { + jstring rv = ACR_NewJavaStringA(_E, tmpd); + x_free(tmpd); + return rv; + } +} Modified: 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=821291&r1=821290&r2=821291&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Sat Oct 3 10:51:35 2009 @@ -875,3 +875,31 @@ return attr; } +ACR_IO_EXPORT_DECLARE(jstring, File, tmpdir0)(ACR_JNISTDARGS, jstring path, + jstring prefix) +{ + int rc = 0; + wchar_t *tmpd = NULL; + + UNREFERENCED_O; + + WITH_ZWSTR(path) { + WITH_ZWSTR(prefix) { + /* Provide INVALID_HANDLE_VALUE for JNIEnv + * so that in case of failure, exception doesn't get thrown + */ + tmpd = ACR_TempDirMake(INVALID_HANDLE_VALUE, J2W(path), J2W(prefix)); + if (!tmpd) + rc = ACR_GET_OS_ERROR(); + } END_WITH_WSTR(prefix); + } END_WITH_WSTR(path); + if (rc) { + ACR_THROW_IO_IF_ERR(rc); + return NULL; + } + else { + jstring rv = ACR_NewJavaStringW(_E, tmpd); + x_free(tmpd); + return rv; + } +} Modified: commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c?rev=821291&r1=821290&r2=821291&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Sat Oct 3 10:51:35 2009 @@ -19,6 +19,7 @@ #include "acr_arch.h" #include "acr_error.h" #include "acr_memory.h" +#include "acr_string.h" #include "acr_descriptor.h" #include "acr_file.h" #include "acr_fileio.h" @@ -56,6 +57,22 @@ return V2Z(f->eof); } +ACR_IO_EXPORT_DECLARE(jboolean, FileWrapper, blocking0)(ACR_JNISTDARGS, + jint file) +{ + acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file); + + if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) { + ACR_THROW_IO_IF_ERR(ACR_EFTYPE); + return JNI_FALSE; + } + if (IS_INVALID_HANDLE(f)) { + ACR_THROW_IO_IF_ERR(ACR_EBADF); + return JNI_FALSE; + } + return f->blocking == BLK_ON ? JNI_TRUE : JNI_FALSE; +} + ACR_IO_EXPORT_DECLARE(jint, FileWrapper, tmset0)(ACR_JNISTDARGS, jint file, jlong timeout) @@ -90,3 +107,19 @@ } return (jlong)f->timeout; } + +ACR_IO_EXPORT_DECLARE(jstring, FileWrapper, name0)(ACR_JNISTDARGS, + jint file) +{ + acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file); + + if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) { + ACR_THROW_IO_IF_ERR(ACR_EFTYPE); + return NULL; + } + if (IS_INVALID_HANDLE(f)) { + ACR_THROW_IO_IF_ERR(ACR_EBADF); + return NULL; + } + return PSTR_TO_JSTRING(f->name); +}