// POSIX basename() modifies the path, so protect it (and add a terminating NULL).
char path_argument[path.used + 1];
- f_string_t path_to_name;
memcpy(path_argument, path.string, sizeof(f_char_t) * path.used);
path_argument[path.used] = 0;
- path_to_name = (f_string_t) basename(path_argument);
+ char *path_to_name = basename(path_argument);
const f_array_length_t size = strnlen(path_to_name, path.used);
// POSIX dirname() modifies the path, so protect it (and add a terminating NULL).
char path_argument[path.used + 1];
- f_string_t path_to_name;
memcpy(path_argument, path.string, sizeof(f_char_t) * path.used);
path_argument[path.used] = 0;
- path_to_name = (f_string_t) dirname(path_argument);
+ char *path_to_name = dirname(path_argument);
const f_array_length_t size = strnlen(path_to_name, path.used);
- // Do not treat '.' as a directory.
- if (size == 1 && f_string_ascii_plus_s.string[0]) {
- return F_none;
- }
-
{
const f_status_t status = f_string_dynamic_increase_by(size + 1, name_directory);
if (F_status_is_error(status)) return status;
}
+ // Do not treat '.' as a directory.
+ if (size == 1 && path_to_name[0] == f_string_ascii_period_s.string[0]) {
+ return f_string_dynamic_terminate_after(name_directory);
+ }
+
memcpy(name_directory->string + name_directory->used, path_to_name, sizeof(f_char_t) * size);
name_directory->used += size;
name_directory->string[name_directory->used] = 0;
buffer->used += size_read;
- } while (size_read == file.size_read);
+ } while (size_read);
return F_none_eof;
}
return F_status_set_error(F_failure);
}
- if (size_read < file.size_read) {
- return F_none_eof;
+ if (size_read) {
+ return F_none;
}
- return F_none;
+ return F_none_eof;
}
#endif // _di_f_file_read_block_
return F_status_set_error(F_file_closed);
}
+ if (!total) {
+ return F_data_not;
+ }
+
f_array_length_t buffer_size = file.size_read;
f_array_length_t buffer_count = 0;
buffer->used += size_read;
- if (size_read < buffer_size) {
+ if (!size_read) {
return F_none_eof;
}
/**
* Get the directory name of a file path.
*
+ * This does not consider '.' a directory for the purposes of appending the directory.
+ *
* @param path
* The path file name.
* Need not be NULL terminated.
* F_string_too_large (with error bit) if string is too large to store in the buffer.
*
* Errors (with error bit) from: f_string_dynamic_increase_by().
+ * Errors (with error bit) from: f_string_dynamic_terminate_after().
*
* @see dirname()
*
* @see f_string_dynamic_increase_by()
+ * @see f_string_dynamic_terminate_after()
*/
#ifndef _di_f_file_name_directory_
extern f_status_t f_file_name_directory(const f_string_static_t path, f_string_dynamic_t * const name_directory);
* @return
* F_none_eof on success and EOF was reached.
* F_none_stop on success and total was reached.
+ * F_data_not if total is 0.
*
* F_block (with error bit) if file descriptor is set to non-block and the read would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.