Ji-Xinyou commented on code in PR #1892:
URL:
https://github.com/apache/incubator-opendal/pull/1892#discussion_r1161837724
##########
bindings/c/src/lib.rs:
##########
@@ -148,3 +149,43 @@ pub unsafe extern "C" fn opendal_operator_blocking_read(
},
}
}
+
+/// Check whether the path exists.
+///
+/// If the operation succeeds, no matter the path exists or not,
+/// the error code should be opendal_code::OPENDAL_OK. Otherwise,
+/// the field `exist` is filled with false, and the error code
+/// is set correspondingly.
+///
+/// # Safety
+///
+/// It is [safe] under two cases below
+/// * The memory pointed to by `path` must contain a valid nul terminator at
the end of
+/// the string.
+/// * The `path` points to NULL, this function simply returns you a false for
field `exist`
+/// and corresponding error code.
+#[no_mangle]
+pub unsafe extern "C" fn opendal_operator_is_exist(
+ op_ptr: opendal_operator_ptr,
+ path: *const c_char,
+) -> opendal_result_exist {
+ if path.is_null() {
Review Comment:
We could just panic here, it is pretty flexible. The common practice in C is
```C
some_type *p = some_func();
if (!p)
return some_errno;
```
The behavior here when nullptr is given could be rather panic or an invalid
return value. My intension was letting the user check the `opendal_code`.
What's your opinion?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]