f_status_t f_file_seek(const f_file_t file, const int whence, const off_t offset, off_t * const seeked) {
#ifndef _di_level_0_parameter_checking_
if (whence < 0) return F_status_set_error(F_parameter);
- if (!seeked) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
if (file.id == -1) return F_file_descriptor_not;
- *seeked = lseek(file.id, offset, whence);
+ const int result = lseek(file.id, offset, whence);
- if (*seeked < 0) {
+ if (result == -1) {
if (errno == EBADF) return F_status_set_error(F_file_descriptor_not);
if (errno == EINVAL) return F_status_set_error(F_parameter);
if (errno == ENXIO) return F_status_set_error(F_bound_not);
return F_status_set_error(F_failure);
}
+ *seeked = result;
+
return F_okay;
}
#endif // _di_f_file_seek_
* @param offset
* The offset to use, based off of whence.
* @param seeked
- * This gets update to represent the total amount seeked.
+ * (optional) This gets update to represent the total amount seeked.
* To be compared against offset.
*
+ * Set to NULL to not use.
+ *
* @return
* F_okay on success.
* F_file_descriptor_not if file.id is -1.
assert_int_equal(status, F_status_set_error(F_parameter));
}
-
- {
- const f_status_t status = f_file_seek(file, 0, 0, 0);
-
- assert_int_equal(status, F_status_set_error(F_parameter));
- }
}
void test__f_file_seek__returns_file_descriptor_not(void **state) {