From 5f94fb485f6e760313b060ea49b50f6999e3042d Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 10 May 2020 20:58:19 -0500 Subject: [PATCH] Update: finish the @todo in errno handling of recent directory additions --- level_0/f_directory/c/directory.c | 28 ++++++++++++++++++++++++---- level_0/f_directory/c/directory.h | 3 +++ level_2/fll_directory/c/directory.h | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/level_0/f_directory/c/directory.c b/level_0/f_directory/c/directory.c index 2dbc324..6c245ba 100644 --- a/level_0/f_directory/c/directory.c +++ b/level_0/f_directory/c/directory.c @@ -82,8 +82,6 @@ extern "C" { result = remove(path); } - // @todo properly handle the correct error codes, this was simply copied over from f_file_remove(). - if (result < 0) { if (errno == EACCES) { return f_status_set_error(f_access_denied); @@ -118,6 +116,18 @@ extern "C" { else if (errno == EROFS) { return f_status_set_error(f_read_only); } + else if (errno == EOVERFLOW) { + return f_status_set_error(f_number_overflow); + } + else if (errno == EMFILE) { + return f_status_set_error(f_file_max_descriptors); + } + else if (errno == ENFILE) { + return f_status_set_error(f_file_max_open); + } + else if (errno == EINVAL) { + return f_status_set_error(f_invalid_parameter); + } return f_status_set_error(f_failure); } @@ -148,8 +158,6 @@ extern "C" { result = remove(path); } - // @todo properly handle the correct error codes, this was simply copied over from f_file_remove(). - if (result < 0) { if (errno == EACCES) { return f_status_set_error(f_access_denied); @@ -184,6 +192,18 @@ extern "C" { else if (errno == EROFS) { return f_status_set_error(f_read_only); } + else if (errno == EOVERFLOW) { + return f_status_set_error(f_number_overflow); + } + else if (errno == EMFILE) { + return f_status_set_error(f_file_max_descriptors); + } + else if (errno == ENFILE) { + return f_status_set_error(f_file_max_open); + } + else if (errno == EINVAL) { + return f_status_set_error(f_invalid_parameter); + } return f_status_set_error(f_failure); } diff --git a/level_0/f_directory/c/directory.h b/level_0/f_directory/c/directory.h index 82a1612..8f55a9a 100644 --- a/level_0/f_directory/c/directory.h +++ b/level_0/f_directory/c/directory.h @@ -195,6 +195,9 @@ extern "C" { * f_prohibited (with error bit) if filesystem does not allow for removing. * f_read_only (with error bit) if file is read-only. * f_failure (with error bit) for any other (unlink()) error. + * f_number_overflow (with error bit) on integer overflow. + * f_file_max_descriptors (with error bit) if max file descriptors was reached. + * f_file_max_open (with error bit) too many open files. * * @see nftw() * @see remove() diff --git a/level_2/fll_directory/c/directory.h b/level_2/fll_directory/c/directory.h index 8007d09..e1b4af1 100644 --- a/level_2/fll_directory/c/directory.h +++ b/level_2/fll_directory/c/directory.h @@ -60,6 +60,8 @@ extern "C" { * f_directory_error_descriptor (with error bit) on directory file descriptor error. * f_directory_error_stream (with error bit) on directory stream error. * f_directory_error_unsupported (with error bit) on directory file descriptor not supported. + * f_file_max_descriptors (with error bit) if max file descriptors was reached. + * f_file_max_open (with error bit) too many open files. * * @see alphasort() * @see scandir() -- 1.8.3.1