Split OS X specific functions out of posix.cpp.
This commit is contained in:
42
src/main/cpp/osx.cpp
Normal file
42
src/main/cpp/osx.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include "native.h"
|
||||||
|
#include "generic.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ucred.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
@@ -14,9 +14,6 @@
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <xlocale.h>
|
#include <xlocale.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/ucred.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Marks the given result as failed, using the current value of errno
|
* 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);
|
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
|
* Process functions
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,24 +1,29 @@
|
|||||||
#ifndef __INCLUDE_GENERIC_H__
|
#ifndef __INCLUDE_GENERIC_H__
|
||||||
#define __INCLUDE_GENERIC_H__
|
#define __INCLUDE_GENERIC_H__
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Marks the given result as failed, using the given error message
|
* Marks the given result as failed, using the given error message
|
||||||
*/
|
*/
|
||||||
extern void mark_failed_with_message(JNIEnv *env, const char* message, jobject result);
|
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
|
* Marks the given result as failed, using the given error message and the current value of errno/GetLastError()
|
||||||
*/
|
*/
|
||||||
extern void mark_failed_with_code(JNIEnv *env, const char* message, int error_code, jobject result);
|
extern void mark_failed_with_errno(JNIEnv *env, const char* message, jobject result);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
/*
|
||||||
}
|
* Marks the given result as failed, using the given error message and error code
|
||||||
#endif
|
*/
|
||||||
|
extern void mark_failed_with_code(JNIEnv *env, const char* message, int error_code, jobject result);
|
||||||
#endif
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user