From 5c05399dd79e5d1e40a25df11656d849899bb0cd Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 7 Sep 2019 16:29:09 -0500 Subject: [PATCH] Update: restructure f_file, add f_file_exists(), add f_file_exists_at(), and other f_file related changes Use "address" instead of "file" in f_file to help make things less confusing. Shorten use of "file_information" with "file". Implement f_file_exists(). Implement f_file_exists_at(). Try to avoid returning f_invalid_parameter to represent invalid parameters for standard C/POSIX functions. Implement new exceptions, like f_invalid_name and f_invalid_desciptor, to accommodate this. Use f_string_eol instead of "\n". --- level_0/f_file/c/file.c | 170 +++++++++++++++------ level_0/f_file/c/file.h | 78 ++++++++-- level_0/f_status/c/status.h | 2 + level_1/fl_color/c/color.c | 2 +- level_1/fl_file/c/file.c | 12 +- level_1/fl_fss/c/fss.c | 14 +- level_1/fl_fss/c/fss.h | 4 +- level_1/fl_status/c/status.c | 6 + level_1/fl_status/c/status.h | 6 + level_2/fll_status/c/status.c | 10 ++ level_3/firewall/c/private-firewall.c | 6 +- .../fss_basic_list_read/c/fss_basic_list_read.c | 8 +- .../fss_basic_list_write/c/fss_basic_list_write.c | 2 +- level_3/fss_basic_read/c/fss_basic_read.c | 8 +- level_3/fss_basic_write/c/fss_basic_write.c | 2 +- level_3/fss_extended_read/c/fss_extended_read.c | 8 +- level_3/fss_extended_write/c/fss_extended_write.c | 2 +- level_3/init/c/private-init.h | 4 +- 18 files changed, 248 insertions(+), 96 deletions(-) diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index d8e7833..b44522b 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -15,66 +15,147 @@ extern "C" { #endif #ifndef _di_f_file_open_ - f_return_status f_file_open(f_file *file_information, const f_string filename) { + f_return_status f_file_open(f_file *file, const f_string filename) { #ifndef _di_level_0_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // if file->mode is unset, then this may cause a segfault, depending on whether or not the libc will handle this appropriately - if (file_information->mode == 0) return f_status_set_error(f_invalid_parameter); + if (file->mode == 0) return f_status_set_error(f_invalid_parameter); - file_information->file = fopen(filename, file_information->mode); + file->address = fopen(filename, file->mode); - if (file_information->file == 0) return f_status_set_error(f_file_not_found); - if (ferror(file_information->file) != 0) return f_status_set_error(f_file_open_error); + if (file->address == 0) return f_status_set_error(f_file_not_found); + if (ferror(file->address) != 0) return f_status_set_error(f_file_open_error); - file_information->id = fileno(file_information->file); + file->id = fileno(file->address); - if (file_information->id == -1) return f_status_set_error(f_file_descriptor_error); + if (file->id == -1) return f_status_set_error(f_file_descriptor_error); return f_none; } #endif // _di_f_file_open_ #ifndef _di_f_file_close_ - f_return_status f_file_close(f_file *file_information) { + f_return_status f_file_close(f_file *file) { #ifndef _di_level_0_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_status_set_error(f_file_not_open); + if (file->address == 0) return f_status_set_error(f_file_not_open); // if we were given a file descriptor as well, make sure to flush all changes to the disk that are not flushed by the 'fflush()' command - if (file_information->id != 0) { + if (file->id != 0) { // make sure all unfinished data gets completed - if (fsync(file_information->id) != 0) return f_status_set_error(f_file_synchronize_error); + if (fsync(file->id) != 0) return f_status_set_error(f_file_synchronize_error); } - if (fclose(file_information->file) == 0) { - file_information->file = 0; + if (fclose(file->address) == 0) { + file->address = 0; return f_none; } else return f_status_set_error(f_file_close_error); } #endif // _di_f_file_close_ +#ifndef _di_f_file_exists_ + f_return_status f_file_exists(const f_string file_name) { + #ifndef _di_level_0_parameter_checking_ + if (file_name == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_0_parameter_checking_ + + if (access(file_name, F_OK)) { + if (errno == ENOENT) { + return f_false; + } + + if (errno == ENAMETOOLONG || errno == EFAULT) { + return f_status_set_error(f_invalid_name); + } + else if (errno == ENOMEM) { + return f_status_set_error(f_out_of_memory); + } + else if (errno == EOVERFLOW) { + return f_status_set_error(f_overflow); + } + else if (errno == ENOTDIR) { + return f_status_set_error(f_invalid_directory); + } + else if (errno == EACCES) { + return f_status_set_error(f_access_denied); + } + else if (errno == ELOOP) { + return f_status_set_error(f_loop); + } + + return f_status_set_error(f_false); + } + + return f_true; + } +#endif // _di_f_file_exists_ + +#ifndef _di_f_file_exists_at_ + f_return_status f_file_exists_at(const int directory_file_descriptor, const f_string file_name, const int flags) { + #ifndef _di_level_0_parameter_checking_ + if (directory_file_descriptor == 0) return f_status_set_error(f_invalid_parameter); + if (file_name == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_0_parameter_checking_ + + if (faccessat(directory_file_descriptor, file_name, F_OK, flags)) { + if (errno == ENOENT) { + return f_false; + } + + if (errno == ENAMETOOLONG || errno == EFAULT) { + return f_status_set_error(f_invalid_name); + } + else if (errno == ENOMEM) { + return f_status_set_error(f_out_of_memory); + } + else if (errno == EOVERFLOW) { + return f_status_set_error(f_overflow); + } + else if (errno == ENOTDIR) { + return f_status_set_error(f_invalid_directory); + } + else if (errno == EACCES) { + return f_status_set_error(f_access_denied); + } + else if (errno == ELOOP) { + return f_status_set_error(f_loop); + } + else if (errno == EBADF) { + return f_status_set_error(f_invalid_descriptor); + } + else if (errno == EINVAL) { + return f_status_set_error(f_invalid_parameter); + } + + return f_status_set_error(f_false); + } + + return f_true; + } +#endif // _di_f_file_exists_at_ + #ifndef _di_f_file_flush_ - f_return_status f_file_flush(f_file *file_information) { + f_return_status f_file_flush(f_file *file) { #ifndef _di_level_0_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_status_set_error(f_file_not_open); + if (file->address == 0) return f_status_set_error(f_file_not_open); - if (fflush(file_information->file) == 0) return f_none; + if (fflush(file->address) == 0) return f_none; else return f_status_set_error(f_file_flush_error); } #endif // _di_f_file_flush_ #ifndef _di_f_file_read_ - f_return_status f_file_read(f_file *file_information, f_string_dynamic *buffer, const f_file_position location) { + f_return_status f_file_read(f_file *file, f_string_dynamic *buffer, const f_file_position location) { #ifndef _di_level_0_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); if (buffer->used >= buffer->size) return f_status_set_error(f_invalid_parameter); if (location.buffer_start < 0) return f_status_set_error(f_invalid_parameter); @@ -87,38 +168,38 @@ extern "C" { } #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_status_set_error(f_file_not_open); + if (file->address == 0) return f_status_set_error(f_file_not_open); // first seek to 'where' we need to begin the read - f_u_long current_file_position = ftell(file_information->file); + f_u_long current_file_position = ftell(file->address); if (current_file_position == (f_u_long) -1) return f_status_set_error(f_file_seek_error); f_s_int result = 0; if (current_file_position > location.file_start) { - result = f_file_seek_from_current(file_information->file, file_information->byte_size * (0 - (current_file_position - location.file_start))); + result = f_file_seek_from_current(file->address, file->byte_size * (0 - (current_file_position - location.file_start))); } else if (current_file_position < location.file_start) { - result = f_file_seek_from_current(file_information->file, file_information->byte_size * (location.file_start - current_file_position)); + result = f_file_seek_from_current(file->address, file->byte_size * (location.file_start - current_file_position)); } if (result != 0) return f_status_set_error(f_file_seek_error); // now do the actual read if (location.total_elements == 0) { - result = fread(buffer->string + location.buffer_start, file_information->byte_size, buffer->size - buffer->used - 1, file_information->file); + result = fread(buffer->string + location.buffer_start, file->byte_size, buffer->size - buffer->used - 1, file->address); } else { - result = fread(buffer->string + location.buffer_start, file_information->byte_size, location.total_elements, file_information->file); + result = fread(buffer->string + location.buffer_start, file->byte_size, location.total_elements, file->address); } - if (file_information->file == 0) return f_status_set_error(f_file_read_error); - if (ferror(file_information->file) != 0) return f_status_set_error(f_file_read_error); + if (file->address == 0) return f_status_set_error(f_file_read_error); + if (ferror(file->address) != 0) return f_status_set_error(f_file_read_error); // now save how much of our allocated buffer is actually used // also make sure that we aren't making used space vanish if (location.buffer_start + result > buffer->used) { - buffer->used = location.buffer_start + (result / file_information->byte_size); + buffer->used = location.buffer_start + (result / file->byte_size); } // append an EOS only when the total elements were set to 0 @@ -127,7 +208,7 @@ extern "C" { } // make sure to communicate that we are done without a problem and the eof was reached - if (feof(file_information->file)) { + if (feof(file->address)) { return f_none_on_eof; } @@ -136,26 +217,26 @@ extern "C" { #endif // _di_f_file_read_ #ifndef _di_f_file_read_fifo_ - f_return_status f_file_read_fifo(f_file *file_information, f_string_dynamic *buffer) { + f_return_status f_file_read_fifo(f_file *file, f_string_dynamic *buffer) { #ifndef _di_level_0_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); if (buffer->used >= buffer->size) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_status_set_error(f_file_not_open); + if (file->address == 0) return f_status_set_error(f_file_not_open); f_s_int result = 0; // now do the actual read - result = fread(buffer->string + buffer->used, file_information->byte_size, buffer->size - buffer->used - 1, file_information->file); + result = fread(buffer->string + buffer->used, file->byte_size, buffer->size - buffer->used - 1, file->address); - if (file_information->file == 0) return f_status_set_error(f_file_read_error); - if (ferror(file_information->file) != 0) return f_status_set_error(f_file_read_error); + if (file->address == 0) return f_status_set_error(f_file_read_error); + if (ferror(file->address) != 0) return f_status_set_error(f_file_read_error); - buffer->used += (result / file_information->byte_size); + buffer->used += (result / file->byte_size); // make sure to communicate that we are done without a problem and the eof was reached - if (feof(file_information->file)) { + if (feof(file->address)) { return f_none_on_eof; } @@ -164,17 +245,14 @@ extern "C" { #endif // _di_f_file_read_fifo_ #ifndef _di_f_file_stat_ - f_return_status f_file_stat(const f_string file, struct stat *file_stat) { + f_return_status f_file_stat(const f_string file_name, struct stat *file_stat) { if (file_stat != 0) { return f_none; } - f_s_int result = 0; - - result = stat(file, file_stat); - if (result < 0) { + if (stat(file_name, file_stat) < 0) { if (errno == ENAMETOOLONG || errno == EFAULT) { - return f_status_set_error(f_invalid_parameter); + return f_status_set_error(f_invalid_name); } else if (errno == ENOMEM) { return f_status_set_error(f_out_of_memory); @@ -217,7 +295,7 @@ extern "C" { result = fstat(file_id, file_stat); if (result < 0) { if (errno == ENAMETOOLONG || errno == EFAULT) { - return f_status_set_error(f_invalid_parameter); + return f_status_set_error(f_invalid_name); } else if (errno == ENOMEM) { return f_status_set_error(f_out_of_memory); diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 42c32a9..7f130db 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -13,6 +13,8 @@ // libc includes #include +#include +#include #include #include #include @@ -54,10 +56,10 @@ extern "C" { #ifndef _di_f_file_ typedef struct { - f_file_id id; // file descriptor - size_t byte_size; // how many bytes to use on each read/write (for normal string handling this should be sizeof(f_string) - FILE * file; // the file data type - f_file_mode mode; // how the file is to be accessed (or is being accessed) + f_file_id id; // file descriptor. + size_t byte_size; // how many bytes to use on each read/write (for normal string handling this should be sizeof(f_string). + FILE * address; // a pointer to a file (generally opened). + f_file_mode mode; // how the file is to be accessed (or is being accessed). } f_file; #define f_file_initialize { 0, sizeof(char), 0, (f_file_mode) f_file_read_only } @@ -192,53 +194,101 @@ extern "C" { #ifndef _di_f_macro_file_reset_position_ #define f_macro_file_reset_position(position, file) \ if (position.total_elements == 0) { \ - fseek(file.file, 0, SEEK_END); \ - position.total_elements = ftell(file.file); \ - fseek(file.file, 0, SEEK_SET); \ + fseek(file.address, 0, SEEK_END); \ + position.total_elements = ftell(file.address); \ + fseek(file.address, 0, SEEK_SET); \ } #endif // _di_f_macro_file_reset_position_ #ifndef _di_f_file_open_ /** * open a particular file and save its stream. - * filename = name of the file. + * file name = name of the file. */ - extern f_return_status f_file_open(f_file *file_information, const f_string filename); + extern f_return_status f_file_open(f_file *file, const f_string filename); #endif // _di_f_file_open_ #ifndef _di_f_file_close_ /** * close file. */ - extern f_return_status f_file_close(f_file *file_information); + extern f_return_status f_file_close(f_file *file); #endif // _di_f_file_close_ +/** + * Check if a file exists. + * + * @param file_name + * The file name. + * + * @return + * f_true if file exists. + * f_false if file does not exist. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_name (with error bit) if the filename is too long. + * f_out_of_memory (with error bit) if out of memory. + * f_overflow (with error bit) on overflow error. + * f_invalid_directory (with error bit) on invalid directory. + * f_access_denied (with error bit) on access denied. + * f_loop (with error bit) on loop error. + * f_false (with error bit) on unknown/unhandled errors. + */ +#ifndef _di_f_file_exists_ + extern f_return_status f_file_exists(const f_string file_name); +#endif // _di_f_file_exists_ + +/** + * Check if a file exists at a given directory. + * + * @param directory_file_descriptor + * The file descriptor of the directory. + * @param file_name + * The file name. + * @param flags + * Additional flags to pass, such as AT_EACCESS or AT_SYMLINK_NOFOLLOW. + * + * @return + * f_true if file exists. + * f_false if file does not exist. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_name (with error bit) if the filename is too long. + * f_out_of_memory (with error bit) if out of memory. + * f_overflow (with error bit) on overflow error. + * f_invalid_directory (with error bit) on invalid directory. + * f_access_denied (with error bit) on access denied. + * f_loop (with error bit) on loop error. + * f_false (with error bit) on unknown/unhandled errors. + */ +#ifndef _di_f_file_exists_at_ + extern f_return_status f_file_exists_at(const int directory_file_descriptor, const f_string file_name, const int flags); +#endif // _di_f_file_exists_at_ + #ifndef _di_f_file_flush_ /** * flush file. */ - extern f_return_status f_file_flush(f_file *file_information); + extern f_return_status f_file_flush(f_file *file); #endif // _di_f_file_flush_ #ifndef _di_f_file_read_ /** * read a given amount of data from the buffer, will auto-seek to where. */ - extern f_return_status f_file_read(f_file *file_information, f_string_dynamic *buffer, const f_file_position location); + extern f_return_status f_file_read(f_file *file, f_string_dynamic *buffer, const f_file_position location); #endif // _di_f_file_read_ #ifndef _di_f_file_read_fifo_ /** * read a given amount of data from the buffer, will not auto seek. */ - extern f_return_status f_file_read_fifo(f_file *file_information, f_string_dynamic *buffer); + extern f_return_status f_file_read_fifo(f_file *file, f_string_dynamic *buffer); #endif // _di_f_file_read_fifo_ #ifndef _di_f_file_stat_ /** * read file statistics. */ - extern f_return_status f_file_stat(const f_string file, struct stat *file_stat); + extern f_return_status f_file_stat(const f_string file_name, struct stat *file_stat); #endif // _di_f_file_stat_ #ifndef _di_f_file_stat_by_id_ diff --git a/level_0/f_status/c/status.h b/level_0/f_status/c/status.h index 9120699..5420626 100644 --- a/level_0/f_status/c/status.h +++ b/level_0/f_status/c/status.h @@ -142,11 +142,13 @@ enum { #ifndef _di_f_status_invalid_ f_invalid, + f_invalid_name, f_invalid_parameter, f_invalid_syntax, f_invalid_data, f_invalid_file, f_invalid_directory, + f_invalid_descriptor, f_invalid_socket, f_invalid_device, f_invalid_link, diff --git a/level_1/fl_color/c/color.c b/level_1/fl_color/c/color.c index 4149a5e..13ccc40 100644 --- a/level_1/fl_color/c/color.c +++ b/level_1/fl_color/c/color.c @@ -172,7 +172,7 @@ extern "C" { } // now print the trailing newline, this is done _after_ ending the colors to avoid color wrapping issues that can happen when a color code follows a newline - fprintf(file, "\n"); + fprintf(file, "%c", f_string_eol); return f_none; } diff --git a/level_1/fl_file/c/file.c b/level_1/fl_file/c/file.c index 2ed2a4b..ce2cd67 100644 --- a/level_1/fl_file/c/file.c +++ b/level_1/fl_file/c/file.c @@ -14,7 +14,7 @@ extern "C" { if (position.total_elements < 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (file.file == 0) return f_status_set_warning(f_file_not_open); + if (file.address == 0) return f_status_set_warning(f_file_not_open); f_status status = f_none; f_string_length size = 0; @@ -67,7 +67,7 @@ extern "C" { if (buffer == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (file.file == 0) return f_status_set_warning(f_file_not_open); + if (file.address == 0) return f_status_set_warning(f_file_not_open); f_status status = f_none; f_string_length size = 0; @@ -106,12 +106,12 @@ extern "C" { #ifndef _di_fl_file_write_ f_return_status fl_file_write(f_file file, const f_string_dynamic buffer) { - if (file.file == 0) return f_status_set_error(f_file_not_open); + if (file.address == 0) return f_status_set_error(f_file_not_open); f_status status = f_none; size_t size = 0; - size = fwrite(buffer.string, file.byte_size, buffer.used, file.file); + size = fwrite(buffer.string, file.byte_size, buffer.used, file.address); if (size < buffer.used * file.byte_size) { return f_status_set_error(f_file_write_error); @@ -127,14 +127,14 @@ extern "C" { if (position.start < position.stop) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (file.file == 0) return f_file_not_open; + if (file.address == 0) return f_file_not_open; f_status status = f_none; size_t size = 0; f_string_length total = buffer.used - (position.stop - position.start + 1); - size = fwrite(buffer.string + position.start, file.byte_size, total, file.file); + size = fwrite(buffer.string + position.start, file.byte_size, total, file.address); if (size < total * file.byte_size) { return f_status_set_error(f_file_write_error); diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index 02c7ea4..abd0026 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -187,15 +187,15 @@ extern "C" { #endif // _di_fl_fss_identify_ #ifndef _di_fl_fss_identify_file_ - f_return_status fl_fss_identify_file(f_file *file_information, f_fss_header *header) { + f_return_status fl_fss_identify_file(f_file *file, f_fss_header *header) { #ifndef _di_level_1_parameter_checking_ - if (file_information == 0) return f_status_set_error(f_invalid_parameter); + if (file == 0) return f_status_set_error(f_invalid_parameter); if (header == 0) return f_status_set_error(f_invalid_parameter); - if (file_information->file == 0) return f_status_set_error(f_file_not_open); - if (ferror(file_information->file) != 0) return f_status_set_error(f_file_error); + if (file->address == 0) return f_status_set_error(f_file_not_open); + if (ferror(file->address) != 0) return f_status_set_error(f_file_error); #endif // _di_level_1_parameter_checking_ - clearerr(file_information->file); + clearerr(file->address); f_status status = f_none; f_string_dynamic buffer = f_string_dynamic_initialize; @@ -203,7 +203,7 @@ extern "C" { // make sure we are in the proper location in the file { - f_s_int seek_result = f_file_seek_from_beginning(file_information->file, 0); + f_s_int seek_result = f_file_seek_from_beginning(file->address, 0); if (seek_result != 0) return f_status_set_error(f_file_seek_error); } @@ -218,7 +218,7 @@ extern "C" { } // 2: buffer the file - status = f_file_read(file_information, &buffer, location); + status = f_file_read(file, &buffer, location); if (f_status_is_error(status)) { return status; diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index c129804..433d3e1 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -79,7 +79,7 @@ extern "C" { /** * Identify FSS type from a file. * - * @param file_information + * @param file * The file information. * @param header * The header data to populate with results of this function. @@ -96,7 +96,7 @@ extern "C" { * @see fl_fss_identify() */ #ifndef _di_fl_fss_identify_file_ - extern f_return_status fl_fss_identify_file(f_file *file_information, f_fss_header *header); + extern f_return_status fl_fss_identify_file(f_file *file, f_fss_header *header); #endif // _di_fl_fss_identify_file_ /** diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index d7391fc..adfe4a0 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -273,6 +273,9 @@ extern "C" { case f_invalid: *string = fl_status_string_invalid; break; + case f_invalid_name: + *string = fl_status_string_invalid_name; + break; case f_invalid_parameter: *string = fl_status_string_invalid_parameter; break; @@ -288,6 +291,9 @@ extern "C" { case f_invalid_directory: *string = fl_status_string_invalid_directory; break; + case f_invalid_descriptor: + *string = fl_status_string_invalid_descriptor; + break; case f_invalid_socket: *string = fl_status_string_invalid_socket; break; diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index 2f5f479..e8e41f3 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -280,6 +280,9 @@ extern "C" { #define fl_status_string_invalid "f_invalid" #define fl_status_string_invalid_length 10 + #define fl_status_string_invalid_name "f_invalid_name" + #define fl_status_string_invalid_name_length 15 + #define fl_status_string_invalid_parameter "f_invalid_parameter" #define fl_status_string_invalid_parameter_length 20 @@ -295,6 +298,9 @@ extern "C" { #define fl_status_string_invalid_directory "f_invalid_directory" #define fl_status_string_invalid_directory_length 20 + #define fl_status_string_invalid_descriptor "f_invalid_descriptor" + #define fl_status_string_invalid_descriptor_length 21 + #define fl_status_string_invalid_socket "f_invalid_socket" #define fl_status_string_invalid_socket_length 17 diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index b8d2dac..c8e5df7 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -453,6 +453,11 @@ extern "C" { return f_none; } + if (fl_string_compare(string, fl_status_string_invalid_name, length, fl_status_string_invalid_name_length) == f_equal_to) { + *code = f_invalid_name; + return f_none; + } + if (fl_string_compare(string, fl_status_string_invalid_parameter, length, fl_status_string_invalid_parameter_length) == f_equal_to) { *code = f_invalid_parameter; return f_none; @@ -478,6 +483,11 @@ extern "C" { return f_none; } + if (fl_string_compare(string, fl_status_string_invalid_descriptor, length, fl_status_string_invalid_descriptor_length) == f_equal_to) { + *code = f_invalid_descriptor; + return f_none; + } + if (fl_string_compare(string, fl_status_string_invalid_socket, length, fl_status_string_invalid_socket_length) == f_equal_to) { *code = f_invalid_socket; return f_none; diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 5e23359..4c8ebea 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -611,9 +611,9 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const } else { if (file_position.total_elements == 0) { - fseek(file.file, 0, SEEK_END); - file_position.total_elements = ftell(file.file); - fseek(file.file, 0, SEEK_SET); + fseek(file.address, 0, SEEK_END); + file_position.total_elements = ftell(file.address); + fseek(file.address, 0, SEEK_SET); } status = fl_file_read(file, file_position, &local_buffer); diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index 143f0ec..273b40f 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -62,7 +62,7 @@ extern "C" { if (data->process_pipe) { f_file file = f_file_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &data->buffer); @@ -132,9 +132,9 @@ extern "C" { } if (data->file_position.total_elements == 0) { - fseek(file.file, 0, SEEK_END); + fseek(file.address, 0, SEEK_END); - data->file_position.total_elements = ftell(file.file); + data->file_position.total_elements = ftell(file.address); // skip past empty files if (data->file_position.total_elements == 0) { @@ -142,7 +142,7 @@ extern "C" { continue; } - fseek(file.file, 0, SEEK_SET); + fseek(file.address, 0, SEEK_SET); } status = fl_file_read(file, data->file_position, &data->buffer); diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index dd841b7..35bfe60 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -55,7 +55,7 @@ extern "C" { f_file file = f_file_initialize; f_string_dynamic input = f_string_dynamic_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &input); diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 0723658..6e8d7f5 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -60,7 +60,7 @@ extern "C" { if (data->process_pipe) { f_file file = f_file_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &data->buffer); @@ -137,9 +137,9 @@ extern "C" { } if (data->file_position.total_elements == 0) { - fseek(file.file, 0, SEEK_END); + fseek(file.address, 0, SEEK_END); - data->file_position.total_elements = ftell(file.file); + data->file_position.total_elements = ftell(file.address); // skip past empty files if (data->file_position.total_elements == 0) { @@ -147,7 +147,7 @@ extern "C" { continue; } - fseek(file.file, 0, SEEK_SET); + fseek(file.address, 0, SEEK_SET); } status = fl_file_read(file, data->file_position, &data->buffer); diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index ec45108..b2407a8 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -55,7 +55,7 @@ extern "C" { f_file file = f_file_initialize; f_string_dynamic input = f_string_dynamic_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &input); diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 17ca402..bc3e4ae 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -66,7 +66,7 @@ extern "C" { if (data->process_pipe) { f_file file = f_file_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &data->buffer); @@ -137,9 +137,9 @@ extern "C" { } if (data->file_position.total_elements == 0) { - fseek(file.file, 0, SEEK_END); + fseek(file.address, 0, SEEK_END); - data->file_position.total_elements = ftell(file.file); + data->file_position.total_elements = ftell(file.address); // skip past empty files if (data->file_position.total_elements == 0) { @@ -147,7 +147,7 @@ extern "C" { continue; } - fseek(file.file, 0, SEEK_SET); + fseek(file.address, 0, SEEK_SET); } status = fl_file_read(file, data->file_position, &data->buffer); diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index db587bc..34bc474 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -79,7 +79,7 @@ extern "C" { f_file file = f_file_initialize; f_string_dynamic input = f_string_dynamic_initialize; - file.file = f_pipe; + file.address = f_pipe; status = fl_file_read_fifo(file, &input); diff --git a/level_3/init/c/private-init.h b/level_3/init/c/private-init.h index 8f7d750..52eb28b 100644 --- a/level_3/init/c/private-init.h +++ b/level_3/init/c/private-init.h @@ -53,7 +53,7 @@ extern "C" { f_macro_string_dynamic_delete(status, rule.directory); \ } \ if (status == f_none) { \ - f_macro_string_dynamic_delete(status, rule.file); \ + f_macro_string_dynamic_delete(status, rule.address); \ } \ if (status == f_none) { \ rule.require = 0; \ @@ -66,7 +66,7 @@ extern "C" { f_macro_string_dynamic_destroy(status, rule.directory); \ } \ if (status == f_none) { \ - f_macro_string_dynamic_destroy(status, rule.file); \ + f_macro_string_dynamic_destroy(status, rule.address); \ } \ if (status == f_none) { \ rule.require = 0; \ -- 1.8.3.1