You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "silver-ymz (via GitHub)" <gi...@apache.org> on 2025/04/29 02:17:55 UTC
Re: [PR] feat(bindings/c): Add seek support for c-binding [opendal]
silver-ymz commented on code in PR #6119:
URL: https://github.com/apache/opendal/pull/6119#discussion_r2065244408
##########
bindings/c/src/reader.rs:
##########
@@ -72,6 +76,33 @@ impl opendal_reader {
}
}
+ /// \brief Seek to an offset, in bytes, in a stream.
+ #[no_mangle]
+ pub unsafe extern "C" fn opendal_reader_seek(
+ &mut self,
+ offset: i64,
+ whence: i32,
+ ) -> *mut opendal_error {
+ let pos = match whence {
+ _x @ OPENDAL_SEEK_SET => SeekFrom::Start(offset as u64),
+ _x @ OPENDAL_SEEK_CUR => SeekFrom::Current(offset),
+ _x @ OPENDAL_SEEK_END => SeekFrom::End(offset),
+ _ => {
+ return opendal_error::new(core::Error::new(
+ core::ErrorKind::Unexpected,
+ "undefined whence",
+ ))
+ }
+ };
+
+ match self.deref_mut().seek(pos) {
+ Ok(_) => std::ptr::null_mut(),
+ Err(e) => {
+ opendal_error::new(core::Error::new(core::ErrorKind::Unexpected, e.to_string()))
+ }
Review Comment:
Setting error source here may be better to show more infomations
```rust
opendal_error::new(core::Error::new(core::ErrorKind::Unexpected, "seek failed from reader").set_source(e))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org