diff --git a/src/main/cpp/osx.cpp b/src/main/cpp/osx.cpp new file mode 100644 index 0000000..31ae0b1 --- /dev/null +++ b/src/main/cpp/osx.cpp @@ -0,0 +1,42 @@ +#ifdef __APPLE__ + +#include "native.h" +#include "generic.h" +#include +#include +#include +#include + +/* + * File system functions + */ +JNIEXPORT void JNICALL +Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) { + int fs_count = getfsstat(NULL, 0, MNT_NOWAIT); + if (fs_count < 0) { + mark_failed_with_errno(env, "could not stat file systems", result); + return; + } + + size_t len = fs_count * sizeof(struct statfs); + struct statfs* buf = (struct statfs*)malloc(len); + if (getfsstat(buf, len, MNT_NOWAIT) < 0 ) { + mark_failed_with_errno(env, "could not stat file systems", result); + free(buf); + return; + } + + jclass info_class = env->GetObjectClass(info); + jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"); + + for (int i = 0; i < fs_count; i++) { + jstring mount_point = env->NewStringUTF(buf[i].f_mntonname); + jstring file_system_type = env->NewStringUTF(buf[i].f_fstypename); + jstring device_name = env->NewStringUTF(buf[i].f_mntfromname); + jboolean remote = (buf[i].f_flags & MNT_LOCAL) == 0; + env->CallVoidMethod(info, method, mount_point, file_system_type, device_name, remote); + } + free(buf); +} + +#endif diff --git a/src/main/cpp/posix.cpp b/src/main/cpp/posix.cpp index 33ca1ba..0ef1457 100755 --- a/src/main/cpp/posix.cpp +++ b/src/main/cpp/posix.cpp @@ -14,9 +14,6 @@ #include #include #include -#include -#include -#include /* * Marks the given result as failed, using the current value of errno @@ -83,38 +80,6 @@ Java_net_rubygrapefruit_platform_internal_jni_PosixFileFunctions_stat(JNIEnv *en env->SetIntField(dest, modeField, 0777 & fileInfo.st_mode); } -/* - * File system functions - */ -JNIEXPORT void JNICALL -Java_net_rubygrapefruit_platform_internal_jni_PosixFileSystemFunctions_listFileSystems(JNIEnv *env, jclass target, jobject info, jobject result) { - int fs_count = getfsstat(NULL, 0, MNT_NOWAIT); - if (fs_count < 0) { - mark_failed_with_errno(env, "could not stat file systems", result); - return; - } - - size_t len = fs_count * sizeof(struct statfs); - struct statfs* buf = (struct statfs*)malloc(len); - if (getfsstat(buf, len, MNT_NOWAIT) < 0 ) { - mark_failed_with_errno(env, "could not stat file systems", result); - free(buf); - return; - } - - jclass info_class = env->GetObjectClass(info); - jmethodID method = env->GetMethodID(info_class, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V"); - - for (int i = 0; i < fs_count; i++) { - jstring mount_point = env->NewStringUTF(buf[i].f_mntonname); - jstring file_system_type = env->NewStringUTF(buf[i].f_fstypename); - jstring device_name = env->NewStringUTF(buf[i].f_mntfromname); - jboolean remote = (buf[i].f_flags & MNT_LOCAL) == 0; - env->CallVoidMethod(info, method, mount_point, file_system_type, device_name, remote); - } - free(buf); -} - /* * Process functions */ diff --git a/src/main/headers/generic.h b/src/main/headers/generic.h index b92d7d7..6d8edb1 100755 --- a/src/main/headers/generic.h +++ b/src/main/headers/generic.h @@ -1,24 +1,29 @@ -#ifndef __INCLUDE_GENERIC_H__ -#define __INCLUDE_GENERIC_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Marks the given result as failed, using the given error message - */ -extern void mark_failed_with_message(JNIEnv *env, const char* message, jobject result); - -/* - * Marks the given result as failed, using the given error message and error code - */ -extern void mark_failed_with_code(JNIEnv *env, const char* message, int error_code, jobject result); - -#ifdef __cplusplus -} -#endif - -#endif +#ifndef __INCLUDE_GENERIC_H__ +#define __INCLUDE_GENERIC_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Marks the given result as failed, using the given error message + */ +extern void mark_failed_with_message(JNIEnv *env, const char* message, jobject result); + +/* + * Marks the given result as failed, using the given error message and the current value of errno/GetLastError() + */ +extern void mark_failed_with_errno(JNIEnv *env, const char* message, jobject result); + +/* + * Marks the given result as failed, using the given error message and error code + */ +extern void mark_failed_with_code(JNIEnv *env, const char* message, int error_code, jobject result); + +#ifdef __cplusplus +} +#endif + +#endif