diff --git a/xtandard.c b/xtandard.c index ef799fa..df83032 100644 --- a/xtandard.c +++ b/xtandard.c @@ -429,30 +429,30 @@ void file_list_import (char * name) { file_list_name = reallocate (file_list_name, (int) sizeof (* file_list_name) * file_list_count); file_list_data = reallocate (file_list_data, (int) sizeof (* file_list_data) * file_list_count); - file_list_mark [file_list_count - 1] = -1; - file_list_size [file_list_count - 1] = -1; - file_list_name [file_list_count - 1] = NULL; - file_list_data [file_list_count - 1] = NULL; + file_list_mark [file_list_active] = -1; + file_list_size [file_list_active] = -1; + file_list_name [file_list_active] = NULL; + file_list_data [file_list_active] = NULL; - file_list_name [file_list_count - 1] = allocate (string_length (name) + 1); + file_list_name [file_list_active] = allocate (string_length (name) + 1); - (void) string_copy_limit (file_list_name [file_list_count - 1], name, string_length (name) + 1); + (void) string_copy_limit (file_list_name [file_list_active], name, string_length (name) + 1); - file_list_mark [file_list_count - 1] = open (name, O_RDONLY); + file_list_mark [file_list_active] = open (name, O_RDWR); - fatal_failure (file_list_mark [file_list_count - 1] == -1, "file_list_import: Failed to open file, function open returned invalid descriptor."); + fatal_failure (file_list_mark [file_list_active] == -1, "file_list_import: Failed to open file, function open returned invalid descriptor."); - file_list_size [file_list_count - 1] = (int) lseek (file_list_mark [file_list_count - 1], 0, SEEK_END) + 1; + file_list_size [file_list_active] = (int) lseek (file_list_mark [file_list_active], 0, SEEK_END) + 1; - (void) lseek (file_list_mark [file_list_count - 1], 0, SEEK_SET); + (void) lseek (file_list_mark [file_list_active], 0, SEEK_SET); - file_list_data [file_list_count - 1] = allocate (file_list_size [file_list_count - 1]); + file_list_data [file_list_active] = allocate (file_list_size [file_list_active]); - (void) read (file_list_mark [file_list_count - 1], file_list_data [file_list_count - 1], (unsigned long int) (file_list_size [file_list_count - 1] - 1)); + (void) read (file_list_mark [file_list_active], file_list_data [file_list_active], (unsigned long int) (file_list_size [file_list_active] - 1)); - close (file_list_mark [file_list_count - 1]); + close (file_list_mark [file_list_active]); - file_list_data [file_list_count - 1] [file_list_size [file_list_count - 1] - 1] = '\0'; + file_list_data [file_list_active] [file_list_size [file_list_active] - 1] = '\0'; } void file_list_export (char * name) { @@ -466,10 +466,14 @@ void file_list_export (char * name) { } void file_list_insert_character (char character, int position) { - int offset = 0; + int offset; ++file_list_size [file_list_active]; - +/* + if (file_list_size [file_list_active] <= string_length (file_list_data [file_list_active])) { + file_list_data [file_list_active] = reallocate (file_list_data [file_list_active], file_list_size [file_list_active]); + } +*/ file_list_data [file_list_active] = reallocate (file_list_data [file_list_active], file_list_size [file_list_active]); for (offset = file_list_size [file_list_active] - 1; offset != position; --offset) { @@ -480,7 +484,7 @@ void file_list_insert_character (char character, int position) { } void file_list_remove_character (int position) { - int offset = 0; + int offset; if (position == 0) { return;