mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
complete filesystem api
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
use std::str;
|
||||
use SdlResult;
|
||||
use get_error;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub mod ll {
|
||||
use libc::{c_char};
|
||||
|
||||
extern "C" {
|
||||
pub fn SDL_GetBasePath() -> *c_char;
|
||||
pub fn SDL_GetPrefPath(arg: *c_char, app: *c_char) -> *c_char;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_base_path() -> SdlResult<String> {
|
||||
let result = unsafe {
|
||||
let cstr = ll::SDL_GetBasePath();
|
||||
str::raw::from_c_str(cstr)
|
||||
};
|
||||
|
||||
if result.len() == 0 {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_pref_path(org: &str, app: &str) -> SdlResult<String> {
|
||||
let result = unsafe {
|
||||
let cstr =
|
||||
org.with_c_str(|org_cstr| {
|
||||
app.with_c_str(|app_cstr| {
|
||||
ll::SDL_GetPrefPath(org_cstr, app_cstr)
|
||||
})});
|
||||
str::raw::from_c_str(cstr)
|
||||
};
|
||||
|
||||
if result.len() == 0 {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ pub mod scancode;
|
||||
pub mod cpuinfo;
|
||||
pub mod macros;
|
||||
pub mod event;
|
||||
pub mod filesystem;
|
||||
pub mod gesture;
|
||||
pub mod touch;
|
||||
pub mod joystick;
|
||||
|
||||
Reference in New Issue
Block a user