In particular, this is used for reading from piped files, namely stdin.
}
#endif // _di_f_file_read_
+#ifndef _di_f_file_read_fifo_
+ f_return_status f_file_read_fifo(f_file *file_information, f_dynamic_string *buffer){
+ #ifndef _di_level_0_parameter_checking_
+ if (file_information == f_null) return f_invalid_parameter;
+ #endif // _di_level_0_parameter_checking_
+
+ if (file_information->file == 0) return 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 - 1, file_information->file);
+
+ if (file_information->file == 0) return f_file_read_error;
+ if (ferror(file_information->file) != 0) return f_file_read_error;
+
+ buffer->used += result;
+
+ // make sure to communicate that we are done without a problem and the eof was reached
+ if (feof(file_information->file)){
+ return f_none_on_eof;
+ }
+
+ return f_none;
+ }
+#endif // _di_f_file_read_fifo_
+
#ifdef __cplusplus
} // extern "C"
#endif
extern f_return_status f_file_read(f_file *file_information, f_dynamic_string *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_dynamic_string *buffer);
+#endif // _di_f_file_read_fifo_
+
#ifdef __cplusplus
} // extern "C"
#endif
// populate the buffer
do{
- f_resize_dynamic_string(status, (*buffer), size);
+ if (buffer->size < size){
+ f_resize_dynamic_string(status, (*buffer), size);
- if (f_macro_test_for_allocation_errors(status)){
- return status;
+ if (f_macro_test_for_allocation_errors(status)){
+ return status;
+ }
}
status = f_file_read(&file, buffer, position);
}
#endif // _di_fl_file_read_
+#ifndef _di_fl_file_read_fifo_
+ f_return_status fl_file_read_fifo(f_file file, f_dynamic_string *buffer){
+ #ifndef _di_level_1_parameter_checking_
+ if (buffer == f_null) return f_invalid_parameter;
+ #endif // _di_level_1_parameter_checking_
+
+ if (file.file == 0) return f_file_not_open;
+
+ f_status status = f_status_initialize;
+ f_string_length size = f_string_length_initialize;
+
+ size = f_file_default_read_size;
+
+ // populate the buffer
+ do {
+ if (buffer->size < size){
+ f_resize_dynamic_string(status, (*buffer), size);
+
+ if (f_macro_test_for_allocation_errors(status)){
+ return status;
+ }
+ }
+
+ status = f_file_read_fifo(&file, buffer);
+
+ if (status == f_none_on_eof){
+ break;
+ } else if (status != f_none){
+ return status;
+ }
+
+ if (size + f_file_default_read_size > f_string_max_size){
+ return f_overflow;
+ }
+
+ size += f_file_default_read_size;
+ } while (f_true);
+
+ return f_none;
+ }
+#endif // _di_fl_file_read_fifo_
+
#ifdef __cplusplus
} // extern "C"
#endif
extern f_return_status fl_file_read(f_file file, const f_file_position position, f_dynamic_string *buffer);
#endif // _di_fl_file_read_
+#ifndef _di_fl_file_read_fifo_
+ extern f_return_status fl_file_read_fifo(f_file file, f_dynamic_string *buffer);
+#endif // _di_fl_file_read_fifo_
+
#ifdef __cplusplus
} // extern "C"
#endif