Storage: a path buffer too small fails with E_FAIL, as on Xbox
XPersistentLocalStorageGetPath documents E_FAIL for a pathSize smaller than the path on Xbox devices; ERROR_INSUFFICIENT_BUFFER is the PC result, which put_string gave us.
This commit is contained in:
1 parent
d2a4bae1f4
commit
376b3cf178
1 file changed
+6
@@ -38,6 +38,8 @@ pub const IID_2026: Guid = Guid::new(
|
|||||||
pub static OBJECT: Object = Object::new("persistent local storage", &VTABLE);
|
pub static OBJECT: Object = Object::new("persistent local storage", &VTABLE);
|
||||||
pub const INTERFACES: &[Interface] = &[(PROVIDER, IID, &OBJECT), (PROVIDER, IID_2026, &OBJECT)];
|
pub const INTERFACES: &[Interface] = &[(PROVIDER, IID, &OBJECT), (PROVIDER, IID_2026, &OBJECT)];
|
||||||
|
|
||||||
|
const E_FAIL: HRESULT = 0x8000_4005_u32 as i32;
|
||||||
|
|
||||||
type This = *const Object;
|
type This = *const Object;
|
||||||
|
|
||||||
/// The path titles get: the root of a virtual drive over the folder. On the
|
/// The path titles get: the root of a virtual drive over the folder. On the
|
||||||
@@ -63,8 +65,11 @@ extern "system" fn path_size(_: This, out: *mut usize) -> HRESULT {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A buffer too small for the path fails with `E_FAIL`, the documented
|
||||||
|
/// Xbox result (a PC gets `ERROR_INSUFFICIENT_BUFFER`).
|
||||||
extern "system" fn path(_: This, size: usize, buffer: *mut u8, used: *mut usize) -> HRESULT {
|
extern "system" fn path(_: This, size: usize, buffer: *mut u8, used: *mut usize) -> HRESULT {
|
||||||
match folder() {
|
match folder() {
|
||||||
|
Some(path) if size <= path.len() => E_FAIL,
|
||||||
Some(path) => put_string(&path, size, buffer, used),
|
Some(path) => put_string(&path, size, buffer, used),
|
||||||
None => NOT_SUPPORTED,
|
None => NOT_SUPPORTED,
|
||||||
}
|
}
|
||||||
@@ -196,6 +201,7 @@ mod tests {
|
|||||||
let (mut buffer, mut used) = ([0u8; 4], 0);
|
let (mut buffer, mut used) = ([0u8; 4], 0);
|
||||||
let get = method::<Get>(&OBJECT, 0x20);
|
let get = method::<Get>(&OBJECT, 0x20);
|
||||||
assert_eq!(get(this, 4, buffer.as_mut_ptr(), &mut used), S_OK);
|
assert_eq!(get(this, 4, buffer.as_mut_ptr(), &mut used), S_OK);
|
||||||
|
assert_eq!(get(this, 3, buffer.as_mut_ptr(), &mut used), E_FAIL);
|
||||||
let drive = std::str::from_utf8(&buffer[..3]).unwrap();
|
let drive = std::str::from_utf8(&buffer[..3]).unwrap();
|
||||||
assert!(drive.ends_with(":\\"), "{drive}");
|
assert!(drive.ends_with(":\\"), "{drive}");
|
||||||
// Title file calls on it reach the folder.
|
// Title file calls on it reach the folder.
|
||||||
|
|||||||
Reference in new issue
Block a user