I like having support for "standard" debug and "standard" warning.
The problem is that there is no such standard.
These are made available in case there ever is.
I want to simplify the code, so get rid of this non-standard "standard" code.
The low-level file functions inconsistently used id, stream, and file structure.
Switch everything to use the file structure.
Relax function errors by having invalid stream or invalid file descriptor return without error bit set.
In these cases use special status codes F_stream_not and F_file_descriptor_not as appropriate.
Simplify the functions to be simpler.
Some of the functions, namely the close functions, also support conditionally flushing before close.
Remove the flushing and the passed boolean.
Let the caller use two functions directly rather than building this in.
Add missing function for flushing via the file descriptor.
The private_f_file_flush() function is missing several disable macro checks.
(This change needs to be backported.)
This change does not address the tests.
This change does not address the programs that use or might use the changed, new, or deleted code.
#endif // _di_f_file_access_
#ifndef _di_f_file_access_at_
- f_status_t f_file_access_at(const int at_id, const f_string_static_t path, const int mode, const int flag) {
+ f_status_t f_file_access_at(const f_file_t directory, const f_string_static_t path, const int mode, const int flag) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- if (faccessat(at_id, path.string, mode, flag) == -1) {
+ if (faccessat(directory.id, path.string, mode, flag) == -1) {
if (mode == F_file_access_mode_exist_d) {
if (errno == ENOENT) return F_false;
#endif // _di_f_file_clone_
#ifndef _di_f_file_close_
- f_status_t f_file_close(int * const id) {
+ f_status_t f_file_close(f_file_t * const file) {
#ifndef _di_level_0_parameter_checking_
- if (!id) return F_status_set_error(F_parameter);
+ if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- return private_f_file_close(F_false, id);
- }
-#endif // _di_f_file_close_
-
-#ifndef _di_f_file_close_flush_
- 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_
+ if (file->id == -1) return F_file_descriptor_not;
- return private_f_file_close(F_true, id);
+ return private_f_file_close(file);
}
-#endif // _di_f_file_close_flush_
+#endif // _di_f_file_close_
#ifndef _di_f_file_copy_
f_status_t f_file_copy(const f_string_static_t source, const f_string_static_t destination, const f_mode_t mode, const f_number_unsigned_t size_block, const uint8_t flag) {
#endif // _di_f_file_create_
#ifndef _di_f_file_create_at_
- f_status_t f_file_create_at(const int at_id, const f_string_static_t path, const mode_t mode, const bool exclusive) {
+ f_status_t f_file_create_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const bool exclusive) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- return private_f_file_create_at(at_id, path, mode, exclusive);
+ return private_f_file_create_at(directory, path, mode, exclusive);
}
#endif // _di_f_file_create_at_
#endif // _di_f_file_create_device_
#ifndef _di_f_file_create_device_at_
- f_status_t f_file_create_device_at(const int at_id, const f_string_static_t path, const mode_t mode, const unsigned int major, const unsigned int minor) {
+ f_status_t f_file_create_device_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const unsigned int major, const unsigned int minor) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
if (!macro_f_file_type_is_fifo(mode) && !macro_f_file_type_is_character(mode) && !macro_f_file_type_is_block(mode)) {
const dev_t device = makedev(major, minor);
- return private_f_file_create_node_at(at_id, path, mode, device);
+ return private_f_file_create_node_at(directory, path, mode, device);
}
#endif // _di_f_file_create_device_at_
#endif // _di_f_file_create_fifo_
#ifndef _di_f_file_create_fifo_at_
- f_status_t f_file_create_fifo_at(const int at_id, const f_string_static_t path, const mode_t mode) {
+ f_status_t f_file_create_fifo_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- return private_f_file_create_fifo_at(at_id, path, mode);
+ return private_f_file_create_fifo_at(directory, path, mode);
}
#endif // _di_f_file_create_fifo_at_
#endif // _di_f_file_create_node_
#ifndef _di_f_file_create_node_at_
- f_status_t f_file_create_node_at(const int at_id, const f_string_static_t path, const mode_t mode, const dev_t device) {
+ f_status_t f_file_create_node_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const dev_t device) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
if (!macro_f_file_type_is_fifo(mode) && !macro_f_file_type_is_character(mode) && !macro_f_file_type_is_block(mode)) {
return F_status_set_error(F_supported_not);
}
- return private_f_file_create_node_at(at_id, path, mode, device);
+ return private_f_file_create_node_at(directory, path, mode, device);
}
#endif // _di_f_file_create_node_at_
#ifndef _di_f_file_descriptor_
- f_status_t f_file_descriptor(f_file_t *file) {
+ f_status_t f_file_descriptor(f_file_t * const file) {
#ifndef _di_level_0_parameter_checking_
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (!file->stream) return F_stream_not;
+
file->id = fileno(file->stream);
- if (file->id == -1) return F_status_set_error(F_stream_not);
+ if (file->id == -1) return F_status_set_error(F_file_descriptor_not);
return F_none;
}
#endif // _di_f_file_exists_
#ifndef _di_f_file_exists_at_
- f_status_t f_file_exists_at(const int at_id, const f_string_static_t path, const int flag) {
+ f_status_t f_file_exists_at(const f_file_t directory, const f_string_static_t path, const int flag) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
- const f_status_t status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ const f_status_t status = private_f_file_stat_at(directory, path, flag, &stat_file);
if (F_status_is_error(status)) {
if (F_status_set_fine(status) == F_file_found_not) return F_false;
#endif // _di_f_file_exists_at_
#ifndef _di_f_file_flush_
- f_status_t f_file_flush(const int id) {
+ f_status_t f_file_flush(const f_file_t file) {
- return private_f_file_flush(id);
+ if (file.id == -1) return F_file_descriptor_not;
+
+ return private_f_file_flush(file);
}
#endif // _di_f_file_flush_
#endif // _di_f_file_is_
#ifndef _di_f_file_is_at_
- f_status_t f_file_is_at(const int at_id, const f_string_static_t path, const int type, const int flag) {
+ f_status_t f_file_is_at(const f_file_t directory, const f_string_static_t path, const int type, const int flag) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
- if (fstatat(at_id, path.string, &stat_file, flag) < 0) {
+ if (fstatat(directory.id, path.string, &stat_file, flag) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
#endif // _di_f_file_link_
#ifndef _di_f_file_link_at_
- f_status_t f_file_link_at(const int at_id, const f_string_static_t target, const f_string_static_t point) {
+ f_status_t f_file_link_at(const f_file_t directory, const f_string_static_t target, const f_string_static_t point) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!target.used || !point.used) return F_data_not;
- return private_f_file_link_at(at_id, target, point);
+ return private_f_file_link_at(directory, target, point);
}
#endif // _di_f_file_link_at_
#endif // _di_f_file_link_hard_
#ifndef _di_f_file_link_hard_at_
- f_status_t f_file_link_hard_at(const int at_id_target, const int at_id_point, const f_string_static_t target, const f_string_static_t point, const int flag) {
+ f_status_t f_file_link_hard_at(const f_file_t file_target, const f_file_t file_point, const f_string_static_t target, const f_string_static_t point, const int flag) {
+ if (file_target.id == -1 || file_point.id == -1) return F_file_descriptor_not;
if (!target.used || !point.used) return F_data_not;
- if (linkat(at_id_target, target.string, at_id_point, point.string, flag) < 0) {
+ if (linkat(file_target.id, target.string, file_point.id, point.string, flag) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
#endif // _di_f_file_link_read_
#ifndef _di_f_file_link_read_at_
- f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const int flag, f_string_dynamic_t * const target) {
+ f_status_t f_file_link_read_at(const f_file_t directory, const f_string_static_t path, const int flag, f_string_dynamic_t * const target) {
#ifndef _di_level_0_parameter_checking_
if (!target) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ const f_status_t status = private_f_file_stat_at(directory, path, flag, &stat_file);
if (F_status_is_error(status)) return status;
}
- return private_f_file_link_read_at(at_id, path, stat_file.st_size, target);
+ return private_f_file_link_read_at(directory, path, stat_file.st_size, target);
}
#endif // _di_f_file_link_read_at_
#endif // _di_f_file_mode_read_
#ifndef _di_f_file_mode_read_at_
- f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, const int flag, mode_t * const mode) {
+ f_status_t f_file_mode_read_at(const f_file_t file, const f_string_static_t path, const int flag, mode_t * const mode) {
#ifndef _di_level_0_parameter_checking_
if (!mode) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (file.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ const f_status_t status = private_f_file_stat_at(file, path, flag, &stat_file);
if (F_status_is_error(status)) return status;
}
#endif // _di_f_file_mode_set_
#ifndef _di_f_file_mode_set_at_
- f_status_t f_file_mode_set_at(const int at_id, const f_string_static_t path, const mode_t mode) {
+ f_status_t f_file_mode_set_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- return private_f_file_mode_set_at(at_id, path, mode);
+ return private_f_file_mode_set_at(directory, path, mode);
}
#endif // _di_f_file_mode_set_at_
#endif // _di_f_file_open_
#ifndef _di_f_file_open_at_
- f_status_t f_file_open_at(const int at_id, const f_string_static_t path, const mode_t mode, f_file_t * const file) {
+ f_status_t f_file_open_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, f_file_t * const file) {
#ifndef _di_level_0_parameter_checking_
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- return private_f_file_open_at(at_id, path, mode, file);
+ return private_f_file_open_at(directory, path, mode, file);
}
#endif // _di_f_file_open_at_
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (file.id == -1) return F_status_set_error(F_file_closed);
+ if (file.id == -1) return F_file_descriptor_not;
f_status_t status = F_none;
ssize_t size_read = 0;
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (file.id == -1) return F_status_set_error(F_file_closed);
+ if (file.id == -1) return F_file_descriptor_not;
ssize_t size_read = 0;
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (file.id == -1) return F_status_set_error(F_file_closed);
-
+ if (file.id == -1) return F_file_descriptor_not;
if (!total) return F_data_not;
f_array_length_t buffer_size = file.size_read;
#endif // _di_f_file_remove_
#ifndef _di_f_file_remove_at_
- f_status_t f_file_remove_at(const int at_id, const f_string_static_t path, const int flag) {
+ f_status_t f_file_remove_at(const f_file_t directory, const f_string_static_t path, const int flag) {
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- if (unlinkat(at_id, path.string, flag) < 0) {
+ if (unlinkat(directory.id, path.string, flag) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EBUSY) return F_status_set_error(F_busy);
#endif // _di_f_file_rename_
#ifndef _di_f_file_rename_at_
- f_status_t f_file_rename_at(const int at_id, const int to_id, const f_string_static_t source, const f_string_static_t destination, const unsigned int flag) {
+ f_status_t f_file_rename_at(const f_file_t directory_source, const f_file_t directory_destination, const f_string_static_t source, const f_string_static_t destination, const unsigned int flag) {
+ if (directory_source.id == -1 || directory_destination.id == -1) return F_file_descriptor_not;
if (!source.used || !destination.used) return F_data_not;
#ifdef _f_file_rename_use_renameat2_
- if (renameat2(at_id, source.string, to_id, destination.string, flag) < 0) {
+ if (renameat2(directory_source.id, source.string, directory_destination.id, destination.string, flag) < 0) {
#else
- if (renameat(at_id, source.string, to_id, destination.string) < 0) {
+ if (renameat(directory_source.id, source.string, directory_destination.id, destination.string) < 0) {
#endif // _f_file_rename_use_renameat2_
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
#endif // _di_f_file_role_change_
#ifndef _di_f_file_role_change_at_
- f_status_t f_file_role_change_at(const int at_id, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
+ f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
+ if (directory.id == -1) return F_file_descriptor_not;
if ((uid == -1 && gid == -1) || !path.used) return F_data_not;
- return private_f_file_role_change_at(at_id, path, uid, gid, flag);
+ return private_f_file_role_change_at(directory, path, uid, gid, flag);
}
#endif // _di_f_file_role_change_at_
#ifndef _di_f_file_seek_
- f_status_t f_file_seek(const int id, const int whence, const off_t offset, off_t * const seeked) {
+ 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_
- *seeked = lseek(id, offset, whence);
+ if (file.id == -1) return F_file_descriptor_not;
+
+ *seeked = lseek(file.id, offset, whence);
if (*seeked < 0) {
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
#endif // _di_f_file_size_
#ifndef _di_f_file_size_at_
- f_status_t f_file_size_at(const int at_id, const f_string_static_t path, const bool dereference, off_t * const size) {
+ f_status_t f_file_size_at(const f_file_t directory, const f_string_static_t path, const bool dereference, off_t * const size) {
#ifndef _di_level_0_parameter_checking_
if (!size) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat_at(at_id, path, dereference, &stat_file);
+ const f_status_t status = private_f_file_stat_at(directory, path, dereference, &stat_file);
if (F_status_is_error(status)) return status;
}
#endif // _di_f_file_size_at_
#ifndef _di_f_file_size_by_id_
- f_status_t f_file_size_by_id(const int id, off_t * const size) {
+ f_status_t f_file_size_by_id(const f_file_t file, off_t * const size) {
#ifndef _di_level_0_parameter_checking_
if (!size) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (id == -1) return F_status_set_error(F_file_closed);
+ if (file.id == -1) return F_file_descriptor_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat_by_id(id, &stat_file);
+ const f_status_t status = private_f_file_stat_by_id(file, &stat_file);
if (F_status_is_error(status)) return status;
}
#endif // _di_f_file_stat_
#ifndef _di_f_file_stat_at_
- f_status_t f_file_stat_at(const int at_id, const f_string_static_t path, const int flag, struct stat * const stat_file) {
+ f_status_t f_file_stat_at(const f_file_t directory, const f_string_static_t path, const int flag, struct stat * const stat_file) {
#ifndef _di_level_0_parameter_checking_
if (!stat_file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (directory.id == -1) return F_file_descriptor_not;
if (!path.used) return F_data_not;
- return private_f_file_stat_at(at_id, path, flag, stat_file);
+ return private_f_file_stat_at(directory, path, flag, stat_file);
}
#endif // _di_f_file_stat_at_
#ifndef _di_f_file_stat_by_id_
- f_status_t f_file_stat_by_id(const int id, struct stat * const stat_file) {
+ f_status_t f_file_stat_by_id(const f_file_t file, struct stat * const stat_file) {
#ifndef _di_level_0_parameter_checking_
if (!stat_file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (id == -1) {
- return F_status_set_error(F_file_closed);
- }
+ if (file.id == -1) return F_file_descriptor_not;
- return private_f_file_stat_by_id(id, stat_file);
+ return private_f_file_stat_by_id(file, stat_file);
}
#endif // _di_f_file_stat_by_id_
#ifndef _di_f_file_stream_close_
- f_status_t f_file_stream_close(const bool flush, f_file_t * const file) {
+ f_status_t f_file_stream_close(f_file_t * const file) {
#ifndef _di_level_0_parameter_checking_
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (file->stream) {
- if (flush) {
- fflush(file->stream);
- }
+ if (!file->stream) return F_stream_not;
- if (fclose(file->stream) == EOF) {
-
- // According to man pages, further access to a stream on error results in undefined behavior.
- file->stream = 0;
- file->id = -1;
-
- if (errno == EACCES) return F_status_set_error(F_access_denied);
- if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block);
- if (errno == EBADF) return F_status_set_error(F_file_descriptor);
- if (errno == EFBIG) return F_status_set_error(F_file_overflow);
- if (errno == EDEADLK) return F_status_set_error(F_deadlock);
- if (errno == EDESTADDRREQ) return F_status_set_error(F_socket_not);
- if (errno == EDQUOT) return F_status_set_error(F_space_not);
- if (errno == EFAULT) return F_status_set_error(F_buffer);
- if (errno == EINTR) return F_status_set_error(F_interrupt);
- if (errno == EINVAL) return F_status_set_error(F_parameter);
- if (errno == EIO) return F_status_set_error(F_input_output);
- if (errno == EMFILE) return F_status_set_error(F_file_descriptor_max);
- if (errno == ENOLCK) return F_status_set_error(F_lock);
- if (errno == ENOSPC) return F_status_set_error(F_space_not);
- if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory);
- if (errno == EPERM) return F_status_set_error(F_prohibited);
- if (errno == EPIPE) return F_status_set_error(F_pipe_not);
-
- return F_status_set_error(F_file_close);
- }
+ if (fclose(file->stream) == EOF) {
+ // According to man pages, further access to a stream on error results in undefined behavior.
file->stream = 0;
- file->id = -1;
- return F_none;
- }
+ if (errno == EACCES) return F_status_set_error(F_access_denied);
+ if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block);
+ if (errno == EBADF) return F_status_set_error(F_file_descriptor);
+ if (errno == EFBIG) return F_status_set_error(F_file_overflow);
+ if (errno == EDEADLK) return F_status_set_error(F_deadlock);
+ if (errno == EDESTADDRREQ) return F_status_set_error(F_socket_not);
+ if (errno == EDQUOT) return F_status_set_error(F_space_not);
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINTR) return F_status_set_error(F_interrupt);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == EIO) return F_status_set_error(F_input_output);
+ if (errno == EMFILE) return F_status_set_error(F_file_descriptor_max);
+ if (errno == ENOLCK) return F_status_set_error(F_lock);
+ if (errno == ENOSPC) return F_status_set_error(F_space_not);
+ if (errno == ENOTDIR) return F_status_set_error(F_file_type_not_directory);
+ if (errno == EPERM) return F_status_set_error(F_prohibited);
+ if (errno == EPIPE) return F_status_set_error(F_pipe_not);
- const f_status_t status = private_f_file_close(flush, &file->id);
+ return F_status_set_error(F_file_close);
+ }
file->stream = 0;
- file->id = -1;
- return status;
+ return F_none;
}
#endif // _di_f_file_stream_close_
+#ifndef _di_f_file_stream_flush_
+ f_status_t f_file_stream_flush(f_file_t * const file) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file->stream) return F_stream_not;
+
+ // Only 0 is considered a success and so any non-zero value could be an error.
+ if (fflush(file->stream) != 0) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block);
+ if (errno == EBADF) return F_status_set_error(F_file_descriptor);
+ if (errno == EFAULT) return F_status_set_error(F_buffer);
+ if (errno == EINTR) return F_status_set_error(F_interrupt);
+ if (errno == EINVAL) return F_status_set_error(F_parameter);
+ if (errno == EIO) return F_status_set_error(F_input_output);
+ if (errno == EISDIR) return F_status_set_error(F_file_type_directory);
+
+ return F_status_set_error(F_file_synchronize);
+ }
+
+ return F_none;
+ }
+#endif // _di_f_file_stream_flush_
+
#ifndef _di_f_file_stream_open_
f_status_t f_file_stream_open(const f_string_static_t path, const f_string_static_t mode, f_file_t * const file) {
#ifndef _di_level_0_parameter_checking_
return F_status_set_error(F_failure);
}
- file->id = fileno(file->stream);
-
- if (file->id == -1) return F_status_set_error(F_file_descriptor);
-
return F_none;
}
#endif // _di_f_file_stream_open_
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (file->id == -1) return F_status_set_error(F_file_descriptor);
+ if (file->id == -1) return F_file_descriptor_not;
if (mode.used) {
file->stream = fdopen(file->id, private_f_file_stream_open_mode_determine(file->flag));
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
+ if (!file.stream) return F_stream_not;
flockfile(file.stream);
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
+ if (!file.stream) return F_stream_not;
flockfile(file.stream);
if (!buffer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
- if (!total) return F_none_stop;
+ if (!file.stream) return F_stream_not;
+ if (!total) return F_data_not;
flockfile(file.stream);
}
file->stream = result;
- file->id = fileno(file->stream);
-
- if (file->id == -1) return F_status_set_error(F_file_descriptor);
return F_none;
}
#ifndef _di_f_file_stream_write_
f_status_t f_file_stream_write(const f_file_t file, const f_string_static_t buffer, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
-
- if (!buffer.used) {
+ if (!file.stream || !buffer.used || !file.size_write) {
if (written) {
*written = 0;
}
- return F_data_not;
+ return file.stream ? F_data_not : F_stream_not;
}
- f_status_t status = F_none;
-
if (written) {
- status = private_f_file_stream_write_until(file, buffer, buffer.used, written);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, written);
if (status == F_none && *written == buffer.used) return F_none_eos;
}
else {
f_array_length_t written_local = 0;
- status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
if (status == F_none && written_local == buffer.used) return F_none_eos;
}
- return status;
+ return F_none;
}
#endif // _di_f_file_stream_write_
#ifndef _di_f_file_stream_write_block_
f_status_t f_file_stream_write_block(const f_file_t file, const f_string_static_t buffer, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
-
- if (!file.stream) return F_status_set_error(F_file_closed);
- if (!buffer.used) {
+ if (!file.stream || !buffer.used || !file.size_write) {
if (written) {
*written = 0;
}
- return F_data_not;
- }
-
- f_array_length_t write_max = file.size_write;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
+ return file.stream ? F_data_not : F_stream_not;
}
- f_status_t status = F_none;
+ const f_array_length_t write_max = file.size_write > buffer.used ? buffer.used : file.size_write;
if (written) {
- status = private_f_file_stream_write_until(file, buffer, write_max, written);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, written);
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- status = private_f_file_stream_write_until(file, buffer, write_max, &written_local);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, &written_local);
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_stream_write_block_
#ifndef _di_f_file_stream_write_until_
f_status_t f_file_stream_write_until(const f_file_t file, const f_string_static_t buffer, const f_array_length_t total, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
-
- if (!buffer.used || !total) {
+ if (!file.stream || !buffer.used || !total || !file.size_write) {
if (written) {
*written = 0;
}
- return F_data_not;
+ return file.stream ? F_data_not : F_stream_not;
}
- f_array_length_t write_max = total;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
- }
-
- f_status_t status = F_none;
+ const f_array_length_t write_max = total > buffer.used ? buffer.used : total;
if (written) {
- status = private_f_file_stream_write_until(file, buffer, write_max, written);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, write_max, written);
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_stream_write_until_
#ifndef _di_f_file_stream_write_range_
f_status_t f_file_stream_write_range(const f_file_t file, const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
- if (!file.stream) return F_status_set_error(F_file_closed);
-
- if (!buffer.used || range.start > range.stop || range.start >= buffer.used) {
+ if (!file.stream || !buffer.used || range.start > range.stop || range.start >= buffer.used || !file.size_write) {
if (written) {
*written = 0;
}
- return F_data_not;
+ return file.stream ? F_data_not : F_stream_not;
}
- const f_array_length_t total = (range.stop - range.start) + 1;
- f_array_length_t write_max = total;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
- }
-
- f_status_t status = F_none;
+ const f_array_length_t write_max = (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1;
if (written) {
const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize(buffer.string + range.start, 0, buffer.used - range.start);
- status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, written);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, written);
if (status == F_none) {
- if (range.start + *written == buffer.used) return F_none_stop;
- if (range.start + *written == total) return F_none_eos;
+ if (range.start + *written == buffer.used) return F_none_eos;
+ if (range.start + *written == write_max) return F_none_stop;
}
}
else {
const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize(buffer.string + range.start, 0, buffer.used - range.start);
f_array_length_t written_local = 0;
- status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, &written_local);
+ const f_status_t status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, &written_local);
if (status == F_none) {
if (range.start + written_local == buffer.used) return F_none_eos;
- if (range.start + written_local == total) return F_none_stop;
+ if (range.start + written_local == write_max) return F_none_stop;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_stream_write_range_
if (!path.used) return F_data_not;
- f_status_t status = F_none;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
- status = private_f_file_stat(path, dereference, &stat_file);
+ {
+ const f_status_t status = private_f_file_stat(path, dereference, &stat_file);
- if (F_status_set_fine(status) == F_file_found_not) return private_f_file_create(path, mode, dereference);
- if (F_status_is_error(status)) return status;
+ if (F_status_set_fine(status) == F_file_found_not) {
+ return private_f_file_create(path, mode, dereference);
+ }
+
+ if (F_status_is_error(status)) return status;
+ }
if (utimensat(F_file_at_current_working_d, path.string, 0, dereference ? 0 : F_file_at_symlink_follow_no_d) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
#endif // _di_f_file_touch_
#ifndef _di_f_file_touch_at_
- f_status_t f_file_touch_at(const int at_id, const f_string_static_t path, const mode_t mode, const int flag) {
+ f_status_t f_file_touch_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const int flag) {
+ if (directory.id == -1) return F_stream_not;
if (!path.used) return F_data_not;
- f_status_t status = F_none;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
- status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ {
+ const f_status_t status = private_f_file_stat_at(directory, path, flag, &stat_file);
- if (F_status_set_fine(status) == F_file_found_not) return private_f_file_create_at(at_id, path, mode, F_false);
- if (F_status_is_error(status)) return status;
+ if (F_status_set_fine(status) == F_file_found_not) {
+ return private_f_file_create_at(directory, path, mode, F_false);
+ }
+
+ if (F_status_is_error(status)) return status;
+ }
- if (utimensat(at_id, path.string, 0, flag) < 0) {
+ if (utimensat(directory.id, path.string, 0, flag) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
#endif // _di_f_file_type_
#ifndef _di_f_file_type_at_
- f_status_t f_file_type_at(const int at_id, const f_string_static_t path, const int flag, int * const type) {
+ f_status_t f_file_type_at(const f_file_t directory, const f_string_static_t path, const int flag, int * const type) {
#ifndef _di_level_0_parameter_checking_
if (!type) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (directory.id == -1) return F_stream_not;
if (!path.used) return F_data_not;
struct stat stat_file;
memset(&stat_file, 0, sizeof(struct stat));
{
- const f_status_t status = private_f_file_stat_at(at_id, path, flag, &stat_file);
+ const f_status_t status = private_f_file_stat_at(directory, path, flag, &stat_file);
if (F_status_is_error(status)) return status;
}
#ifndef _di_f_file_write_
f_status_t f_file_write(const f_file_t file, const f_string_static_t buffer, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
-
- if (file.id == -1) return F_status_set_error(F_file_closed);
- if (!buffer.used) {
+ if (file.id == -1 || !buffer.used || !file.size_write) {
if (written) *written = 0;
- return F_data_not;
+ return file.id == -1 ? F_stream_not : F_data_not;
}
- f_status_t status = F_none;
-
if (written) {
- status = private_f_file_write_until(file, buffer, buffer.used, written);
+ const f_status_t status = private_f_file_write_until(file, buffer, buffer.used, written);
+ if (F_status_is_error(status)) return status;
if (status == F_none && *written == buffer.used) return F_none_eos;
}
else {
f_array_length_t written_local = 0;
- status = private_f_file_write_until(file, buffer, buffer.used, &written_local);
+ const f_status_t status = private_f_file_write_until(file, buffer, buffer.used, &written_local);
+ if (F_status_is_error(status)) return status;
if (status == F_none && written_local == buffer.used) return F_none_eos;
}
- return status;
+ return F_none;
}
#endif // _di_f_file_write_
#ifndef _di_f_file_write_block_
f_status_t f_file_write_block(const f_file_t file, const f_string_static_t buffer, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
- if (file.id == -1) return F_status_set_error(F_file_closed);
-
- if (!buffer.used) {
+ if (file.id == -1 || !buffer.used || !file.size_write) {
if (written) *written = 0;
- return F_data_not;
+ return file.id == -1 ? F_stream_not : F_data_not;
}
- f_array_length_t write_max = file.size_write;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
- }
-
- f_status_t status = F_none;
+ const f_array_length_t write_max = file.size_write > buffer.used ? buffer.used : file.size_write;
if (written) {
- status = private_f_file_write_until(file, buffer, write_max, written);
+ const f_status_t status = private_f_file_write_until(file, buffer, write_max, written);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- status = private_f_file_write_until(file, buffer, write_max, &written_local);
+ const f_status_t status = private_f_file_write_until(file, buffer, write_max, &written_local);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_write_block_
#ifndef _di_f_file_write_until_
f_status_t f_file_write_until(const f_file_t file, const f_string_static_t buffer, const f_array_length_t total, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
-
- if (file.id == -1) return F_status_set_error(F_file_closed);
- if (!buffer.used || !total) {
+ if (file.id == -1 || !buffer.used || !total || !file.size_write) {
if (written) *written = 0;
- return F_data_not;
- }
-
- f_array_length_t write_max = total;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
+ return file.id == -1 ? F_stream_not : F_data_not;
}
- f_status_t status = F_none;
+ const f_array_length_t write_max = total > buffer.used ? buffer.used : total;
if (written) {
- status = private_f_file_write_until(file, buffer, write_max, written);
+ const f_status_t status = private_f_file_write_until(file, buffer, write_max, written);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
if (*written == buffer.used) return F_none_eos;
else {
f_array_length_t written_local = 0;
- status = private_f_file_write_until(file, buffer, buffer.used, &written_local);
+ const f_status_t status = private_f_file_write_until(file, buffer, buffer.used, &written_local);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
if (written_local == buffer.used) return F_none_eos;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_write_until_
#ifndef _di_f_file_write_range_
f_status_t f_file_write_range(const f_file_t file, const f_string_static_t buffer, const f_string_range_t range, f_array_length_t * const written) {
- #ifndef _di_level_0_parameter_checking_
- if (!file.size_write) return F_status_set_error(F_parameter);
- #endif // _di_level_0_parameter_checking_
-
- if (file.id == -1) return F_status_set_error(F_file_closed);
- if (!buffer.used || range.start > range.stop || range.start >= buffer.used) {
+ if (file.id == -1 || !buffer.used || range.start > range.stop || range.start >= buffer.used || !file.size_write) {
if (written) {
*written = 0;
}
- return F_data_not;
+ return file.id == -1 ? F_stream_not : F_data_not;
}
- const f_array_length_t total = (range.stop - range.start) + 1;
- f_array_length_t write_max = total;
-
- if (write_max > buffer.used) {
- write_max = buffer.used;
- }
-
- f_status_t status = F_none;
+ const f_array_length_t write_max = (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1;
if (written) {
const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize(buffer.string + range.start, 0, buffer.used - range.start);
- status = private_f_file_write_until(file, buffer_adjusted, write_max, written);
+ const f_status_t status = private_f_file_write_until(file, buffer_adjusted, write_max, written);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
- if (range.start + *written == buffer.used) return F_none_stop;
- if (range.start + *written == total) return F_none_eos;
+ if (range.start + *written == buffer.used) return F_none_eos;
+ if (range.start + *written == write_max) return F_none_stop;
}
}
else {
const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize(buffer.string + range.start, 0, buffer.used - range.start);
f_array_length_t written_local = 0;
- status = private_f_file_write_until(file, buffer_adjusted, write_max, &written_local);
+ const f_status_t status = private_f_file_write_until(file, buffer_adjusted, write_max, &written_local);
+ if (F_status_is_error(status)) return status;
if (status == F_none) {
if (range.start + written_local == buffer.used) return F_none_eos;
- if (range.start + written_local == total) return F_none_stop;
+ if (range.start + written_local == write_max) return F_none_stop;
}
}
- return status;
+ return F_none;
}
#endif // _di_f_file_write_range_
* Do not use this to check file access before immediately attempting to open a file due to the possibility that the permissions change between this call and the open call.
* Instead, use the f_file_open() directly.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* F_true if requested access is allowed.
* F_false if requested access is denied.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see faccessat()
*/
#ifndef _di_f_file_access_at_
- extern f_status_t f_file_access_at(const int at_id, const f_string_static_t path, const int mode, const int flag);
+ extern f_status_t f_file_access_at(const f_file_t directory, const f_string_static_t path, const int mode, const int flag);
#endif // _di_f_file_access_at_
/**
*
* Will not flush before closing.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_file_close (with error bit) if fclose() failed for any other reason.
* F_file_descriptor (with error bit) if file descriptor is invalid.
* @see fclose()
*/
#ifndef _di_f_file_close_
- extern f_status_t f_file_close(int * const id);
+ extern f_status_t f_file_close(f_file_t * const file);
#endif // _di_f_file_close_
/**
- * Close an open file.
- *
- * Will flush before closing.
- *
- * @param id
- * The file descriptor.
- *
- * @return
- * F_none on success.
- *
- * F_file_close (with error bit) if fclose() failed for any other reason.
- * F_file_descriptor (with error bit) if file descriptor is invalid.
- * F_file_synchronize (with error bit) on flush failure.
- * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted.
- * F_input_output (with error bit) on I/O error.
- * F_interrupt (with error bit) when program received an interrupt signal, halting operation.
- * F_space_not (with error bit) if file system is out of space (or file system quota is reached).
- *
- * @see fclose()
- */
-#ifndef _di_f_file_close_flush_
- extern f_status_t f_file_close_flush(int * const id);
-#endif // _di_f_file_close_flush_
-
-/**
* Copy a file.
*
* The paths must not contain NULL except for the terminating NULL.
*
* The file will not be open after calling this.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_busy (with error bit) if file system is too busy to perform write.
* @see openat()
*/
#ifndef _di_f_file_create_at_
- extern f_status_t f_file_create_at(const int at_id, const f_string_static_t path, const mode_t mode, const bool exclusive);
+ extern f_status_t f_file_create_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const bool exclusive);
#endif // _di_f_file_create_at_
/**
*
* Warning: Due to the current status of POSIX and LINUX in regards to major and minor devices, this utilizes the non-POSI makedev() function.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see mknodat()
*/
#ifndef _di_f_file_create_device_at_
- extern f_status_t f_file_create_device_at(const int at_id, const f_string_static_t path, const mode_t mode, const unsigned int major, const unsigned int minor);
+ extern f_status_t f_file_create_device_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const unsigned int major, const unsigned int minor);
#endif // _di_f_file_create_device_at_
/**
/**
* Create a fifo based on the given path and file mode.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see mkfifoat()
*/
#ifndef _di_f_file_create_fifo_at_
- extern f_status_t f_file_create_fifo_at(const int at_id, const f_string_static_t path, const mode_t mode);
+ extern f_status_t f_file_create_fifo_at(const f_file_t directory, const f_string_static_t path, const mode_t mode);
#endif // _di_f_file_create_fifo_at_
/**
/**
* Create a node based on the given path and file mode.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see mknodat()
*/
#ifndef _di_f_file_create_node_at_
- extern f_status_t f_file_create_node_at(const int at_id, const f_string_static_t path, const mode_t mode, const dev_t device);
+ extern f_status_t f_file_create_node_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const dev_t device);
#endif // _di_f_file_create_node_at_
/**
* Identify the file descriptor of a valid file stream.
*
* @param file
- * The file stream to get descriptor of.
+ * The file.
*
* @return
* F_none is returned on success.
+ * F_stream_not if file.stream is NULL.
*
* F_parameter (with error bit) if a parameter is invalid.
* F_stream_not (with error bit) if file is not a valid stream.
* This does not require access on the file itself.
* This only requires access via the parent directories in the path.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param flag
* F_true if file exists.
* F_false if file does not exist.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see fstatat()
*/
#ifndef _di_f_file_exists_at_
- extern f_status_t f_file_exists_at(const int at_id, const f_string_static_t path, const int flag);
+ extern f_status_t f_file_exists_at(const f_file_t directory, const f_string_static_t path, const int flag);
#endif // _di_f_file_exists_at_
/**
* Flush the file.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
*
* @return
* F_none is returned on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_file_descriptor (with error bit) if file descriptor is invalid.
* F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted.
* @see fsync()
*/
#ifndef _di_f_file_flush_
- extern f_status_t f_file_flush(const int id);
+ extern f_status_t f_file_flush(const f_file_t id);
#endif // _di_f_file_flush_
/**
* @return
* F_true if path was found and path is type.
* F_false if path was found and path is not type.
- * F_file_found_not if the path was not found.
* F_data_not if path.used is 0.
+ * F_file_found_not if the path was not found.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_not (with error bit) on invalid directory.
/**
* Identify whether or not a file exists at the given path within the parent directory and if that file is a specific type.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param type
* @return
* F_true if path was found and path is type.
* F_false if path was found and path is not type.
- * F_file_found_not if the path was not found.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
+ * F_file_found_not if the path was not found.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see fstatat()
*/
#ifndef _di_f_file_is_at_
- extern f_status_t f_file_is_at(const int at_id, const f_string_static_t path, const int type, const int flag);
+ extern f_status_t f_file_is_at(const f_file_t directory, const f_string_static_t path, const int type, const int flag);
#endif // _di_f_file_is_at_
/**
* This will not replace existing files/links.
* This does not validate the existence of target.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which point path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param target
* A path that the link points to.
* @param point
* @return
* F_none on success.
* F_data_not if target.used or point.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_busy (with error bit) if file system is too busy to perform write.
* @see symlinkat()
*/
#ifndef _di_f_file_link_at_
- extern f_status_t f_file_link_at(const int at_id, const f_string_static_t target, const f_string_static_t point);
+ extern f_status_t f_file_link_at(const f_file_t directory, const f_string_static_t target, const f_string_static_t point);
#endif // _di_f_file_link_at_
/**
*
* This will not replace existing files/links.
*
- * @param at_id_target
- * The parent directory, as an open directory file descriptor, in which target path is relative to.
- * @param at_id_point
- * The parent directory, as an open directory file descriptor, in which point path is relative to.
+ * @param file_target
+ * The parent directory, via an open directory file descriptor, in which target path is relative to.
+ * @param file_point
+ * The parent directory, via an open directory file descriptor, in which point path is relative to.
* @param target
* A path that the link points to.
* @param point
* @return
* F_none on success.
* F_data_not if target.used or point.used is 0.
+ * F_file_descriptor_not if either file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_buffer (with error bit) if the buffer is invalid.
* @see linkat()
*/
#ifndef _di_f_file_link_hard_at_
- extern f_status_t f_file_link_hard_at(const int at_id_target, const int at_id_point, const f_string_static_t target, const f_string_static_t point, const int flag);
+ extern f_status_t f_file_link_hard_at(const f_file_t file_target, const f_file_t file_point, const f_string_static_t target, const f_string_static_t point, const int flag);
#endif // _di_f_file_link_hard_at_
/**
* This does not require access on the file itself.
* This only requires access via the parent directories in the path.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param flag
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_buffer (with error bit) if the buffer is invalid.
* @see f_string_dynamic_terminate_after()
*/
#ifndef _di_f_file_link_read_at_
- extern f_status_t f_file_link_read_at(const int at_id, const f_string_static_t path, const int flag, f_string_dynamic_t * const target);
+ extern f_status_t f_file_link_read_at(const f_file_t directory, const f_string_static_t path, const int flag, f_string_dynamic_t * const target);
#endif // _di_f_file_link_read_at_
/**
/**
* Get the current file mode as an f_file_mode_t.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param flag
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see fstatat()
*/
#ifndef _di_f_file_mode_read_at_
- extern f_status_t f_file_mode_read_at(const int at_id, const f_string_static_t path, const int flag, mode_t * const mode);
+ extern f_status_t f_file_mode_read_at(const f_file_t directory, const f_string_static_t path, const int flag, mode_t * const mode);
#endif // _di_f_file_mode_read_at_
/**
* This does not set mode based on umask(), be sure to apply umask if so desired.
* (such as: mode & ~mask).
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_access_mode (with error bit) if the current user does not have access to assign the file mode.
* @see fchmodat()
*/
#ifndef _di_f_file_mode_set_at_
- extern f_status_t f_file_mode_set_at(const int at_id, const f_string_static_t path, const mode_t mode);
+ extern f_status_t f_file_mode_set_at(const f_file_t directory, const f_string_static_t path, const mode_t mode);
#endif // _di_f_file_mode_set_at_
/**
* This will open the file as a file descriptor.
* This does not open a file stream.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @return
* F_none on success.
* F_data_not if path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_directory_descriptor (with error bit) for bad directory descriptor for at_id.
* F_file_found_not (with error bit) if the file was not found.
* @see openat()
*/
#ifndef _di_f_file_open_at_
- extern f_status_t f_file_open_at(const int at_id, const f_string_static_t path, const mode_t mode, f_file_t * const file);
+ extern f_status_t f_file_open_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, f_file_t * const file);
#endif // _di_f_file_open_at_
/**
*
* @param file
* The file to read.
- * The file must already be open.
* @param buffer
* The buffer the file is being read into.
* The contents of the file is appended into this buffer.
*
* @return
* F_none_eof on success and EOF was reached.
+ * F_file_descriptor_not if file.id is -1.
*
* 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.
*
* @param file
* The file to read.
- * The file must already be open.
* @param buffer
* The buffer the file is being read into.
* The contents of the file is appended into this buffer.
* @return
* F_none on success.
* F_none_eof on success and EOF was reached.
+ * F_file_descriptor_not if file.id is -1.
*
* 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.
*
* @param file
* The file to read.
- * The file must already be open.
* @param total
* The total bytes to read, unless EOF is reached first.
* @param buffer
* 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_file_descriptor_not if file.id is -1.
*
* 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.
/**
* Remove a file.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param flag
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_busy (with error bit) if file is busy.
* @see unlinkat()
*/
#ifndef _di_f_file_remove_at_
- extern f_status_t f_file_remove_at(const int at_id, const f_string_static_t path, const int flag);
+ extern f_status_t f_file_remove_at(const f_file_t directory, const f_string_static_t path, const int flag);
#endif // _di_f_file_remove_at_
/**
* If destination already exists, then according to rename(), destination will be atomically replaced.
* Which, if destination is a directory, then that directory must either not exist or be empty.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which the source is relative to.
- * @param to_id
- * The parent directory, as an open directory file descriptor, in which the destination is relative to.
+ * @param directory_source
+ * The parent directory, via an open directory file descriptor, in which the source path is relative to.
+ * @param directory_destination
+ * The parent directory, via an open directory file descriptor, in which the destination path is relative to.
* @param source
* The path to the file to copy from.
* @param destination
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_buffer (with error bit) if the buffer is invalid.
* @see renameat()
*/
#ifndef _di_f_file_rename_at_
- extern f_status_t f_file_rename_at(const int at_id, const int to_id, const f_string_static_t source, const f_string_static_t destination, const unsigned int flag);
+ extern f_status_t f_file_rename_at(const f_file_t directory_source, const f_file_t directory_destination, const f_string_static_t source, const f_string_static_t destination, const unsigned int flag);
#endif // _di_f_file_rename_at_
/**
/**
* Change owner and/or group of a given file at the specified path.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param uid
* @return
* F_none on success.
* F_data_not if either both uid and gid are -1 or path.used is 0.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_access_group (with error bit) if the current user does not have access to assign the specified group.
* @see fchownat()
*/
#ifndef _di_f_file_role_change_at_
- extern f_status_t f_file_role_change_at(const int at_id, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag);
+ extern f_status_t f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag);
#endif // _di_f_file_role_change_at_
/**
* Given an open file descriptor, seek to a given location.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
* @param whence
* One of: SEEK_SET, SEEK_CUR, SEEK_END, SEEK_DATA, SEEK_HOLE.
* @param offset
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_bound_not (with error bit) if SEEK_DATA or SEEK_HOLE is specified as whence and offset is beyond the end of file.
* F_file_descriptor (with error bit) if the file descriptor is invalid.
* @see lseek
*/
#ifndef _di_f_file_seek_
- extern f_status_t f_file_seek(const int id, const int whence, const off_t offset, off_t * const seeked);
+ extern f_status_t f_file_seek(const f_file_t file, const int whence, const off_t offset, off_t * const seeked);
#endif // _di_f_file_seek_
/**
/**
* Read the size of file.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path to the file.
* @param dereference
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* F_number_overflow (with error bit) on overflow error.
* F_parameter (with error bit) if a parameter is invalid.
*
+ * F_file_stat (with error bit) on any other error.
+ *
* @see f_file_stat_at()
*/
#ifndef _di_f_file_size_at_
- extern f_status_t f_file_size_at(const int at_id, const f_string_static_t path, const bool dereference, off_t * const size);
+ extern f_status_t f_file_size_at(const f_file_t directory, const f_string_static_t path, const bool dereference, off_t * const size);
#endif // _di_f_file_size_at_
/**
* Read size of a file relative to the path represented by the file descriptor id.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
* @param size
* This gets set to the size of the file.
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_not (with error bit) on invalid directory.
* F_number_overflow (with error bit) on overflow error.
* F_parameter (with error bit) if a parameter is invalid.
*
+ * F_file_stat (with error bit) on any other error.
+ *
* @see f_file_stat_by_id()
*/
#ifndef _di_f_file_size_by_id_
- extern f_status_t f_file_size_by_id(const int id, off_t * const size);
+ extern f_status_t f_file_size_by_id(const f_file_t file, off_t * const size);
#endif // _di_f_file_size_by_id_
/**
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_not (with error bit) on invalid directory.
* F_number_overflow (with error bit) on overflow error.
* F_parameter (with error bit) if a parameter is invalid.
*
+ * F_file_stat (with error bit) on any other error.
+ *
* @see stat()
*/
#ifndef _di_f_file_stat_
/**
* Read statistics of a file relative to the path represented by the file descriptor id.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path to the file.
* @param flag
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* F_number_overflow (with error bit) on overflow error.
* F_parameter (with error bit) if a parameter is invalid.
*
+ * F_file_stat (with error bit) on any other error.
+ *
* @see fstatat()
*/
#ifndef _di_f_file_stat_at_
- extern f_status_t f_file_stat_at(const int at_id, const f_string_static_t path, const int flag, struct stat * const stat_file);
+ extern f_status_t f_file_stat_at(const f_file_t directory, const f_string_static_t path, const int flag, struct stat * const stat_file);
#endif // _di_f_file_stat_at_
/**
* Read statistics of a file using a file descriptor id.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
* @param stat_file
* The statistics read.
*
* @return
* F_none on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_not (with error bit) on invalid directory.
* F_number_overflow (with error bit) on overflow error.
* F_parameter (with error bit) if a parameter is invalid.
*
+ * F_file_stat (with error bit) on any other error.
+ *
* @see fstat()
*/
#ifndef _di_f_file_stat_by_id_
- extern f_status_t f_file_stat_by_id(const int id, struct stat * const stat_file);
+ extern f_status_t f_file_stat_by_id(const f_file_t file, struct stat * const stat_file);
#endif // _di_f_file_stat_by_id_
/**
* Close an open file stream.
*
- * @param flush
- * If TRUE, will explicitly flush all unwritten data in any buffers to the file.
- * If FALSE, will not explicitly flush unwritten data.
- *
- * If TRUE and flush fails, then this will still attempt to close the stream.
* @param file
* The file information.
- * The file.stream is set to 0, on success or on failure.
- * The file.id is set to 0, on success or on failure.
+ * The file.stream is set to NULL, on both success or on failure.
*
* @return
- * F_none is returned on success.
+ * F_none on success.
+ * F_stream_not if file.stream is NULL.
*
* F_access_denied (with error bit) on access denied.
* F_block (with error bit) if the action would block and non-blocking is set on the stream.
* F_buffer (with error bit) if the buffer is invalid.
* F_deadlock (with error bit) if operation would cause a deadlock.
- * F_file_close (with error bit) if fclose() failed for any other reason.
* F_file_descriptor (with error bit) if file descriptor is invalid.
* F_file_descriptor_max (with error bit) if max file descriptors is reached.
* F_file_overflow (with error bit) if the write exceeds some implementation defined maximum file size.
- * F_file_synchronize (with error bit) on flush failure.
* F_file_type_not_directory (with error bit) if F_NOTIFY was specified and file.id is not a directory.
- * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted.
* F_input_output (with error bit) on I/O error.
* F_interrupt (with error bit) when program received an interrupt signal, halting operation.
* F_lock (with error bit) if failed to lock, such as lock table is full or too many open segments.
* F_space_not (with error bit) if file system is out of space (or file system quota is reached).
* F_socket_not (with error bit) if the datagram socket in which a peer has not been set (for socket related streams).
*
- * @see close()
+ * F_file_close (with error bit) on any other error.
+ *
* @see fclose()
- * @see fflush()
*/
#ifndef _di_f_file_stream_close_
- extern f_status_t f_file_stream_close(const bool flush, f_file_t * const file);
+ extern f_status_t f_file_stream_close(f_file_t * const file);
#endif // _di_f_file_stream_close_
/**
+ * Flush a file stream.
+ *
+ * @param file
+ * The file information.
+ * The file.id is updated with the file descriptor, if necessary and able.
+ *
+ * @return
+ * F_none is returned on success.
+ * F_stream_not if file.stream is NULL.
+ * F_file_descriptor_not if file.id is -1.
+ *
+ * F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
+ * F_buffer (with error bit) if the buffer is invalid.
+ * F_file_closed (with error bit) if file is not open.
+ * F_file_descriptor (with error bit) if the file descriptor is invalid.
+ * F_file_type_directory (with error bit) if file descriptor represents a directory.
+ * F_input_output (with error bit) on I/O error.
+ * F_interrupt (with error bit) if interrupt was received.
+ *
+ * F_file_synchronize (with error bit) on any other error.
+ *
+ * @see fflush()
+ */
+#ifndef _di_f_file_stream_flush_
+ extern f_status_t f_file_stream_flush(f_file_t * const file);
+#endif // _di_f_file_stream_flush_
+
+/**
* Open a file stream.
*
* The file descriptor is retrieved on success, if necessary and able.
* F_supported_not (with error bit) fo unsupported file types.
* F_failure (with error bit) for any other error.
*
- * @see fileno()
* @see fopen()
*/
#ifndef _di_f_file_stream_open_
* This should match the modes used to open the file descriptor as it relates to the stream modes.
* @param file
* The file with a valid file descriptor (file.id).
- * THe file stream (file.stream) is updated on success, but may be set to NULL on error.
*
* @return
* F_none is returned on success.
+ * F_file_descriptor_not if file.id is -1.
*
* F_access_denied (with error bit) on access denied.
* F_block (with error bit) if the action would block and non-blocking is set on the stream.
*
* @param file
* The file to read.
- * The file must already be open.
* The file.size_read represents the amount to process at a given time.
* @param buffer
* The buffer the file is being read into.
*
* @return
* F_none_eof on success and EOF was reached.
+ * F_stream_not if file.stream is NULL.
*
* 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.
*
* @param file
* The file to read.
- * The file must already be open.
* The file.size_read represents the amount to process at a given time.
* @param buffer
* The buffer the file is being read into.
* @return
* F_none on success.
* F_none_eof on success and EOF was reached.
+ * F_stream_not if file.stream is NULL.
*
* F_error (with error bit) if the file is already in the error state at the start of this function.
* F_file_closed (with error bit) if the file is closed.
*
* @param file
* The file to read.
- * The file must already be open.
* The file.size_read represents the amount to process at a given time.
* @param total
* The total bytes to read, unless EOF is reached first.
* @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_stream_not if file.stream is NULL.
*
* F_error (with error bit) if the file is already in the error state at the start of this function.
* F_file_closed (with error bit) if the file is closed.
* @param file
* The file information.
* The file.stream is updated, if necessary.
- * The file.id is updated with the file descriptor, if necessary and able.
*
* @return
* F_none is returned on success.
* @param buffer
* The buffer to write to the file.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
* F_none_eof when the file stream is at the end of the file.
* F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
* F_data_not on success but buffer.used is 0.
+ * F_stream_not if file.stream is NULL.
*
* F_file_write (with error bit) on error during file write.
* F_parameter (with error bit) if a parameter is invalid.
* @param buffer
* The buffer to write to the file.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
* F_none_eof when the file stream is at the end of the file.
* F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
* F_data_not on success but buffer.used is 0.
+ * F_stream_not if file.stream is NULL.
*
* F_file_write (with error bit) on error during file write.
* F_parameter (with error bit) if a parameter is invalid.
* @param total
* The total bytes to write, unless end of buffer is reached first.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use..
*
* @return
* F_none on success.
* F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
* F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
* F_data_not on success but either buffer.used or total is 0.
+ * F_stream_not if file.stream is NULL.
*
* F_file_write (with error bit) on error during file write.
* F_parameter (with error bit) if a parameter is invalid.
*
* @param file
* The file to write to.
- * The file must already be open.
* The file.size_write represents the amount to process at a given time.
* @param buffer
* The buffer to write to the file.
* @param range
* An inclusive start an stop range within the buffer to read.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
* F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
* F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
+ * F_stream_not if file.stream is NULL.
*
* F_file_write (with error bit) on error during file write.
* F_parameter (with error bit) if a parameter is invalid.
*
* When the file is created, it is created as a regular file.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* F_none on success.
* F_access_denied (with error bit) on access denied.
* F_buffer (with error bit) if the buffer is invalid.
+ * F_stream_not if file.stream is NULL.
*
* F_busy (with error bit) if file system is too busy to perform write.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see utimensat()
*/
#ifndef _di_f_file_touch_at_
- extern f_status_t f_file_touch_at(const int at_id, const f_string_static_t path, const mode_t mode, const int flag);
+ extern f_status_t f_file_touch_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const int flag);
#endif // _di_f_file_touch_at_
/**
/**
* Get the file type for the file at the given path within the parent directory.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param flag
* @return
* F_none if path was found and and the type was loaded in the type parameter.
* F_file_found_not if the path was not found.
+ * F_stream_not if file.stream is NULL.
*
* F_access_denied (with error bit) if access to the file was denied.
* F_directory_descriptor (with error bit) when at_id is not a valid file descriptor (at_id must point to a directory).
* @see fstatat()
*/
#ifndef _di_f_file_type_at_
- extern f_status_t f_file_type_at(const int at_id, const f_string_static_t path, const int flag, int * const type);
+ extern f_status_t f_file_type_at(const f_file_t directory, const f_string_static_t path, const int flag, int * const type);
#endif // _di_f_file_type_at_
/**
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The buffer to write to the file.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
- * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- * F_data_not if buffer.used is 0.
+ * F_none_eos on success and wrote up to buffer.used.
+ * F_data_not if buffer.used is 0 or range.start > range.stop.
+ * F_stream_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The buffer to write to the file.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
- * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- * F_data_not if buffer.used is 0.
+ * F_none_stop on success and wrote up to stop point.
+ * F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
+ * F_data_not if buffer.used is 0 or range.start > range.stop.
+ * F_stream_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The buffer to write to the file.
* @param total
* The total bytes to write, unless end of buffer is reached first.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
- * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
- * F_data_not if buffer.used is 0 or total is 0.
+ * F_none_stop on success and wrote up to stop point.
+ * F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
+ * F_data_not if buffer.used is 0 or range.start > range.stop.
+ * F_stream_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The buffer to write to the file.
* @param range
* An inclusive start an stop range within the buffer to read.
* @param written
- * The total bytes written.
- * Set pointer to 0 to not use.
+ * (optional) The total bytes written.
+ * Set to NULL to not use.
*
* @return
* F_none on success.
- * F_none_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- * F_none_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
+ * F_none_stop on success and wrote up to stop point.
+ * F_none_eos on success and wrote up to buffer.used (buffer.used is reached before stop point).
* F_data_not if buffer.used is 0 or range.start > range.stop.
+ * F_stream_not if file.id is -1.
*
* F_block (with error bit) if file descriptor is set to non-block and the write would result in a blocking operation.
* F_buffer (with error bit) if the buffer is invalid.
#define macro_f_file_t_initialize(stream, id, flag, read_size, write_size) { stream, id, flag, read_size, write_size }
#define macro_f_file_t_initialize2(stream, id, flag) { stream, id, flag, F_file_default_read_size_d, F_file_default_write_size_d }
+ #define macro_f_file_t_initialize_id(id) { 0, id, F_file_flag_read_only_d, F_file_default_read_size_d, F_file_default_write_size_d }
+ #define macro_f_file_t_initialize_stream(stream) { stream, -1, F_file_flag_read_only_d, F_file_default_read_size_d, F_file_default_write_size_d }
#define macro_f_file_t_clear(file) \
file.stream = 0; \
#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 * const id) {
+ f_status_t private_f_file_close(f_file_t * const file) {
- if (*id == -1) {
- return F_none;
- }
-
- if (flush) {
- private_f_file_flush(*id);
- }
-
- if (close(*id) < 0) {
+ if (close(file->id) < 0) {
// According to man pages, retrying close() after another close on error is invalid on Linux because Linux releases the descriptor before stages that cause failures.
if (errno != EBADF && errno != EINTR) {
- *id = -1;
+ file->id = -1;
}
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
return F_status_set_error(F_file_close);
}
- *id = -1;
+ file->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_flush(file_source);
+ private_f_file_close(&file_source);
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_flush(file_destination);
+ private_f_file_flush(file_source);
+
+ private_f_file_close(&file_destination);
+ private_f_file_close(&file_source);
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_flush(file_destination);
+ private_f_file_flush(file_source);
- if (size_read < 0) {
- return F_status_set_error(F_file_read);
- }
+ private_f_file_close(&file_destination);
+ private_f_file_close(&file_source);
+
+ if (size_read < 0) return F_status_set_error(F_file_read);
return F_none;
}
#endif // !defined(_di_f_file_copy_) || !defined(_di_f_file_clone_)
#if !defined(_di_f_file_copy_at_) || !defined(_di_f_file_clone_at_)
- f_status_t private_f_file_copy_content_at(const int at_id, const f_string_static_t source, const f_string_static_t destination, const f_number_unsigned_t size_block) {
+ f_status_t private_f_file_copy_content_at(const f_file_t directory, const f_string_static_t source, const f_string_static_t destination, const f_number_unsigned_t size_block) {
f_file_t file_source = f_file_t_initialize;
f_file_t file_destination = f_file_t_initialize;
file_source.flag = F_file_flag_read_only_d;
file_destination.flag = F_file_flag_write_only_d | F_file_flag_no_follow_d;
- f_status_t status = private_f_file_open_at(at_id, source, 0, &file_source);
+ f_status_t status = private_f_file_open_at(directory, source, 0, &file_source);
if (F_status_is_error(status)) return status;
- status = private_f_file_open_at(at_id, destination, 0, &file_destination);
+ status = private_f_file_open_at(directory, destination, 0, &file_destination);
if (F_status_is_error(status)) {
- private_f_file_close(F_true, &file_source.id);
+ private_f_file_flush(file_source);
+ private_f_file_close(&file_source);
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_flush(file_destination);
+ private_f_file_flush(file_source);
+
+ private_f_file_close(&file_destination);
+ private_f_file_close(&file_source);
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_flush(file_destination);
+ private_f_file_flush(file_source);
- if (size_read < 0) {
- return F_status_set_error(F_file_read);
- }
+ private_f_file_close(&file_destination);
+ private_f_file_close(&file_source);
+
+ if (size_read < 0) return F_status_set_error(F_file_read);
return F_none;
}
file.flag |= F_file_flag_exclusive_d;
}
- const f_status_t status = private_f_file_open(path, mode, &file);
+ f_status_t status = private_f_file_open(path, mode, &file);
+
+ if (F_status_is_error_not(status) && file.id != -1) {
+ private_f_file_flush(file);
- if (file.id != -1) {
- return private_f_file_close(F_true, &file.id);
+ status = private_f_file_close(&file);
}
- return status;
+ if (F_status_is_error(status)) return status;
+
+ return F_none;
}
#endif // !defined(_di_f_file_create_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_create_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_create_at(const int at_id, const f_string_static_t path, const mode_t mode, const bool exclusive) {
+ f_status_t private_f_file_create_at(const f_file_t file, const f_string_static_t path, const mode_t mode, const bool exclusive) {
- f_file_t file = f_file_t_initialize;
+ f_file_t file_internal = f_file_t_initialize;
- file.flag = F_file_flag_close_execute_d | F_file_flag_create_d | F_file_flag_write_only_d;
+ file_internal.flag = F_file_flag_close_execute_d | F_file_flag_create_d | F_file_flag_write_only_d;
if (exclusive) {
- file.flag |= F_file_flag_exclusive_d;
+ file_internal.flag |= F_file_flag_exclusive_d;
}
- const f_status_t status = private_f_file_open_at(at_id, path, mode, &file);
+ f_status_t status = private_f_file_open_at(file, path, mode, &file_internal);
+
+ if (F_status_is_error_not(status) && file_internal.id != -1) {
+ private_f_file_flush(file_internal);
- if (file.id != -1) {
- return private_f_file_close(F_true, &file.id);
+ status = private_f_file_close(&file_internal);
}
- return status;
+ if (F_status_is_error(status)) return status;
+
+ return F_none;
}
#endif // !defined(_di_f_file_create_at_) || !defined(_di_f_file_copy_at_)
#endif // !defined(_di_f_file_copy_)
#if !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_create_directory_at(const int at_id, const f_string_static_t path, const mode_t mode) {
+ f_status_t private_f_file_create_directory_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) {
- if (mkdirat(at_id, path.string, mode) < 0) {
+ if (mkdirat(directory.id, path.string, mode) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
if (errno == EEXIST) return F_status_set_error(F_file_found);
#endif // !defined(_di_f_file_create_fifo_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_create_fifo_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_create_fifo_at(const int at_id, const f_string_static_t path, const mode_t mode) {
+ f_status_t private_f_file_create_fifo_at(const f_file_t file, const f_string_static_t path, const mode_t mode) {
- if (mkfifoat(at_id, path.string, mode) < 0) {
+ if (mkfifoat(file.id, path.string, mode) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
#endif // !defined(_di_f_file_create_device_) || !defined(_di_f_file_create_node_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_create_device_at_) || !defined(_di_f_file_create_node_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_create_node_at(const int at_id, const f_string_static_t path, const mode_t mode, const dev_t device) {
+ f_status_t private_f_file_create_node_at(const f_file_t file, const f_string_static_t path, const mode_t mode, const dev_t device) {
- if (mknodat(at_id, path.string, mode, device) < 0) {
+ if (mknodat(file.id, path.string, mode, device) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
}
#endif // !defined(_di_f_file_create_device_at_) || !defined(_di_f_file_create_node_at_) || !defined(_di_f_file_copy_at_)
-#if !defined(_di_f_file_flush_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
- f_status_t private_f_file_flush(const int id) {
+#if !defined(_di_f_file_clone_at_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_copy_at_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_flush_) || !defined(_di_f_file_stream_close_)
+ f_status_t private_f_file_flush(const f_file_t file) {
- if (fsync(id) < 0) {
+ if (fsync(file.id) < 0) {
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
if (errno == EINVAL) return F_status_set_error(F_supported_not);
return F_none;
}
-#endif // !defined(_di_f_file_flush_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
+#endif // !defined(_di_f_file_clone_at_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_copy_at_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_flush_) || !defined(_di_f_file_stream_close_)
#if !defined(_di_f_file_link_) || !defined(_di_f_file_copy_)
f_status_t private_f_file_link(const f_string_static_t target, const f_string_static_t point) {
#endif // !defined(_di_f_file_link_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_link_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_link_at(const int at_id, const f_string_static_t target, const f_string_static_t point) {
+ f_status_t private_f_file_link_at(const f_file_t directory, const f_string_static_t target, const f_string_static_t point) {
- if (symlinkat(target.string, at_id, point.string) < 0) {
+ if (symlinkat(target.string, directory.id, point.string) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block);
#endif // !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) {
+ f_status_t private_f_file_link_read_at(const f_file_t file, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) {
target->used = 0;
if (F_status_is_error(status)) return status;
if (size) {
- if (readlinkat(at_id, path.string, target->string, size) < 0) {
+ if (readlinkat(file.id, path.string, target->string, size) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
#endif // !defined(_di_f_file_mode_set_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_mode_set_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_mode_set_at(const int at_id, const f_string_static_t path, const mode_t mode) {
+ f_status_t private_f_file_mode_set_at(const f_file_t file, const f_string_static_t path, const mode_t mode) {
- if (fchmodat(at_id, path.string, mode, 0) < 0) {
+ if (fchmodat(file.id, path.string, mode, 0) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
#endif // !defined(_di_f_file_open_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_copy_at_) || !defined(_di_f_file_clone_at_) || !defined(_di_f_file_open_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_open_at(const int at_id, const f_string_static_t path, const mode_t mode, f_file_t * const file) {
+ f_status_t private_f_file_open_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, f_file_t * const file) {
- file->id = openat(at_id, path.string, file->flag, mode);
+ file->id = openat(directory.id, path.string, file->flag, mode);
if (file->id == -1) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
#endif // !defined(_di_f_file_role_change_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_role_change_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_role_change_at(const int at_id, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
+ f_status_t private_f_file_role_change_at(const f_file_t file, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) {
int result = 0;
if (uid != -1) {
- result = fchownat(at_id, path.string, uid, -1, flag);
+ result = fchownat(file.id, path.string, uid, -1, flag);
if (result < 0 && errno == EPERM) {
return F_status_set_error(F_access_owner);
}
if (result == 0 && gid != -1) {
- result = fchownat(at_id, path.string, -1, gid, flag);
+ result = fchownat(file.id, path.string, -1, gid, flag);
if (result < 0 && errno == EPERM) {
return F_status_set_error(F_access_group);
#endif // !defined(_di_f_file_stat_) || !defined(_di_f_file_copy_)
#if !defined(_di_f_file_stat_at_) || !defined(_di_f_file_copy_at_)
- f_status_t private_f_file_stat_at(const int at_id, const f_string_static_t path, const int flag, struct stat * const file_stat) {
+ f_status_t private_f_file_stat_at(const f_file_t file, const f_string_static_t path, const int flag, struct stat * const file_stat) {
- if (fstatat(at_id, path.string, file_stat, flag) < 0) {
+ if (fstatat(file.id, path.string, file_stat, flag) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_directory_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
#endif // !defined(_di_f_file_stat_at_) || !defined(_di_f_file_copy_at_)
#if !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_)
- f_status_t private_f_file_stat_by_id(const int id, struct stat * const file_stat) {
+ f_status_t private_f_file_stat_by_id(const f_file_t file, struct stat * const file_stat) {
- if (fstat(id, file_stat) < 0) {
+ if (fstat(file.id, file_stat) < 0) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
if (errno == EFAULT) return F_status_set_error(F_buffer);
*
* Intended to be shared to each of the different implementation variations.
*
- * @param flush
- * If TRUE, then perform flush before closing.
- * If FALSE, then do not perform flush before closing.
- * @param id
- * The file descriptor.
- * The value gets set to -1.
+ * @param file
+ * The file to close.
+ * The file descriptor gets set to -1.
*
* @return
* F_none on success.
* F_space_not (with error bit) if file system is out of space (or file system quota is reached).
*
* @see close()
- * @see fsync()
*
* @see f_file_close()
* @see f_file_copy()
* @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 * const id) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_close(f_file_t * const file) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via 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.
* @see f_file_create_at()
*/
#if !defined(_di_f_file_create_at_)
- extern f_status_t private_f_file_create_at(const int at_id, const f_string_static_t path, const mode_t mode, const bool exclusive) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_create_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const bool exclusive) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_create_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The file descriptor in which the directory will be created within.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @see f_file_copy_at()
*/
#if !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_create_directory_at(const int at_id, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_create_directory_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_copy_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @see f_file_copy_at()
*/
#if !defined(_di_f_file_create_fifo_at_) || !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_create_fifo_at(const int at_id, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_create_fifo_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_create_fifo_at_) || !defined(_di_f_file_copy_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @see f_file_create_node_at()
*/
#if !defined(_di_f_file_create_device_at_) || !defined(_di_f_file_create_node_at_) || !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_create_node_at(const int at_id, const f_string_static_t path, const mode_t mode, const dev_t device) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_create_node_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, const dev_t device) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_create_device_at_) || !defined(_di_f_file_create_node_at_) || !defined(_di_f_file_copy_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file to flush.
*
* @return
* F_none is returned on success.
* F_supported_not (with error bit) if the file system or file type does not support flushing.
* F_file_synchronize (with error bit) on any other failure.
*
- * @see fsync()
- *
+ * @see f_file_clone_at()
* @see f_file_close()
* @see f_file_copy()
+ * @see f_file_copy_at()
+ * @see f_file_create()
+ * @see f_file_create_at()
* @see f_file_flush()
* @see f_file_stream_close()
*/
-#if !defined(_di_f_file_flush_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
- extern f_status_t private_f_file_flush(const int id) F_attribute_visibility_internal_d;
-#endif // !defined(_di_f_file_flush_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_stream_close_)
+#if !defined(_di_f_file_clone_at_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_copy_at_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_flush_) || !defined(_di_f_file_stream_close_)
+ extern f_status_t private_f_file_flush(const f_file_t file) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_file_clone_at_) || !defined(_di_f_file_close_) || !defined(_di_f_file_copy_) || !defined(_di_f_file_copy_at_) || !defined(_di_f_file_create_) || !defined(_di_f_file_create_at_) || !defined(_di_f_file_flush_) || !defined(_di_f_file_stream_close_)
/**
* Private implementation of f_file_link().
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which point point path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which point point path is relative to.
* @param target
* A path that the link points to.
* @param point
* @see f_file_link_at()
*/
#if !defined(_di_f_file_link_at_)
- extern f_status_t private_f_file_link_at(const int at_id, const f_string_static_t target, const f_string_static_t point) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_link_at(const f_file_t directory, const f_string_static_t target, const f_string_static_t point) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_link_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param size
* @see f_string_dynamic_terminate_after()
*/
#if !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_link_read_at(const int at_id, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_link_read_at(const f_file_t directory, const f_string_static_t path, const off_t size, f_string_dynamic_t * const target) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_link_read_at_) || !defined(_di_f_file_copy_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @see f_file_mode_set_at()
*/
#if !defined(_di_f_file_mode_set_at_)
- extern f_status_t private_f_file_mode_set_at(const int at_id, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_mode_set_at(const f_file_t directory, const f_string_static_t path, const mode_t mode) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_mode_set_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param mode
* @see f_file_copy_at()
*/
#if !defined(_di_f_file_copy_at_) || !defined(_di_f_file_clone_at_) || !defined(_di_f_file_open_at_) || !defined(_di_f_file_copy_at_)
- extern f_status_t private_f_file_open_at(const int at_id, const f_string_static_t path, const mode_t mode, f_file_t * const file) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_open_at(const f_file_t directory, const f_string_static_t path, const mode_t mode, f_file_t * const file) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_copy_at_) || !defined(_di_f_file_clone_at_) || !defined(_di_f_file_open_at_) || !defined(_di_f_file_copy_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param path
* The path file name.
* @param uid
* @see f_file_role_change_at()
*/
#if !defined(_di_f_file_role_change_at_)
- extern f_status_t private_f_file_role_change_at(const int at_id, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_role_change_at(const f_file_t directory, const f_string_static_t path, const uid_t uid, const gid_t gid, const int flag) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_role_change_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param at_id
- * The parent directory, as an open directory file descriptor, in which path is relative to.
+ * @param directory
+ * The parent directory, via an open directory file descriptor, in which path is relative to.
* @param file_name
* The name of the file.
* @param flag
* @see f_file_touch_at()
*/
#if !defined(_di_f_file_stat_at_) || !defined(_di_f_file_exists_at_) || !defined(_di_f_file_touch_at_)
- extern f_status_t private_f_file_stat_at(const int at_id, const f_string_static_t file_name, const int flag, struct stat * const file_stat) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_stat_at(const f_file_t directory, const f_string_static_t file_name, const int flag, struct stat * const file_stat) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_stat_at_) || !defined(_di_f_file_exists_at_) || !defined(_di_f_file_touch_at_)
/**
*
* Intended to be shared to each of the different implementation variations.
*
- * @param id
- * The file descriptor.
+ * @param file
+ * The file.
* @param file_stat
* The statistics read.
*
* @see f_file_stat_by_id()
*/
#if !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_)
- extern f_status_t private_f_file_stat_by_id(const int id, struct stat * const file_stat) F_attribute_visibility_internal_d;
+ extern f_status_t private_f_file_stat_by_id(const f_file_t file, struct stat * const file_stat) F_attribute_visibility_internal_d;
#endif // !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_)
/**
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The string to write to the file.
* @param total
*
* @param file
* The file to write to.
- * The file must already be open.
* @param buffer
* The string to write to the file.
* @param total
extern "C" {
#endif
-#ifndef _di_f_pipe_input_exists_
- f_status_t f_pipe_input_exists(void) {
-
- struct stat st_info;
-
- memset(&st_info, 0, sizeof(struct stat));
-
- if (fstat(F_type_descriptor_input_d, &st_info) != 0) {
- return F_status_set_error(F_file_stat);
- }
-
- if (S_ISFIFO(st_info.st_mode)) {
- return F_true;
- }
-
- return F_false;
- }
-#endif // _di_f_pipe_input_exists_
-
-#ifndef _di_f_pipe_warning_exists_
- f_status_t f_pipe_warning_exists(void) {
+#ifndef _di_f_pipe_error_exists_
+ f_status_t f_pipe_error_exists(void) {
struct stat st_info;
memset(&st_info, 0, sizeof(struct stat));
- if (fstat(F_type_descriptor_warning_d, &st_info) != 0) {
+ if (fstat(F_type_descriptor_error_d, &st_info) != 0) {
return F_status_set_error(F_file_stat);
}
- if (S_ISFIFO(st_info.st_mode)) {
- return F_true;
- }
-
- return F_false;
+ return S_ISFIFO(st_info.st_mode) ? F_true : F_false;
}
-#endif // _di_f_pipe_warning_exists_
+#endif // _di_f_pipe_error_exists_
-#ifndef _di_f_pipe_error_exists_
- f_status_t f_pipe_error_exists(void) {
+#ifndef _di_f_pipe_input_exists_
+ f_status_t f_pipe_input_exists(void) {
struct stat st_info;
memset(&st_info, 0, sizeof(struct stat));
- if (fstat(F_type_descriptor_error_d, &st_info) != 0) {
+ if (fstat(F_type_descriptor_input_d, &st_info) != 0) {
return F_status_set_error(F_file_stat);
}
- if (S_ISFIFO(st_info.st_mode)) {
- return F_true;
- }
-
- return F_false;
+ return S_ISFIFO(st_info.st_mode) ? F_true : F_false;
}
-#endif // _di_f_pipe_error_exists_
+#endif // _di_f_pipe_input_exists_
-#ifndef _di_f_pipe_debug_exists_
- f_status_t f_pipe_debug_exists(void) {
+#ifndef _di_f_pipe_output_exists_
+ f_status_t f_pipe_output_exists(void) {
struct stat st_info;
memset(&st_info, 0, sizeof(struct stat));
- if (fstat(F_type_descriptor_debug_d, &st_info) != 0) {
+ if (fstat(F_type_descriptor_output_d, &st_info) != 0) {
return F_status_set_error(F_file_stat);
}
- if (S_ISFIFO(st_info.st_mode)) {
- return F_true;
- }
-
- return F_false;
+ return S_ISFIFO(st_info.st_mode) ? F_true : F_false;
}
-#endif // _di_f_pipe_debug_exists_
+#endif // _di_f_pipe_output_exists_
#ifdef __cplusplus
} // extern "C"
#endif
/**
- * Identify whether or not the standard input pipe source contains piped data.
- *
- * @return
- * F_true if there is piped data.
- * F_false if there is no piped data.
- * F_file_stat (with error bit) on stat() error.
- *
- * @see fstat()
- */
-#ifndef _di_f_pipe_input_exists_
- extern f_status_t f_pipe_input_exists(void);
-#endif // _di_f_pipe_input_exists_
-
-/**
- * Identify whether or not the standard warning pipe contains piped data.
- *
- * For most systems, standard warning does not exist and instead maps to standard output.
+ * Identify whether or not the standard error pipe source contains piped data.
*
* @return
* F_true if there is piped data.
*
* @see fstat()
*/
-#ifndef _di_f_pipe_warning_exists_
- extern f_status_t f_pipe_warning_exists(void);
-#endif // _di_f_pipe_warning_exists_
+#ifndef _di_f_pipe_error_exists_
+ extern f_status_t f_pipe_error_exists(void);
+#endif // _di_f_pipe_error_exists_
/**
- * Identify whether or not the standard error pipe source contains piped data.
+ * Identify whether or not the standard input pipe source contains piped data.
*
* @return
* F_true if there is piped data.
*
* @see fstat()
*/
-#ifndef _di_f_pipe_error_exists_
- extern f_status_t f_pipe_error_exists(void);
-#endif // _di_f_pipe_error_exists_
+#ifndef _di_f_pipe_input_exists_
+ extern f_status_t f_pipe_input_exists(void);
+#endif // _di_f_pipe_input_exists_
/**
- * Identify whether or not the standard debug pipe source contains piped data.
+ * Identify whether or not the standard output pipe source contains piped data.
*
- * For most systems, standard debug does not exist and instead maps to standard output.
+ * For most systems, standard output does not exist and instead maps to standard output.
*
* @return
* F_false if there is no piped data.
*
* @see fstat()
*/
-#ifndef _di_f_pipe_debug_exists_
- extern f_status_t f_pipe_debug_exists(void);
-#endif // _di_f_pipe_debug_exists_
+#ifndef _di_f_pipe_output_exists_
+ extern f_status_t f_pipe_output_exists(void);
+#endif // _di_f_pipe_output_exists_
#ifdef __cplusplus
} // extern "C"
/**
* Standard Input/Output types.
*
- * For most systems, there is no standard warning nor is there a standard debug.
- * Therefore, these will map to standard output.
+ * F_type_*_d:
+ * - error: Standard error stream.
+ * - input: Standard input stream.
+ * - output: Standard output stream.
+ *
+ * F_type_descriptor_*_d:
+ * - error: Standard error file descriptor.
+ * - input: Standard input file descriptor.
+ * - output: Standard output file descriptor.
*/
#ifndef _di_f_type_input_output_
- #define F_type_debug_d stdout
- #define F_type_error_d stderr
- #define F_type_input_d stdin
- #define F_type_output_d stdout
- #define F_type_warning_d stdout
-
- #define F_type_descriptor_debug_d STDOUT_FILENO
- #define F_type_descriptor_error_d STDERR_FILENO
- #define F_type_descriptor_input_d STDIN_FILENO
- #define F_type_descriptor_output_d STDOUT_FILENO
- #define F_type_descriptor_warning_d STDOUT_FILENO
+ #define F_type_error_d stderr
+ #define F_type_input_d stdin
+ #define F_type_output_d stdout
+
+ #define F_type_descriptor_error_d STDERR_FILENO
+ #define F_type_descriptor_input_d STDIN_FILENO
+ #define F_type_descriptor_output_d STDOUT_FILENO
#endif // _di_f_type_input_output_
/**
if (F_status_is_error(status)) break;
fprintf(file.stream, "%d", id);
- fflush(file.stream);
- status = f_file_stream_close(F_true, &file);
+ f_file_stream_flush(&file);
+ status = f_file_stream_close(&file);
if (F_status_is_error(status)) break;
} // for
return F_status_set_error(F_directory_open);
}
- int parent_fd = dirfd(parent);
+ const f_file_t directory = macro_f_file_t_initialize_id(dirfd(parent));
- if (parent_fd < 0) {
+ if (directory.id < 0) {
closedir(parent);
if (errno == EINVAL) return F_status_set_error(F_directory_stream);
memset(&file_stat, 0, sizeof(struct stat));
- status = f_file_stat_at(parent_fd, name_directory, dereference ? 0 : AT_SYMLINK_NOFOLLOW, &file_stat);
+ status = f_file_stat_at(directory, name_directory, dereference ? 0 : AT_SYMLINK_NOFOLLOW, &file_stat);
if (F_status_is_error(status)) break;
mode = macro_f_file_type_get(file_stat.st_mode);
extern "C" {
#endif
-#ifndef _di_fl_print_t_
+#ifndef _di_fl_print_s_
const f_string_static_t fl_print_debug_s = macro_f_string_static_t_initialize(FL_print_debug_s, 0, FL_print_debug_s_length);
const f_string_static_t fl_print_error_s = macro_f_string_static_t_initialize(FL_print_error_s, 0, FL_print_error_s_length);
const f_string_static_t fl_print_warning_s = macro_f_string_static_t_initialize(FL_print_warning_s, 0, FL_print_warning_s_length);
-#endif // _di_fl_print_t_
+#endif // _di_fl_print_s_
#ifdef __cplusplus
} // extern "C"
#endif
/**
- * Structure for facilitating colored or other managed printing.
+ * Special print strings.
*
- * to: The file to print to.
- * verbosity: The verbosity mode.
- * prefix: An optional prefix string for displaying before any special messages.
- * suffix: An optional suffix string for displaying after any special messages.
- * context: The color codes for the entire error message.
- * notable: The color codes for a part of the message to make more visible.
- * set: An optional pointer to a set of all available color contexts for explicit use.
+ * fl_print_*_s:
+ * - debug: A string used as part of the message when printing a debug.
+ * - error: A string used as part of the message when printing an error.
+ * - warning: A string used as part of the message when printing a warning.
*/
-#ifndef _di_fl_print_t_
+#ifndef _di_fl_print_s_
#define FL_print_debug_s "DEBUG: "
#define FL_print_error_s "ERROR: "
#define FL_print_warning_s "WARNING: "
extern const f_string_static_t fl_print_debug_s;
extern const f_string_static_t fl_print_error_s;
extern const f_string_static_t fl_print_warning_s;
+#endif // _di_fl_print_s_
+/**
+ * Structure for facilitating colored or other managed printing.
+ *
+ * to: The file to print to.
+ * verbosity: The verbosity mode.
+ *
+ * prefix: An optional prefix string for displaying before any special messages.
+ * suffix: An optional suffix string for displaying after any special messages.
+ *
+ * context: The color codes for the entire error message.
+ * notable: The color codes for a part of the message to make more visible.
+ * set: An optional pointer to a set of all available color contexts for explicit use.
+ */
+#ifndef _di_fl_print_t_
typedef struct {
f_file_t to;
uint8_t verbosity;
0, \
}
- #define macro_fl_print_t_initialize(to, verbosity, prefix, suffix, context, notable, set) { to, verbosity, prefix, suffix, context, notable, set }
- #define macro_fl_print_t_initialize_debug() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_debug_d, F_type_descriptor_debug_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_debug_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
- #define macro_fl_print_t_initialize_debug2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_debug_d, F_type_descriptor_debug_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_debug_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
- #define macro_fl_print_t_initialize_error() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_error_d, F_type_descriptor_error_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_error_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
- #define macro_fl_print_t_initialize_error2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_error_d, F_type_descriptor_error_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_error_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
- #define macro_fl_print_t_initialize_warning() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_warning_d, F_type_descriptor_warning_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_warning_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
- #define macro_fl_print_t_initialize_warning2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_warning_d, F_type_descriptor_warning_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_warning_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
+ #define macro_fl_print_t_initialize(to, verbosity, prefix, suffix, context, notable, set) { \
+ to, verbosity, prefix, suffix, context, notable, set \
+ }
+
+ #define macro_fl_print_t_initialize_debug() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_debug_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
+ #define macro_fl_print_t_initialize_debug2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_debug_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
+ #define macro_fl_print_t_initialize_error() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_error_d, F_type_descriptor_error_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_error_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
+ #define macro_fl_print_t_initialize_error2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_error_d, F_type_descriptor_error_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_error_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
+ #define macro_fl_print_t_initialize_warning() macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_warning_s, f_string_static_t_initialize, f_color_set_t_initialize, f_color_set_t_initialize, 0)
+ #define macro_fl_print_t_initialize_warning2(suffix, set) macro_fl_print_t_initialize(macro_f_file_t_initialize2(F_type_output_d, F_type_descriptor_output_d, F_file_flag_write_only_d), f_console_verbosity_normal_e, fl_print_warning_s, suffix, f_color_set_t_initialize, f_color_set_t_initialize, set)
#endif // _di_fl_print_t_
#ifdef __cplusplus