complete filesystem api

This commit is contained in:
josh
2014-06-20 06:41:13 +09:00
parent ee150ce399
commit faad71edf4
2 changed files with 45 additions and 0 deletions
+44
View File
@@ -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)
}
}
+1
View File
@@ -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;