From: Kevin Day Date: Wed, 8 Jun 2022 01:11:45 +0000 (-0500) Subject: Bugfix: Problems exposed by unit tests in f_file. X-Git-Tag: 0.5.10~60 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=52f4261a2ea69b4cdc0b84d6cc7d92455a325d95;p=fll Bugfix: Problems exposed by unit tests in f_file. The stream functions do not populate errno. In these cases return either F_file_read or F_file_write with the error bits set as appropriate. Update the documentation comments. --- diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 51e8755..41d09b4 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -2211,15 +2211,7 @@ extern "C" { if (ferror_unlocked(file.stream)) { funlockfile(file.stream); - 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_failure); + return F_status_set_error(F_file_read); } buffer->used += size_read; @@ -2272,15 +2264,7 @@ extern "C" { if (ferror_unlocked(file.stream)) { funlockfile(file.stream); - 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_failure); + return F_status_set_error(F_file_read); } if (size_read) { @@ -2354,15 +2338,7 @@ extern "C" { if (ferror_unlocked(file.stream)) { funlockfile(file.stream); - 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_failure); + return F_status_set_error(F_file_read); } buffer->used += size_read; diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index e0a4dcf..1b685e9 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -2206,6 +2206,8 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. * * @see flockfile() + * @see feof_unlocked() + * @see ferror_unlocked() * @see fread_unlocked() * @see funlockfile() */ @@ -2230,17 +2232,16 @@ extern "C" { * F_none on success. * F_none_eof on success and EOF was reached. * - * 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. * 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 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_closed (with error bit) if the file is closed. + * F_file_read (with error bit) on file read error. * F_parameter (with error bit) if a parameter is invalid. * + * @see feof_unlocked() + * @see ferror_unlocked() + * @see flockfile() * @see fread() + * @see funlockfile() */ #ifndef _di_f_file_stream_read_block_ extern f_status_t f_file_stream_read_block(const f_file_t file, f_string_dynamic_t * const buffer); @@ -2269,18 +2270,15 @@ extern "C" { * F_none_eof on success and EOF was reached. * F_none_stop on success and total was reached. * - * 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. * 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 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_closed (with error bit) if the file is closed. + * F_file_read (with error bit) on file read error. * F_parameter (with error bit) if a parameter is invalid. * * Errors (with error bit) from: f_string_dynamic_increase_by(). * + * @see feof_unlocked() + * @see ferror_unlocked() * @see flockfile() * @see fread_unlocked() * @see funlockfile() @@ -2355,23 +2353,18 @@ extern "C" { * * @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_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_write (with error bit) on error during file write. * F_parameter (with error bit) if a parameter is invalid. * * F_file_write (with error bit) on any other error. * + * @see ferror_unlocked() * @see flockfile() * @see fwrite_unlocked() - * @see ferror_unlocked() * @see funlockfile() */ #ifndef _di_f_file_stream_write_ @@ -2395,16 +2388,11 @@ extern "C" { * * @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_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_write (with error bit) on error during file write. * F_parameter (with error bit) if a parameter is invalid. * * F_file_write (with error bit) on any other error. @@ -2435,17 +2423,12 @@ extern "C" { * * @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_eof when the file stream is at the end of the file. * 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_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_write (with error bit) on error during file write. * F_parameter (with error bit) if a parameter is invalid. * * F_file_write (with error bit) on any other error. @@ -2479,12 +2462,7 @@ extern "C" { * 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_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_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_write (with error bit) on error during file write. * F_parameter (with error bit) if a parameter is invalid. * * @see fwrite_unlocked() diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index d2af685..b9e5b13 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -796,14 +796,6 @@ extern "C" { if (ferror_unlocked(file.stream)) { funlockfile(file.stream); - 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_write); } diff --git a/level_0/f_file/c/private-file.h b/level_0/f_file/c/private-file.h index ae6edbe..1c38e9b 100644 --- a/level_0/f_file/c/private-file.h +++ b/level_0/f_file/c/private-file.h @@ -39,6 +39,9 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. * 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() @@ -89,6 +92,8 @@ extern "C" { * F_supported_not if copying a given type of file is unsupported. * F_failure (with error bit) for any other error. * + * @see open() + * * @see f_file_copy() * @see f_file_clone() */ @@ -133,6 +138,8 @@ extern "C" { * F_space_not (with error bit) if file system is out of space (or file system quota is reached). * F_failure (with error bit) for any other error. * + * @see open() + * * @see f_file_copy() * @see f_file_create() */ @@ -179,6 +186,8 @@ extern "C" { * F_space_not (with error bit) if file system is out of space (or file system quota is reached). * F_failure (with error bit) for any other error. * + * @see openat() + * * @see f_file_create_at() */ #if !defined(_di_f_file_create_at_) @@ -214,6 +223,8 @@ extern "C" { * F_space_not (with error bit) if file system is out of space (or file system quota is reached). * F_failure (with error bit) for any other error. * + * @see mkdir() + * * @see f_file_copy() */ #if !defined(_di_f_file_copy_) @@ -252,6 +263,8 @@ extern "C" { * F_space_not (with error bit) if file system is out of space (or file system quota is reached). * F_failure (with error bit) for any other error. * + * @see mkdirat() + * * @see f_file_copy_at() */ #if !defined(_di_f_file_copy_at_) @@ -284,6 +297,8 @@ extern "C" { * F_supported_not (with error bit) for unsupported file types. * F_failure (with error bit) for any other error. * + * @see mkfifo() + * * @see f_file_create_fifo() * @see f_file_copy() */ @@ -320,6 +335,8 @@ extern "C" { * F_supported_not (with error bit) for unsupported file types. * F_failure (with error bit) for any other error. * + * @see mkfifoat() + * * @see f_file_create_fifo_at() * @see f_file_copy_at() */ @@ -359,6 +376,8 @@ extern "C" { * F_supported_not (with error bit) for unsupported file types. * F_failure (with error bit) for any other error. * + * @see mknod() + * * @see f_file_copy() * @see f_file_create_device() * @see f_file_create_node() @@ -402,6 +421,8 @@ extern "C" { * F_failure (with error bit) for any other error. * F_supported_not (with error bit) for unsupported file types. * + * @see mknodat() + * * @see f_file_copy_at() * @see f_file_create_device_at() * @see f_file_create_node_at() @@ -429,6 +450,8 @@ extern "C" { * 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_close() * @see f_file_copy() * @see f_file_flush() @@ -467,6 +490,8 @@ extern "C" { * F_read_only (with error bit) if file system is read-only. * F_failure (with error bit) for any other error. * + * @see symlink() + * * @see f_file_copy() * @see f_file_link() */ @@ -507,6 +532,8 @@ extern "C" { * F_read_only (with error bit) if file system is read-only. * F_failure (with error bit) for any other error. * + * @see symlinkat() + * * @see f_file_link_at() */ #if !defined(_di_f_file_link_at_) @@ -541,6 +568,8 @@ extern "C" { * F_string_too_large (with error bit) if link target path is too large for string buffer size. * F_failure (with error bit) for any other error. * + * @see readlink() + * * @see f_file_copy() * @see f_file_link_read() * @see f_string_dynamic_increase_by() @@ -581,6 +610,8 @@ extern "C" { * F_string_too_large (with error bit) if link target path is too large for string buffer size. * F_failure (with error bit) for any other error. * + * @see readlinkat() + * * @see f_file_copy_at() * @see f_file_link_read_at() * @see f_string_dynamic_increase_by() @@ -615,6 +646,8 @@ extern "C" { * F_read_only (with error bit) if file is read-only. * F_failure (with error bit) for any other error. * + * @see chmod() + * * @see f_file_copy() * @see f_file_mode_set() */ @@ -649,6 +682,8 @@ extern "C" { * F_read_only (with error bit) if file is read-only. * F_failure (with error bit) for any other error. * + * @see fchmodat() + * * @see f_file_mode_set_at() */ #if !defined(_di_f_file_mode_set_at_) @@ -677,6 +712,8 @@ extern "C" { * F_file_open (with error bit) if the file is already open. * F_parameter (with error bit) if a parameter is invalid. * + * @see open() + * * @see f_file_copy() * @see f_file_open() */ @@ -708,6 +745,8 @@ extern "C" { * F_file_open (with error bit) if the file is already open. * F_parameter (with error bit) if a parameter is invalid. * + * @see openat() + * * @see f_file_open_at() */ #if !defined(_di_f_file_open_at_) @@ -746,6 +785,9 @@ extern "C" { * F_read_only (with error bit) if file is read-only. * F_failure (with error bit) for any other error. * + * @see chown() + * @see lchown() + * * @see f_file_copy() * @see f_file_role_change() */ @@ -787,6 +829,8 @@ extern "C" { * F_read_only (with error bit) if file is read-only. * F_failure (with error bit) for any other error. * + * @see fchownat() + * * @see f_file_role_change_at() */ #if !defined(_di_f_file_role_change_at_) @@ -818,6 +862,9 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * + * @see lstat() + * @see stat() + * * @see f_file_copy() * @see f_file_exists() * @see f_file_is() @@ -854,6 +901,8 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * + * @see fstatat() + * * @see f_file_stat_at() * @see f_file_exists_at() * @see f_file_touch_at() @@ -884,6 +933,8 @@ extern "C" { * F_number_overflow (with error bit) on overflow error. * F_parameter (with error bit) if a parameter is invalid. * + * @see fstat() + * * @see f_file_size_by_id() * @see f_file_stat_by_id() */ @@ -929,16 +980,13 @@ extern "C" { * 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_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 (with error bit) if file descriptor is in an error state. - * 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_write (with error bit) on error during file write. * F_parameter (with error bit) if a parameter is invalid. * + * @see flockfile() + * @see fwrite_unlocked() + * @see funlockfile() + * * @see f_file_stream_write() * @see f_file_stream_write_block() * @see f_file_stream_write_range() @@ -977,6 +1025,8 @@ extern "C" { * F_interrupt (with error bit) if interrupt was received. * F_parameter (with error bit) if a parameter is invalid. * + * @see write() + * * @see f_file_write() * @see f_file_write_block() * @see f_file_write_range()