Merge pull request #134 from jdeseno/filesystem

complete filesystem api
This commit is contained in:
Tony Aldridge
2014-06-20 09:01:17 +01:00
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
@@ -21,6 +21,7 @@ pub mod clipboard;
pub mod cpuinfo;
pub mod macros;
pub mod event;
pub mod filesystem;
pub mod gesture;
pub mod touch;
pub mod joystick;