Fix documentation inaccuracies such as "Set to 0 to not use." when 0 is not a "not use" value and is instead a valid value with discrete meaning.
Remove documentation about non-existent parameter "file".
Clarify the wording in some of the documentation.
Add missing return on error check after several memory allocation function calls.
Add missing range parameter checks.
Error checking is being performed on wrong status variable and wrong status variable is being returned.
Perform some general code clean up as encountered.
#ifndef _di_f_directory_create_
f_status_t f_directory_create(const f_string_static_t path, const mode_t mode) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
return private_f_directory_create(path, mode);
}
#ifndef _di_f_directory_create_at_
f_status_t f_directory_create_at(const int at_id, const f_string_static_t path, const mode_t mode) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
return private_f_directory_create_at(at_id, path, mode);
}
#ifndef _di_f_directory_exists_
f_status_t f_directory_exists(const f_string_static_t path) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
return F_status_set_error(F_file_stat);
}
- if ((file_stat.st_mode & S_IFMT) == S_IFDIR) {
- return F_true;
- }
+ if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true;
return F_false;
}
#ifndef _di_f_directory_exists_at_
f_status_t f_directory_exists_at(const int at_id, const f_string_static_t path, const int flag) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
return F_status_set_error(F_file_stat);
}
- if ((file_stat.st_mode & S_IFMT) == S_IFDIR) {
- return F_true;
- }
+ if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true;
return F_false;
}
#ifndef _di_f_directory_is_
f_status_t f_directory_is(const f_string_static_t path) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
#ifndef _di_f_directory_is_at_
f_status_t f_directory_is_at(const int at_id, const f_string_static_t path, const int flag) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
return F_status_set_error(F_file_stat);
}
- if ((file_stat.st_mode & S_IFMT) == S_IFDIR) {
- return F_true;
- }
+ if ((file_stat.st_mode & S_IFMT) == S_IFDIR) return F_true;
return F_false;
}
if (!names) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct dirent **listing = 0;
f_status_t status = F_none;
f_memory_delete(1, sizeof(struct dirent *), (void *) &listing);
}
- if (F_status_is_error(status)) {
- return status;
- }
-
- if (!length) {
- return F_directory_empty;
- }
+ if (F_status_is_error(status)) return status;
+ if (!length) return F_directory_empty;
return F_none;
}
if (!id) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
int flag = F_directory_flag_directory_d | F_directory_flag_close_execute_d | F_directory_flag_path_d;
if (!id) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
int flag = F_directory_flag_directory_d | F_directory_flag_close_execute_d | F_directory_flag_path_d;
if (depth_max < 0) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
int result = 0;
else {
// Not recursively deleting and the path is requested to be preserved, so there is nothing to delete.
- if (preserve) {
- return F_none;
- }
+ if (preserve) return F_none;
result = remove(path.string);
}
if (depth_max < 0) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
int result = 0;
else {
// Not recursively deleting and the path is requested to be preserved, so there is nothing to delete.
- if (preserve) {
- return F_none;
- }
+ if (preserve) return F_none;
result = remove(path.string);
}
#ifndef _di_f_directory_touch_
f_status_t f_directory_touch(const f_string_static_t path, const mode_t mode) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
memset(&file_stat, 0, sizeof(struct stat));
if (stat(path.string, &file_stat) < 0) {
- if (errno == ENOENT) {
- return private_f_directory_create(path, mode);
- }
-
+ if (errno == ENOENT) return private_f_directory_create(path, mode);
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EFAULT) return F_status_set_error(F_buffer);
if (errno == ELOOP) return F_status_set_error(F_loop);
#ifndef _di_f_directory_touch_at_
f_status_t f_directory_touch_at(const int at_id, const f_string_static_t path, const mode_t mode, const int flag) {
- if (!path.used) {
- return F_data_not;
- }
+ if (!path.used) return F_data_not;
struct stat file_stat;
#if !defined(_di_f_directory_remove_)
int private_f_directory_remove_recursively(const char * const path, const struct stat *file_stat, int type, struct FTW *entity) {
- if (!entity->level) {
- return 0;
- }
+ if (!entity->level) return 0;
return remove(path);
}
* The path file name.
* @param mode
* The file mode to open in.
- * Set to 0 to not use.
* @param file
* The data related to the file being opened.
* This will be updated with the file descriptor.
* The path file name.
* @param mode
* The file mode to open in.
- * Set to 0 to not use.
* @param file
* The data related to the file being opened.
* This will be updated with the file descriptor.
* The path file name.
* @param mode
* The file mode to open in.
- * @param file
- * The data related to the file being opened.
- * This will be updated with the file descriptor.
- * This will be updated with the create flag (ignoring and overriding existing file.flag).
* @param exclusive
* If TRUE, will fail when file already exists.
* If FALSE, will not fail if file already exists.
*
* @param at_id
* The parent directory, as an open directory file descriptor, in which path is relative to.
- * @param file
- * The data related to the file being opened.
- * This will be updated with the file descriptor.
- * This will be updated with the create flag (ignoring and overriding existing file.flag).
* @param path
* The path file name.
* @param mode
* The path file name.
* @param mode
* The file mode to open in.
- * Set to 0 to not use.
* @param file
* The data related to the file being opened.
* This will be updated with the file descriptor.
* The path file name.
* @param mode
* The file mode to open in.
- * Set to 0 to not use.
* @param file
* The data related to the file being opened.
* This will be updated with the file descriptor.
f_status_t status = F_none;
for (f_array_length_t i = length; i < items->size; ++i) {
+
macro_f_fss_item_t_adjust(status, items->array[i], 0)
+ if (F_status_is_error(status)) return status;
} // for
status = f_memory_adjust(items->size, length, sizeof(f_fss_item_t), (void **) & items->array);
f_status_t status = F_none;
for (f_array_length_t i = length; i < items->size; ++i) {
+
macro_f_fss_item_t_resize(status, items->array[i], 0)
+ if (F_status_is_error(status)) return status;
} // for
status = f_memory_resize(items->size, length, sizeof(f_fss_item_t), (void **) & items->array);
f_status_t status = F_none;
for (f_array_length_t i = length; i < nameds->size; ++i) {
+
status = private_f_fss_named_adjust(0, &nameds->array[i]);
if (F_status_is_error(status)) return status;
} // for
f_status_t status = F_none;
for (f_array_length_t i = length; i < nameds->size; ++i) {
+
status = private_f_fss_named_resize(0, &nameds->array[i]);
if (F_status_is_error(status)) return status;
} // for
f_status_t status = F_none;
for (f_array_length_t i = length; i < nest->size; ++i) {
+
status = private_f_fss_items_adjust(0, &nest->depth[i]);
if (F_status_is_error(status)) return status;
} // for
f_status_t status = F_none;
for (f_array_length_t i = length; i < nest->size; ++i) {
+
status = private_f_fss_items_resize(0, &nest->depth[i]);
if (F_status_is_error(status)) return status;
} // for
f_status_t status = F_none;
for (f_array_length_t i = length; i < nests->size; ++i) {
+
status = private_f_fss_nest_adjust(0, &nests->array[i]);
if (F_status_is_error(status)) return status;
} // for
f_status_t status = F_none;
for (f_array_length_t i = length; i < nests->size; ++i) {
+
status = private_f_fss_nest_resize(0, &nests->array[i]);
if (F_status_is_error(status)) return status;
} // for
#endif // _di_fl_directory_clone_
/**
- * Copy a directory contents, as well as its file mode and possibly the owner and group.
+ * Copy a directory contents but not the directory itself, as well as its file mode and possibly the owner and group.
*
* When cloning the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean.
*
/**
* Copy a directory contents.
*
- * When copying the contents of a directory, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean.
+ * When copying the contents of a directory but not the directory itself, both the source and the destination paths must already exist and be directories, regardless of exclusive boolean.
*
* The paths must not contain NULL except for the terminating NULL.
* The paths must be NULL terminated.
#endif
/**
- * An association of a path and a status code.
+ * A structure containing directory recursion information.
*
* The allocation macros apply to the path.
*
#ifndef _di_fl_fss_basic_list_object_write_
f_status_t fl_fss_basic_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) {
#ifndef _di_level_1_parameter_checking_
+ if (!range) return F_status_set_error(F_parameter);
if (!destination) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
#ifndef _di_fl_fss_embedded_list_object_write_
f_status_t fl_fss_embedded_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) {
#ifndef _di_level_1_parameter_checking_
+ if (!range) return F_status_set_error(F_parameter);
if (!destination) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
#ifndef _di_fl_fss_extended_list_object_write_
f_status_t fl_fss_extended_list_object_write(const f_string_static_t object, const uint8_t complete, f_state_t state, f_string_range_t * const range, f_string_dynamic_t * const destination) {
#ifndef _di_level_1_parameter_checking_
+ if (!range) return F_status_set_error(F_parameter);
if (!destination) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
if (fl_string_dynamic_partial_compare_string(f_fss_string_payload_s.string, buffer, f_fss_string_payload_s.used, objects->array[objects->used]) == F_equal_to) {
status2 = f_string_ranges_increase(state.step_small, &contents->array[contents->used]);
- if (F_status_is_error(status)) return status;
+ if (F_status_is_error(status2)) return status2;
contents->array[contents->used].used = 1;
contents->array[contents->used].array[0].start = range->start;