Now that I am moving towards using pointer constants (sch as "int * const"), I can move many of the parameters to the left side.
I believe this sufficiently follows the pattern of having constants on the left and editables on the right even though the data pointed to can be edited.
I feel this allows me to relax the compromise I originally made when following this design paradigm.
#endif
/**
- * Provide common file-typ specific data types.
+ * Provide file defaults.
+ *
+ * F_file_default_*:
+ * - read_size: Default read size in bytes.
+ * - write_size: Default write size in bytes.
*/
-#ifndef _di_f_file_types_
- #define F_file_default_read_size_d 8192 // default to 8k read sizes. // @fixme rename and move into _di_f_file_type_
- #define F_file_default_write_size_d 8192 // default to 8k write sizes. // @fixme rename and move into _di_f_file_type_
-#endif // _di_f_file_types_
+#ifndef _di_f_file_defaults_
+ #define F_file_default_read_size_d 8192
+ #define F_file_default_write_size_d 8192
+#endif // _di_f_file_defaults_
/**
* Provide macros for file-seek operations.
* The fseek() function parameters can be confusing, so provide a hopefully more readibly code via these macros.
*
* macro_f_file_seek_*:
- * - begin: sets the file pointer from this many bytes from the beginning of the file.
- * - data: sets the file pointer from this many bytes from the end of the file, relative to the next data.
- * - end: sets the file pointer from this many bytes from the end of the file.
- * - hole: sets the file pointer from this many bytes from the end of the file, relative to the next hole.
- * - to: sets the file pointer from this many bytes relative to the current position.
+ * - begin: sets the file pointer from this many bytes from the beginning of the file.
+ * - data: sets the file pointer from this many bytes from the end of the file, relative to the next data.
+ * - end: sets the file pointer from this many bytes from the end of the file.
+ * - hole: sets the file pointer from this many bytes from the end of the file, relative to the next hole.
+ * - to: sets the file pointer from this many bytes relative to the current position.
*/
#ifndef _di_f_file_seeks_
#define macro_f_file_seek_begin(file, bytes) fseek(file, bytes, SEEK_SET)
#endif // _di_f_file_clone_
#ifndef _di_f_file_close_
- f_status_t f_file_close(int *id) {
- return private_f_file_close(F_false, id);
+ f_status_t f_file_close(int * const id) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!id) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ return private_f_file_close(id, F_false);
}
#endif // _di_f_file_close_
#ifndef _di_f_file_close_flush_
- f_status_t f_file_close_flush(int *id) {
- return private_f_file_close(F_true, id);
+ f_status_t f_file_close_flush(int * const id) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!id) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ return private_f_file_close(id, F_true);
}
#endif // _di_f_file_close_flush_
}
if (complete) {
- return private_f_file_close(F_true, &file->id);
+ return private_f_file_close(&file->id, F_true);
}
return F_none;
* @see fclose()
*/
#ifndef _di_f_file_close_
- extern f_status_t f_file_close(int *id);
+ extern f_status_t f_file_close(int * const id);
#endif // _di_f_file_close_
/**
* @see fclose()
*/
#ifndef _di_f_file_close_flush_
- extern f_status_t f_file_close_flush(int *id);
+ extern f_status_t f_file_close_flush(int * const id);
#endif // _di_f_file_close_flush_
/**
#endif
#if !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
- f_status_t private_f_file_close(const bool flush, int *id) {
+ f_status_t private_f_file_close(int * const id, const bool flush) {
- if (id == 0 || *id == -1) {
+ if (*id == -1) {
return F_none;
}
status = private_f_file_open(destination, 0, &file_destination);
if (F_status_is_error(status)) {
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_source.id, F_true);
+
return status;
}
size_write = write(file_destination.id, buffer, size_read);
if (size_write < 0 || size_write != size_read) {
- private_f_file_close(F_true, &file_destination.id);
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_destination.id, F_true);
+ private_f_file_close(&file_source.id, F_true);
return F_status_set_error(F_file_write);
}
} // while
- private_f_file_close(F_true, &file_destination.id);
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_destination.id, F_true);
+ private_f_file_close(&file_source.id, F_true);
if (size_read < 0) {
return F_status_set_error(F_file_read);
status = private_f_file_open_at(at_id, destination, 0, &file_destination);
if (F_status_is_error(status)) {
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_source.id, F_true);
+
return status;
}
size_write = write(file_destination.id, buffer, size_read);
if (size_write < 0 || size_write != size_read) {
- private_f_file_close(F_true, &file_destination.id);
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_destination.id, F_true);
+ private_f_file_close(&file_source.id, F_true);
return F_status_set_error(F_file_write);
}
} // while
- private_f_file_close(F_true, &file_destination.id);
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_close(&file_destination.id, F_true);
+ private_f_file_close(&file_source.id, F_true);
if (size_read < 0) {
return F_status_set_error(F_file_read);
const f_status_t status = private_f_file_open(path, mode, &file);
if (file.id != -1) {
- return private_f_file_close(F_true, &file.id);
+ return private_f_file_close(&file.id, F_true);
}
return status;
const f_status_t status = private_f_file_open_at(at_id, path, mode, &file);
if (file.id != -1) {
- return private_f_file_close(F_true, &file.id);
+ return private_f_file_close(&file.id, F_true);
}
return status;
*
* Intended to be shared to each of the different implementation variations.
*
+ * @param id
+ * The file descriptor.
+ * The value gets set to -1.
* @param flush
* If TRUE, then perform flush before closing.
* If FALSE, then do not perform flush before closing.
- * @param id
- * The file descriptor.
*
* @return
* F_none on success.
* @see f_file_stream_close()
*/
#if !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
- extern f_status_t private_f_file_close(const bool flush, int *id) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_close(int * const id, const bool flush) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
/**