The stream read and write functions should also be implemented.
This is just an off the top of my mind implementation and may need to be reviewed at a later date.
Change the existing f_file functions to re-use the existing string structure to avoid the more wasteful memset and memcopy from the static array.
This design now, instead, has a cost of potentially allocating more memory than needed at the size specified by file.size_read.
Continue the print changes.
There is going to need to be work done in regards to how I am reading opening and reading streams.
I started to do this in private-fake.c but then noticed some things that needed review, such as the path.current and path.top.
f_status_t status = F_none;
ssize_t size_read = 0;
- char buffer_read[file.size_read];
+ for (f_string_t buffer_read = 0; ;) {
- memset(&buffer_read, 0, sizeof(file.size_read));
-
- while ((size_read = read(file.id, buffer_read, file.size_read)) > 0) {
-
- if (buffer->used + size_read > buffer->size) {
- if (buffer->size + size_read > f_string_length_t_size) {
+ if (buffer->used + file.size_read > buffer->size) {
+ if (buffer->size + file.size_read > f_string_length_t_size) {
return F_status_set_error(F_string_too_large);
}
- f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + size_read);
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + file.size_read);
if (F_status_is_error(status)) return status;
+
+ memset(buffer->string + buffer->used, 0, sizeof(file.size_read));
}
- memcpy(buffer->string + buffer->used, buffer_read, size_read);
- buffer->used += size_read;
- } // while
+ buffer_read = buffer->string + buffer->used;
- if (!size_read) {
- return F_none_eof;
- }
+ size_read = read(file.id, buffer_read, file.size_read);
- if (size_read < 0) {
- 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_interrupted);
- 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);
+ if (size_read < 0) {
+ 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_interrupted);
+ 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_failure);
+ }
- return F_none;
+ buffer->used += size_read;
+
+ if (size_read < file.size_read) break;
+ } // for
+
+ return F_none_eof;
}
#endif // _di_f_file_read_
f_status_t status = F_none;
ssize_t size_read = 0;
- char buffer_read[file.size_read];
+ f_string_t buffer_read = 0;
- memset(&buffer_read, 0, sizeof(file.size_read));
-
- if ((size_read = read(file.id, buffer_read, file.size_read)) > 0) {
- if (buffer->used + size_read > buffer->size) {
- if (buffer->size + size_read > f_string_length_t_size) {
- return F_status_set_error(F_string_too_large);
- }
-
- f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + size_read);
- if (F_status_is_error(status)) return status;
+ if (buffer->used + size_read > buffer->size) {
+ if (buffer->size + size_read > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
}
- memcpy(buffer->string + buffer->used, buffer_read, size_read);
- buffer->used += size_read;
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + size_read);
+ if (F_status_is_error(status)) return status;
+
+ memset(buffer->string + buffer->used, 0, sizeof(file.size_read));
}
- if (!size_read) {
- return F_none_eof;
+ buffer_read = buffer->string + buffer->used;
+
+ size_read = read(file.id, buffer_read, file.size_read);
+
+ if (size_read > 0) {
+ buffer->used += size_read;
}
if (size_read < 0) {
return F_status_set_error(F_failure);
}
+ if (size_read < file.size_read) {
+ return F_none_eof;
+ }
+
return F_none;
}
#endif // _di_f_file_read_block_
if (file.id == -1) return F_status_set_error(F_file_closed);
- f_status_t status = F_none;
- ssize_t size_read = 0;
-
f_string_length_t buffer_size = file.size_read;
f_string_length_t buffer_count = 0;
- if (total < buffer_size) {
- buffer_size = total;
- }
-
- char buffer_read[buffer_size];
+ f_status_t status = F_none;
+ ssize_t size_read = 0;
- memset(&buffer_read, 0, sizeof(buffer_size));
+ for (f_string_t buffer_read = 0; ;) {
- while (buffer_count < total && (size_read = read(file.id, buffer_read, buffer_size)) > 0) {
+ if (buffer_count + buffer_size > total) {
+ buffer_size = total - buffer_count;
+ }
- if (buffer->used + size_read > buffer->size) {
- if (buffer->size + size_read > f_string_length_t_size) {
+ if (buffer->used + buffer_size > buffer->size) {
+ if (buffer->size + buffer_size > f_string_length_t_size) {
return F_status_set_error(F_string_too_large);
}
- f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + size_read);
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + buffer_size);
if (F_status_is_error(status)) return status;
+
+ memset(buffer->string + buffer->used, 0, sizeof(buffer_size));
+ }
+
+ buffer_read = buffer->string + buffer->used;
+
+ size_read = read(file.id, buffer_read, buffer_size);
+
+ if (size_read < 0) {
+ 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_interrupted);
+ 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);
}
- memcpy(buffer->string + buffer->used, buffer_read, size_read);
buffer->used += size_read;
- buffer_count += size_read;
- } // while
- if (!size_read) {
- return F_none_eof;
- }
+ if (size_read < buffer_size) {
+ return F_none_eof;
+ }
- if (size_read < 0) {
- 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_interrupted);
- 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);
+ buffer_count += size_read;
- return F_status_set_error(F_failure);
- }
+ if (buffer_count == total) {
+ return F_none_stop;
+ }
+ } // for
return F_none;
}
#endif // _di_f_file_stream_close_
#ifndef _di_f_file_stream_descriptor_
- f_return_status f_file_stream_descriptor(const int id, const f_string_t mode, FILE *stream) {
+ f_return_status f_file_stream_descriptor(const f_string_t mode, f_file_t *file) {
#ifndef _di_level_0_parameter_checking_
- if (id == -1) return F_status_set_error(F_parameter);
- if (!mode) return F_status_set_error(F_parameter);
- if (!stream) return F_status_set_error(F_parameter);
+ if (!file) return F_status_set_error(F_parameter);
+ if (file->id == -1) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- stream = fdopen(id, mode);
+ if (mode) {
+ file->stream = fdopen(file->id, mode);
+ }
+ else {
+ file->stream = fdopen(file->id, private_f_file_stream_open_mode_determine(file->flag));
+ }
- if (!stream) {
+ if (!file->stream) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EAGAIN) return F_status_set_error(F_prohibited);
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
f_return_status f_file_stream_open(const f_string_t path, const f_string_t mode, f_file_t *file) {
#ifndef _di_level_0_parameter_checking_
if (!path) return F_status_set_error(F_parameter);
- if (!mode) return F_status_set_error(F_parameter);
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- file->stream = fopen(path, mode);
+ if (mode) {
+ file->stream = fopen(path, mode);
+ }
+ else {
+ file->stream = fopen(path, private_f_file_stream_open_mode_determine(file->flag));
+ }
if (!file->stream) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
}
#endif // _di_f_file_stream_open_
+#ifndef _di_f_file_stream_read_
+ f_return_status f_file_stream_read(const f_file_t file, const f_string_length_t amount, f_string_dynamic_t *buffer) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_read) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ if (buffer->used > buffer->size) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ f_status_t status = F_none;
+ ssize_t size_read = 0;
+
+ for (;;) {
+
+ if (buffer->used + file.size_read > buffer->size) {
+ if (buffer->size + file.size_read > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
+ }
+
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + file.size_read);
+ if (F_status_is_error(status)) return status;
+
+ memset(buffer->string + buffer->used, 0, sizeof(file.size_read));
+ }
+
+ size_read = fread(buffer->string + buffer->used, amount, file.size_read, file.stream);
+
+ if (ferror(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_interrupted);
+ 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);
+ }
+
+ buffer->used += size_read * amount;
+
+ if (feof(file.stream)) break;
+ } // for
+
+ return F_none_eof;
+ }
+#endif // _di_f_file_stream_read_
+
+#ifndef _di_f_file_stream_read_block_
+ f_return_status f_file_stream_read_block(const f_file_t file, const f_string_length_t amount, f_string_dynamic_t *buffer) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_read) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ if (buffer->used > buffer->size) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ const f_string_length_t buffer_size = file.size_read * amount;
+
+ f_status_t status = F_none;
+ ssize_t size_read = 0;
+
+ if (buffer->used + buffer_size > buffer->size) {
+ if (buffer->size + buffer_size > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
+ }
+
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + buffer_size);
+ if (F_status_is_error(status)) return status;
+ }
+
+ memset(buffer->string + buffer->used, 0, sizeof(buffer_size));
+
+ size_read = fread(buffer->string + buffer->used, amount, file.size_read, file.stream);
+
+ if (ferror(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_interrupted);
+ 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);
+ }
+
+ buffer->used += size_read * amount;
+
+ if (feof(file.stream)) {
+ return F_none_eof;
+ }
+
+ return F_none;
+ }
+#endif // _di_f_file_stream_read_block_
+
+#ifndef _di_f_file_stream_read_until_
+ f_return_status f_file_stream_read_until(const f_file_t file, const f_string_length_t amount, const f_string_length_t total, f_string_dynamic_t *buffer) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_read) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ if (buffer->used > buffer->size) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ f_string_length_t buffer_size = file.size_read;
+ f_string_length_t buffer_count = 0;
+
+ f_status_t status = F_none;
+ ssize_t size_read = 0;
+
+ for (;;) {
+
+ if (buffer_count + buffer_size > total) {
+ buffer_size = total - buffer_count;
+ }
+
+ if (buffer->used + buffer_size > buffer->size) {
+ if (buffer->size + buffer_size > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
+ }
+
+ f_macro_string_dynamic_t_resize(status, (*buffer), buffer->size + buffer_size);
+ if (F_status_is_error(status)) return status;
+
+ memset(buffer->string + buffer->used, 0, sizeof(buffer_size));
+ }
+
+ size_read = fread(buffer->string + buffer->used, amount, file.size_read, file.stream);
+
+ if (ferror(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_interrupted);
+ 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);
+ }
+
+ buffer->used += size_read * amount;
+
+ if (feof(file.stream)) {
+ return F_none_eof;
+ }
+
+ buffer_count += size_read * amount;
+
+ if (buffer_count == total) break;
+ } // for
+
+ return F_none_stop;
+ }
+#endif // _di_f_file_stream_read_until_
+
#ifndef _di_f_file_stream_reopen_
f_return_status f_file_stream_reopen(const f_string_t path, const f_string_t mode, f_file_t *file) {
#ifndef _di_level_0_parameter_checking_
if (!path) return F_status_set_error(F_parameter);
- if (!mode) return F_status_set_error(F_parameter);
if (!file) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (!freopen(path, mode, file->stream)) {
+ FILE *result = 0;
+
+ if (mode) {
+ result = freopen(path, mode, file->stream);
+ }
+ else {
+ result = freopen(path, private_f_file_stream_open_mode_determine(file->flag), file->stream);
+ }
+
+ if (!result) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EAGAIN) return F_status_set_error(F_prohibited);
if (errno == EBADF) return F_status_set_error(F_file_descriptor);
}
#endif // _di_f_file_stream_reopen_
+#ifndef _di_f_file_stream_write_
+ f_return_status f_file_stream_write(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, f_string_length_t *written) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_write) return F_status_set_error(F_parameter);
+ if (buffer.used > buffer.size) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ if (!buffer.used) {
+ if (written) *written = 0;
+ return F_data_not;
+ }
+
+ f_status_t status = F_none;
+
+ if (written) {
+ private_f_file_stream_write_until(file, buffer.string, amount, buffer.used, written);
+
+ if (status == F_none && *written == buffer.used) return F_none_eos;
+ }
+ else {
+ f_string_length_t written_local = 0;
+
+ private_f_file_stream_write_until(file, buffer.string, amount, buffer.used, &written_local);
+
+ if (status == F_none && written_local == buffer.used) return F_none_eos;
+ }
+
+ if (F_status_is_error(status)) return F_status_set_error(status);
+
+ return status;
+ }
+#endif // _di_f_file_stream_write_
+
+#ifndef _di_f_file_stream_write_block_
+ f_return_status f_file_stream_write_block(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, f_string_length_t *written) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_write) return F_status_set_error(F_parameter);
+ if (buffer.used > buffer.size) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ if (!buffer.used) {
+ if (written) *written = 0;
+ return F_data_not;
+ }
+
+ f_string_length_t write_max = file.size_write;
+
+ if (write_max > buffer.used) {
+ write_max = buffer.used;
+ }
+
+ f_status_t status = F_none;
+
+ if (written) {
+ private_f_file_stream_write_until(file, buffer.string, amount, write_max, written);
+
+ if (status == F_none) {
+ if (*written == buffer.used) return F_none_eos;
+ if (*written == write_max) return F_none_stop;
+ }
+ }
+ else {
+ f_string_length_t written_local = 0;
+
+ private_f_file_stream_write_until(file, buffer.string, amount, write_max, &written_local);
+
+ if (status == F_none) {
+ if (written_local == buffer.used) return F_none_eos;
+ if (written_local == write_max) return F_none_stop;
+ }
+ }
+
+ return status;
+ }
+#endif // _di_f_file_stream_write_block_
+
+#ifndef _di_f_file_stream_write_until_
+ f_return_status f_file_stream_write_until(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, const f_string_length_t total, f_string_length_t *written) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_write) return F_status_set_error(F_parameter);
+ if (buffer.used > buffer.size) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ if (!total) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ if (!buffer.used || !total) {
+ if (written) *written = 0;
+ return F_data_not;
+ }
+
+ f_string_length_t write_max = total;
+
+ if (write_max > buffer.used) {
+ write_max = buffer.used;
+ }
+
+ f_status_t status = F_none;
+
+ if (written) {
+ private_f_file_stream_write_until(file, buffer.string, amount, write_max, written);
+
+ if (status == F_none) {
+ if (*written == buffer.used) return F_none_eos;
+ if (*written == write_max) return F_none_stop;
+ }
+ }
+ else {
+ f_string_length_t written_local = 0;
+
+ private_f_file_stream_write_until(file, buffer.string, amount, buffer.used, &written_local);
+
+ if (status == F_none) {
+ if (written_local == buffer.used) return F_none_eos;
+ if (written_local == write_max) return F_none_stop;
+ }
+ }
+
+ return status;
+ }
+#endif // _di_f_file_stream_write_until_
+
+#ifndef _di_f_file_stream_write_range_
+ f_return_status f_file_stream_write_range(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, const f_string_range_t range, f_string_length_t *written) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!file.size_write) return F_status_set_error(F_parameter);
+ if (buffer.used > buffer.size) return F_status_set_error(F_parameter);
+ if (amount < 1) return F_status_set_error(F_parameter);
+ if (range.stop < range.start) return F_status_set_error(F_parameter);
+ if (range.start >= buffer.used) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
+
+ if (!file.stream) return F_status_set_error(F_file_closed);
+
+ if (!buffer.used) {
+ if (written) *written = 0;
+ return F_data_not;
+ }
+
+ const f_string_length_t total = (range.stop - range.start) + 1;
+ f_string_length_t write_max = total;
+
+ if (write_max > buffer.used) {
+ write_max = buffer.used;
+ }
+
+ f_status_t status = F_none;
+
+ if (written) {
+ private_f_file_stream_write_until(file, buffer.string + range.start, amount, write_max, written);
+
+ if (status == F_none) {
+ if (range.start + *written == buffer.used) return F_none_stop;
+ if (range.start + *written == total) return F_none_eos;
+ }
+ }
+ else {
+ f_string_length_t written_local = 0;
+
+ private_f_file_stream_write_until(file, buffer.string + range.start, amount, write_max, &written_local);
+
+ if (status == F_none) {
+ if (range.start + written_local == buffer.used) return F_none_eos;
+ if (range.start + written_local == total) return F_none_stop;
+ }
+ }
+
+ return status;
+ }
+#endif // _di_f_file_stream_write_range_
+
#ifndef _di_f_file_touch_
f_return_status f_file_touch(const f_string_t path, const mode_t mode, const bool dereference) {
#ifndef _di_level_0_parameter_checking_
#ifndef _di_level_0_parameter_checking_
if (!file.size_write) return F_status_set_error(F_parameter);
if (buffer.used > buffer.size) return F_status_set_error(F_parameter);
+ if (!total) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
if (file.id == -1) return F_status_set_error(F_file_closed);
return F_data_not;
}
- f_string_length_t write_max = file.size_write;
+ f_string_length_t write_max = total;
if (write_max > buffer.used) {
write_max = buffer.used;
*
* Will flush before closing.
*
+ * @todo consider making this consistent and acceptinf f_file_t instead of just the id.
+ *
* @param id
* The file descriptor.
*
/**
* Read until EOF is reached.
*
- * To check how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ * To determine how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
*
* @param file
* The file to read.
* The contents of the file is appended into this buffer.
*
* @return
- * 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.
/**
* Read until a given number or EOF is reached, storing it in the buffer.
*
- * To check how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ * To determine how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ *
+ * This is different from simply using the file.size_read.
+ * The file.size_read represents the amount to process for a given buffer size.
+ * The total represents the maximum number of bytes to process.
+ * For example, if file.size_read is 16 and total is 128, then this function would need to be called 8 times until total is reached.
*
* @param file
* The file to read.
* The buffer the file is being read into.
*
* @return
- * F_none on success.
* 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_file_closed (with error bit) if file is not open.
/**
* Open a file stream from a file descriptor.
*
- * @param id
- * The file descriptor.
* @param mode
* The file modes do use when opening.
+ * The file modes do use when opening.
+ * Set to 0 to determine mode from file.flags (falling back to read only as a failsafe).
+ * If neither truncate nor append are not specified in write only mode, then the failsafe is to append.
* This should match the modes used to open the file descriptor as it relates to the stream modes.
- * @param stream
- * The file stream.
- * Updated on success, but may be set to NULL on error.
+ * @param file
+ * The file with a valid file descriptor (file.id).
+ * THe file stream (file.stream) is updated on success, but may be set to NULL on error.
*
* @return
* F_none is returned on success.
* @see fdopen()
*/
#ifndef _di_f_file_stream_descriptor_
- extern f_return_status f_file_stream_descriptor(const int id, const f_string_t mode, FILE *stream);
+ extern f_return_status f_file_stream_descriptor(const f_string_t mode, f_file_t *file);
#endif // _di_f_file_stream_descriptor_
/**
* The file path
* @param mode
* The file modes do use when opening.
+ * Set to 0 to determine mode from file.flags (falling back to read only as a failsafe).
+ * If neither truncate nor append are not specified in write only mode, then the failsafe is to append.
* @param file
* The file information.
* The file.stream is updated if necessary.
#endif // _di_f_file_stream_open_
/**
+ * Read until EOF is reached.
+ *
+ * To check how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ *
+ * @param file
+ * The file to read.
+ * The file must already be open.
+ * @param amount
+ * The total amount of file.size_read to process.
+ * This amount is multiplied against file.size_read and must be greater than 0.
+ * @param buffer
+ * The buffer the file is being read into.
+ * The contents of the file is appended into this buffer.
+ *
+ * @return
+ * 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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fread()
+ */
+#ifndef _di_f_file_stream_read_
+ extern f_return_status f_file_stream_read(const f_file_t file, const f_string_length_t amount, f_string_dynamic_t *buffer);
+#endif // _di_f_file_stream_read_
+
+/**
+ * Read until a single block is filled or EOF is reached.
+ *
+ * To determine how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ *
+ * @param file
+ * The file to read.
+ * The file must already be open.
+ * @param amount
+ * The total amount of file.size_read to process.
+ * This amount is multiplied against file.size_read and must be greater than 0.
+ * @param buffer
+ * The buffer the file is being read into.
+ * The contents of the file is appended into this buffer.
+ *
+ * @return
+ * 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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fread()
+ */
+#ifndef _di_f_file_stream_read_block_
+ extern f_return_status f_file_stream_read_block(const f_file_t file, const f_string_length_t amount, f_string_dynamic_t *buffer);
+#endif // _di_f_file_stream_read_block_
+
+/**
+ * Read until a given number or EOF is reached, storing it in the buffer.
+ *
+ * To check how much was read into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ *
+ * This is different from simply using the file.size_read.
+ * The file.size_read represents the amount to process for a given buffer size.
+ * The total represents the maximum number of "size" to process.
+ * For example, if file.size_read is 16 and total is 128, then this function would need to be called 8 times until total is reached.
+ *
+ * @param file
+ * The file to read.
+ * The file must already be open.
+ * @param amount
+ * The total amount of file.size_read to process.
+ * This amount is multiplied against file.size_read and must be greater than 0.
+ * @param total
+ * The total bytes to read, unless EOF is reached first.
+ * @param buffer
+ * The buffer the file is being read into.
+ *
+ * @return
+ * 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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fread()
+ */
+#ifndef _di_f_file_stream_read_until_
+ extern f_return_status f_file_stream_read_until(const f_file_t file, const f_string_length_t amount, const f_string_length_t total, f_string_dynamic_t *buffer);
+#endif // _di_f_file_stream_read_until_
+
+/**
* Re-open a file stream.
*
* This allows for re-using an existing file stream and possibly file-descriptor.
* The file path
* @param mode
* The file modes do use when opening.
+ * Set to 0 to determine mode from file.flags (falling back to read only as a failsafe).
+ * If neither truncate nor append are not specified in write only mode, then the failsafe is to append.
* @param file
* The file information.
* The file.stream is updated, if necessary.
#endif // _di_f_file_stream_reopen_
/**
+ * Write until entire buffer is written.
+ *
+ * @param file
+ * The file to write to.
+ * The file must already be open.
+ * @param buffer
+ * The buffer to write to the file.
+ * @param amount
+ * The total amount of file.size_write to process.
+ * This amount is multiplied against file.size_write and must be greater than 0.
+ * @param written
+ * The total bytes written.
+ * Set pointer to 0 to not use.
+ *
+ * @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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fwrite()
+ */
+#ifndef _di_f_file_stream_write_
+ extern f_return_status f_file_stream_write(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, f_string_length_t *written);
+#endif // _di_f_file_stream_write_
+
+/**
+ * Write until a single block is filled or entire buffer is written.
+ *
+ * To check how much was write into the buffer, record buffer->used before execution and compare to buffer->used after execution.
+ *
+ * @param file
+ * The file to write to.
+ * The file must already be open.
+ * @param buffer
+ * The buffer to write to the file.
+ * @param amount
+ * The total amount of file.size_write to process.
+ * This amount is multiplied against file.size_write and must be greater than 0.
+ * @param written
+ * The total bytes written.
+ * Set pointer to 0 to not use.
+ *
+ * @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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fwrite()
+ */
+#ifndef _di_f_file_stream_write_block_
+ extern f_return_status f_file_stream_write_block(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, f_string_length_t *written);
+#endif // _di_f_file_stream_write_block_
+
+/**
+ * Write until a given number or entire buffer is written.
+ *
+ * @param file
+ * The file to write to.
+ * The file must already be open.
+ * @param buffer
+ * The buffer to write to the file.
+ * @param amount
+ * The total amount of file.size_write to process.
+ * This amount is multiplied against file.size_write and must be greater than 0.
+ * @param total
+ * The total bytes to write, unless end of buffer is reached first.
+ * @param written
+ * The total bytes written.
+ * Set pointer to 0 to not use.
+ *
+ * @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_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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fwrite()
+ */
+#ifndef _di_f_file_stream_write_until_
+ extern f_return_status f_file_stream_write_until(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, const f_string_length_t total, f_string_length_t *written);
+#endif // _di_f_file_stream_write_until_
+
+/**
+ * Write a given range within the buffer.
+ *
+ * @param file
+ * The file to write to.
+ * The file must already be open.
+ * @param buffer
+ * The buffer to write to the file.
+ * @param amount
+ * The total amount of file.size_write to process.
+ * This amount is multiplied against file.size_write and must be greater than 0.
+ * @param range
+ * An inclusive start an stop range within the buffer to read.
+ * @param written
+ * The total bytes written.
+ * Set pointer to 0 to not use.
+ *
+ * @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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see fwrite()
+ */
+#ifndef _di_f_file_stream_write_range_
+ extern f_return_status f_file_stream_write_range(const f_file_t file, const f_string_static_t buffer, const f_string_length_t amount, const f_string_range_t range, f_string_length_t *written);
+#endif // _di_f_file_stream_write_range_
+
+
+/**
* Update the files access and modification timestamp, creating the file if it does not already exist.
*
* When the file is created, it is created as a regular file.
}
#endif // !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_)
-#if !defined(f_file_write) || !defined(f_file_write_until) || !defined(f_file_write_range)
+#if !defined(_di_f_file_stream_descriptor_) || !defined(_di_f_file_stream_open_) || !defined(_di_f_file_stream_reopen_)
+ const char *private_f_file_stream_open_mode_determine(const int flag) {
+
+ if (flag & f_file_flag_read_write) {
+ if (flag & f_file_flag_truncate) {
+ return "w+";
+ }
+ else if (flag & f_file_flag_append) {
+ return "a+";
+ }
+
+ // failsafe to read write prepend.
+ return "r+";
+ }
+ else if (flag & f_file_flag_write_only) {
+ if (flag & f_file_flag_truncate) {
+ return "w";
+ }
+
+ // failsafe to append.
+ return "a";
+ }
+
+ // failsafe to read only.
+ return "r";
+ }
+#endif // !defined(_di_f_file_stream_descriptor_) || !defined(_di_f_file_stream_open_) || !defined(_di_f_file_stream_reopen_)
+
+#if !defined(f_file_stream_write) || !defined(_di_f_file_stream_write_block_) || !defined(f_file_stream_write_until) || !defined(f_file_stream_write_range)
+ f_return_status private_f_file_stream_write_until(const f_file_t file, const f_string_t string, const f_string_length_t amount, const f_string_length_t total, f_string_length_t *written) {
+ *written = 0;
+
+ f_status_t status = F_none;
+ f_string_length_t write_amount = amount;
+ f_string_length_t write_size = file.size_write;
+ f_string_length_t write_max = total;
+
+ ssize_t size_write = 0;
+
+ if (write_max < file.size_write) {
+ write_amount = 1;
+ write_size = write_max;
+ }
+ else if (amount * file.size_write > total) {
+ write_amount = total / file.size_write;
+
+ if (total % file.size_write) {
+ write_amount++;
+ }
+ }
+
+ while (*written < write_max) {
+ size_write = fwrite(string + *written, write_amount, write_size, file.stream);
+
+ if (size_write < 0) {
+ 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_interrupted);
+ 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);
+ }
+
+ *written += size_write * write_amount;
+
+ if (!size_write) {
+ return F_none_stop;
+ }
+ } // while
+
+ return F_none;
+ }
+#endif // !defined(f_file_stream_write) || !defined(_di_f_file_stream_write_block_) || !defined(f_file_stream_write_until) || !defined(f_file_stream_write_range)
+
+#if !defined(f_file_write) || !defined(_di_f_file_write_block_) || !defined(f_file_write_until) || !defined(f_file_write_range)
f_return_status private_f_file_write_until(const f_file_t file, const f_string_t string, const f_string_length_t total, f_string_length_t *written) {
*written = 0;
ssize_t size_write = 0;
- if (write_max < write_size) {
+ if (write_max < file.size_write) {
write_size = write_max;
}
return F_none;
}
-#endif // !defined(f_file_write) || !defined(f_file_write_until) || !defined(f_file_write_range)
+#endif // !defined(f_file_write) || !defined(_di_f_file_write_block_) || !defined(f_file_write_until) || !defined(f_file_write_range)
#ifdef __cplusplus
} // extern "C"
#endif // !defined(_di_f_file_stat_by_id_) || !defined(_di_f_file_size_by_id_)
/**
+ * Special function for use in the f_file_stream_open() and related functions.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param flag
+ * The file flag.
+ *
+ * @return
+ * A string representing the file mode for use in fopen(), fdopen(), or freopen().
+ *
+ * @see f_file_stream_descriptor()
+ * @see f_file_stream_open()
+ * @see f_file_stream_reopen()
+ */
+#if !defined(_di_f_file_stream_descriptor_) || !defined(_di_f_file_stream_open_) || !defined(_di_f_file_stream_reopen_)
+ extern const char *private_f_file_stream_open_mode_determine(const int flag) f_gcc_attribute_visibility_internal;
+#endif // !defined(_di_f_file_stream_descriptor_) || !defined(_di_f_file_stream_open_) || !defined(_di_f_file_stream_reopen_)
+
+/**
+ * Private implementation of f_file_stream_write_until().
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param file
+ * The file to write to.
+ * The file must already be open.
+ * @param string
+ * The string to write to the file.
+ * @param amount
+ * The total amount of file.size_write to process.
+ * This amount is multiplied against file.size_write and must be greater than 0.
+ * @param total
+ * The total bytes to write.
+ * @param written
+ * The total bytes to written.
+ *
+ * @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_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_interrupted (with error bit) if interrupt was received.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see f_file_stream_write()
+ * @see f_file_stream_write_block()
+ * @see f_file_stream_write_range()
+ * @see f_file_stream_write_until()
+ */
+#if !defined(f_file_stream_write) || !defined(_di_f_file_stream_write_block_) || !defined(f_file_stream_write_until) || !defined(f_file_stream_write_range)
+ extern f_return_status private_f_file_stream_write_until(const f_file_t file, const f_string_t string, const f_string_length_t amount, const f_string_length_t total, f_string_length_t *written) f_gcc_attribute_visibility_internal;
+#endif // !defined(f_file_stream_write) || !defined(_di_f_file_stream_write_block_) || !defined(f_file_stream_write_until) || !defined(f_file_stream_write_range)
+
+/**
* Private implementation of f_file_write_until().
*
* Intended to be shared to each of the different implementation variations.
* F_parameter (with error bit) if a parameter is invalid.
*
* @see f_file_write()
+ * @see f_file_write_block()
* @see f_file_write_range()
* @see f_file_write_until()
*/
-#if !defined(f_file_write) || !defined(f_file_write_until) || !defined(f_file_write_range)
+#if !defined(f_file_write) || !defined(_di_f_file_write_block_) || !defined(f_file_write_until) || !defined(f_file_write_range)
extern f_return_status private_f_file_write_until(const f_file_t file, const f_string_t string, const f_string_length_t total, f_string_length_t *written) f_gcc_attribute_visibility_internal;
-#endif // !defined(f_file_write) || !defined(f_file_write_until) || !defined(f_file_write_range)
+#endif // !defined(f_file_write) || !defined(_di_f_file_write_block_) || !defined(f_file_write_until) || !defined(f_file_write_range)
#ifdef __cplusplus
} // extern "C"
missing_files = status;
}
- fll_error_file_print(data.error, F_status_set_fine(status), "f_file_exists", F_true, arguments.argv[data->remaining.array[counter]], "find", fll_error_file_type_file);
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_exists", F_true, arguments.argv[data->remaining.array[counter]], "find", fll_error_file_type_file);
}
} // for
f_file_t file = f_file_t_initialize;
for (f_array_length_t counter = 0; counter < data->remaining.used; counter++) {
+
status = f_file_open(arguments.argv[data->remaining.array[counter]], 0, &file);
if (F_status_is_error(status)) {
- fll_error_file_print(data.error, F_status_set_fine(status), "f_file_open", F_true, arguments.argv[data->remaining.array[counter]], "open", fll_error_file_type_file);
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_open", F_true, arguments.argv[data->remaining.array[counter]], "open", fll_error_file_type_file);
byte_dump_delete_data(data);
return status;
f_file_close(&file.id);
if (F_status_is_error(status)) {
- fll_error_file_print(data.error, F_status_set_fine(status), "byte_dump_file", F_true, arguments.argv[data->remaining.array[counter]], "open", fll_error_file_type_file);
+ fll_error_file_print(data->error, F_status_set_fine(status), "byte_dump_file", F_true, arguments.argv[data->remaining.array[counter]], "process", fll_error_file_type_file);
byte_dump_delete_data(data);
return status;
fprintf(data.output.stream, "%c", f_string_eol[0]);
// make sure to flush standard out to help prevent standard error from causing poblems.
- fflush(f_type_output);
+ fflush(data.output.stream);
if (found_invalid_utf) {
fl_color_print(data.error.to.stream, data.context.set.error, "Invalid UTF-8 codes were detected for file '");
status = F_status_set_error(F_failure);
}
- fflush(f_type_error);
+ fflush(data.error.to.stream);
return status;
}
fprintf(data.output.stream, "%c", f_string_eol[0]);
// flush to stdout before executing command.
- fflush(f_type_output);
+ fflush(data.output.stream);
}
if (fake_signal_received(data)) {
}
name_function = "f_file_open";
- status = f_file_open(path_file, 0, &file);
+ status = f_file_stream_open(path_file, 0, &file);
if (fake_signal_received(data)) {
if (file.id) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
}
return F_status_set_error(F_signal);
name_function = "f_file_read";
status = f_file_read(file, buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
}
}
else if (status == F_false) {
return status;
}
- status = f_directory_open(data_make.path.stack.array[0].string, F_false, &data_make.path.top);
+ status = f_directory_open(data_make.path.stack.array[0].string, F_false, &data_make.path.top.id);
if (F_status_is_error(status)) {
fll_error_print(data.error, F_status_set_fine(status), "f_directory_open", F_true);
fake_make_operate_section(data, data_make.main, &data_make, §ion_stack, &status);
- if (data_make.path.current > 0) {
- f_file_close(&data_make.path.current);
+ if (data_make.path.current.stream) {
+ f_file_stream_close(F_true, &data_make.path.current);
}
{
- f_status_t status_path = f_path_change_at(data_make.path.top);
+ f_status_t status_path = f_path_change_at(data_make.path.top.id);
if (F_status_is_error(status_path) && data.error.verbosity == f_console_verbosity_verbose) {
fprintf(data.output.stream, "%c", f_string_eol[0]);
}
}
- f_file_close(&data_make.path.top);
+ f_file_stream_close(F_true, &data_make.path.top);
f_macro_string_lengths_t_delete_simple(section_stack);
fake_macro_make_data_t_delete_simple(data_make);
if (operation == fake_make_operation_type_top) {
- *status = f_path_change_at(data_make->path.top);
+ *status = f_path_change_at(data_make->path.top.id);
if (F_status_is_error(*status)) {
fake_print_message_section_operation_path_stack_max(data, data_make->error, F_status_set_fine(*status), "f_path_change", arguments.array[0].string);
fprintf(data.output.stream, "%c", f_string_eol[0]);
// flush to stdout before executing command.
- fflush(f_type_output);
+ fflush(data.output.stream);
}
int return_code = 0;
#ifndef _di_fake_make_path_t_
typedef struct {
- int top;
- int current;
+ f_file_t top;
+ f_file_t current;
f_string_dynamics_t stack;
} fake_make_path_t;
#define fake_make_path_t_initialize { \
- 0, \
- 0, \
+ f_file_t_initialize, \
+ f_file_t_initialize, \
f_string_dynamics_t_initialize, \
}
fake_environment_t environment;
fake_make_parameter_t parameter;
- fake_make_path_t path;
+ fake_make_path_t path; // @todo review this, check if path.current is used anymore.
fll_error_print_t error;
if (F_status_is_error(status)) {
fll_error_file_print(data.error, F_status_set_fine(status), "f_file_write", F_true, path.string, "pre-populate", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
return status;
}
fprintf(data.output.stream, "File '%s' pre-populated.%c", path.string, f_string_eol[0]);
}
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
}
}
else if (F_status_is_error(status)) {
data.process_pipe = F_true;
}
- f_status_t status = firewall_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(firewall_main(arguments, &data))) {
return 1;
}
status = F_status_set_error(status);
}
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
}
else {
status = f_file_read(file, &local_buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
status = F_status_set_fine(status);
status = f_file_read(file, &local->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
status = F_status_set_fine(status);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_size_by_id", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
macro_fss_basic_list_read_depths_t_delete_simple(depths);
fss_basic_list_read_delete_data(data);
// Skip past empty files.
if (!data->quantity.total) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
continue;
}
}
status = f_file_read_until(file, data->quantity.total, &data->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_until", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
data.process_pipe = F_true;
}
- f_status_t status = fss_basic_list_read_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_basic_list_read_main(arguments, &data))) {
return 1;
}
printf("%c", f_string_eol[0]);
+ fll_program_print_help_option(file, context, fss_basic_list_write_short_file, fss_basic_list_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_basic_list_write_short_content, fss_basic_list_write_long_content, f_console_symbol_short_enable, f_console_symbol_long_enable, " The content to output.");
fll_program_print_help_option(file, context, fss_basic_list_write_short_double, fss_basic_list_write_long_double, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use double quotes (default).");
- fll_program_print_help_option(file, context, fss_basic_list_write_short_file, fss_basic_list_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_basic_list_write_short_object, fss_basic_list_write_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " The object to output.");
fll_program_print_help_option(file, context, fss_basic_list_write_short_partial, fss_basic_list_write_long_partial, f_console_symbol_short_enable, f_console_symbol_long_enable, "Do not output end of object/content character.");
fll_program_print_help_option(file, context, fss_basic_list_write_short_single, fss_basic_list_write_long_single, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use single quotes.");
status = f_file_open(arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]], 0, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- f_file_close(&output.id);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_found_not) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to find the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_open) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_descriptor) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sFile descriptor error while trying to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_flag_append_wo", F_true, file.string, "open", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_basic_list_write_delete_data(data);
- return F_status_set_error(status);
+ return status;
}
status = f_file_write(output, buffer, 0);
- f_file_close(&output.id);
+ f_file_stream_close(F_true, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_write()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_write) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to write to the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_write()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_close", F_true, file.string, "close", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_basic_list_write_delete_data(data);
- return F_status_set_error(status);
+ return status;
}
}
else {
#endif // _di_fss_basic_list_write_name_
#ifndef _di_fss_basic_list_write_defines_
+ #define fss_basic_list_write_short_file "f"
#define fss_basic_list_write_short_content "c"
#define fss_basic_list_write_short_double "d"
- #define fss_basic_list_write_short_file "f"
#define fss_basic_list_write_short_object "o"
#define fss_basic_list_write_short_partial "p"
#define fss_basic_list_write_short_single "s"
+ #define fss_basic_list_write_long_file "file"
#define fss_basic_list_write_long_content "content"
#define fss_basic_list_write_long_double "double"
- #define fss_basic_list_write_long_file "file"
#define fss_basic_list_write_long_object "object"
#define fss_basic_list_write_long_partial "partial"
#define fss_basic_list_write_long_single "single"
fss_basic_list_write_parameter_verbosity_debug,
fss_basic_list_write_parameter_version,
+ fss_basic_list_write_parameter_file,
fss_basic_list_write_parameter_content,
fss_basic_list_write_parameter_double,
- fss_basic_list_write_parameter_file,
fss_basic_list_write_parameter_object,
fss_basic_list_write_parameter_partial,
fss_basic_list_write_parameter_single,
f_console_parameter_t_initialize(f_console_standard_short_verbose, f_console_standard_long_verbose, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_debug, f_console_standard_long_debug, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, F_false, f_console_type_inverse), \
+ f_console_parameter_t_initialize(fss_basic_list_write_short_file, fss_basic_list_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_list_write_short_content, fss_basic_list_write_long_content, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_list_write_short_double, fss_basic_list_write_long_double, 0, F_true, f_console_type_normal), \
- f_console_parameter_t_initialize(fss_basic_list_write_short_file, fss_basic_list_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_list_write_short_object, fss_basic_list_write_long_object, 0, F_false, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_list_write_short_partial, fss_basic_list_write_long_partial, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_list_write_short_single, fss_basic_list_write_long_single, 0, F_true, f_console_type_normal), \
data.process_pipe = F_true;
}
- f_status_t status = fss_basic_list_write_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_basic_list_write_main(arguments, &data))) {
return 1;
}
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_size_by_id", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
macro_fss_basic_read_depths_t_delete_simple(depths);
fss_basic_read_delete_data(data);
// Skip past empty files.
if (!data->quantity.total) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
continue;
}
}
status = f_file_read_until(file, data->quantity.total, &data->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_until", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
data.process_pipe = F_true;
}
- f_status_t status = fss_basic_read_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_basic_read_main(arguments, &data))) {
return 1;
}
printf("%c", f_string_eol[0]);
+ fll_program_print_help_option(file, context, fss_basic_write_short_file, fss_basic_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_basic_write_short_content, fss_basic_write_long_content, f_console_symbol_short_enable, f_console_symbol_long_enable, " The content to output.");
fll_program_print_help_option(file, context, fss_basic_write_short_double, fss_basic_write_long_double, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use double quotes (default).");
- fll_program_print_help_option(file, context, fss_basic_write_short_file, fss_basic_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_basic_write_short_object, fss_basic_write_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " The object to output.");
fll_program_print_help_option(file, context, fss_basic_write_short_partial, fss_basic_write_long_partial, f_console_symbol_short_enable, f_console_symbol_long_enable, "Do not output end of object/content character.");
fll_program_print_help_option(file, context, fss_basic_write_short_single, fss_basic_write_long_single, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use single quotes.");
}
f_array_length_t counter = 0;
- bool object = (data->parameters[fss_basic_write_parameter_object].result == f_console_result_found);
+ bool object = data->parameters[fss_basic_write_parameter_object].result == f_console_result_found;
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
f_string_range_t range = f_string_range_t_initialize;
status = f_file_read(file, &input);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_found_not) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to find the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else if (status == F_file_open) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to open the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else if (status == F_file_descriptor) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sFile descriptor error while trying to open the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read", F_true, file.string, "read", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(input);
fss_basic_write_delete_data(data);
status = f_file_open(arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]], 0, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- f_file_close(&output.id);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_found_not) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to find the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_open) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_descriptor) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sFile descriptor error while trying to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_open", F_true, file.string, "open", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_basic_write_delete_data(data);
}
status = f_file_write(output, buffer, 0);
- f_file_close(&output.id);
+ f_file_stream_close(F_true, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_write()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_write) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to write to the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_write()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_stream_close", F_true, file.string, "close", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_basic_write_delete_data(data);
- return F_status_set_error(status);
+ return status;
}
}
else {
#endif // _di_fss_basic_write_name_
#ifndef _di_fss_basic_write_defines_
+ #define fss_basic_write_short_file "f"
#define fss_basic_write_short_content "c"
#define fss_basic_write_short_double "d"
- #define fss_basic_write_short_file "f"
#define fss_basic_write_short_object "o"
#define fss_basic_write_short_partial "p"
#define fss_basic_write_short_single "s"
+ #define fss_basic_write_long_file "file"
#define fss_basic_write_long_content "content"
#define fss_basic_write_long_double "double"
- #define fss_basic_write_long_file "file"
#define fss_basic_write_long_object "object"
#define fss_basic_write_long_partial "partial"
#define fss_basic_write_long_single "single"
fss_basic_write_parameter_verbosity_debug,
fss_basic_write_parameter_version,
+ fss_basic_write_parameter_file,
fss_basic_write_parameter_content,
fss_basic_write_parameter_double,
- fss_basic_write_parameter_file,
fss_basic_write_parameter_object,
fss_basic_write_parameter_partial,
fss_basic_write_parameter_single,
f_console_parameter_t_initialize(f_console_standard_short_verbose, f_console_standard_long_verbose, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_debug, f_console_standard_long_debug, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, F_false, f_console_type_inverse), \
+ f_console_parameter_t_initialize(fss_basic_write_short_file, fss_basic_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_write_short_content, fss_basic_write_long_content, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_write_short_double, fss_basic_write_long_double, 0, F_true, f_console_type_normal), \
- f_console_parameter_t_initialize(fss_basic_write_short_file, fss_basic_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_write_short_object, fss_basic_write_long_object, 0, F_false, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_write_short_partial, fss_basic_write_long_partial, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_basic_write_short_single, fss_basic_write_long_single, 0, F_true, f_console_type_normal), \
const f_console_arguments_t arguments = { argc, argv };
fss_basic_write_data data = fss_basic_write_data_initialize;
- f_status_t status = fss_basic_write_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_basic_write_main(arguments, &data))) {
return 1;
}
if (data->parameters[fss_extended_list_read_parameter_help].result == f_console_result_found) {
fss_extended_list_read_print_help(data->output, data->context);
- fss_extended_list_write_delete_data(data);
+ fss_extended_list_read_delete_data(data);
return F_none;
}
if (data->parameters[fss_extended_list_read_parameter_version].result == f_console_result_found) {
fll_program_print_version(data->output, fss_extended_list_read_version);
- fss_extended_list_write_delete_data(data);
+ fss_extended_list_read_delete_data(data);
return F_none;
}
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_size_by_id", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
macro_fss_extended_list_read_depths_t_delete_simple(depths);
fss_extended_list_read_delete_data(data);
// Skip past empty files.
if (!data->quantity.total) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
continue;
}
}
status = f_file_read_until(file, data->quantity.total, &data->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_until", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
data.process_pipe = F_true;
}
- f_status_t status = fss_extended_list_read_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_extended_list_read_main(arguments, &data))) {
return 1;
}
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_size_by_id", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
macro_fss_extended_read_depths_t_delete_simple(depths);
fss_extended_read_delete_data(data);
// Skip past empty files.
if (!data->quantity.total) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
continue;
}
}
status = f_file_read_until(file, data->quantity.total, &data->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_until", F_true, arguments.argv[data->remaining.array[counter]], "read", fll_error_file_type_file);
data.process_pipe = F_true;
}
- f_status_t status = fss_extended_read_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_extended_read_main(arguments, &data))) {
return 1;
}
printf("%c", f_string_eol[0]);
+ fll_program_print_help_option(file, context, fss_extended_write_short_file, fss_extended_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_extended_write_short_content, fss_extended_write_long_content, f_console_symbol_short_enable, f_console_symbol_long_enable, " The content to output.");
fll_program_print_help_option(file, context, fss_extended_write_short_double, fss_extended_write_long_double, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use double quotes (default).");
- fll_program_print_help_option(file, context, fss_extended_write_short_file, fss_extended_write_long_file, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a file to send output to.");
fll_program_print_help_option(file, context, fss_extended_write_short_object, fss_extended_write_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " The object to output.");
fll_program_print_help_option(file, context, fss_extended_write_short_partial, fss_extended_write_long_partial, f_console_symbol_short_enable, f_console_symbol_long_enable, "Do not output end of object/content character.");
fll_program_print_help_option(file, context, fss_extended_write_short_single, fss_extended_write_long_single, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use single quotes.");
}
f_array_length_t counter = 0;
- bool object = (data->parameters[fss_extended_write_parameter_object].result == f_console_result_found);
+ bool object = data->parameters[fss_extended_write_parameter_object].result == f_console_result_found;
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
f_string_range_t range = f_string_range_t_initialize;
status = f_file_read(file, &input);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_found_not) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to find the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else if (status == F_file_open) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to open the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else if (status == F_file_descriptor) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sFile descriptor error while trying to open the file '%s'%c", fll_error_print_error, "-", f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read", F_true, file.string, "read", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(input);
fss_extended_write_delete_data(data);
- return F_status_set_error(status);
+ return status;
}
if (input.used) {
status = f_file_open(arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]], 0, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- f_file_close(&output.id);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_open()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_found_not) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to find the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_open) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else if (status == F_file_descriptor) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sFile descriptor error while trying to open the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_open()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_open", F_true, file.string, "open", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_extended_write_delete_data(data);
}
status = f_file_write(output, buffer, 0);
- f_file_close(&output.id);
+ f_file_stream_close(F_true, &output);
if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
-
- if (status == F_parameter) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sInvalid parameter when calling f_file_write()%c", fll_error_print_error, f_string_eol[0]);
- }
- else if (status == F_file_write) {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sUnable to write to the file '%s'%c", fll_error_print_error, arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]], f_string_eol[0]);
- }
- else {
- fl_color_print(data->error.to.stream, data->context.set.error, "%sAn unhandled error (%u) has occurred while calling f_file_write()%c", fll_error_print_error, status, f_string_eol[0]);
- }
+ fll_error_file_print(data->error, F_status_set_fine(status), "f_file_close", F_true, file.string, "close", fll_error_file_type_file);
f_macro_string_dynamic_t_delete_simple(buffer);
fss_extended_write_delete_data(data);
- return F_status_set_error(status);
+ return status;
}
}
else {
#endif // _di_fss_extended_write_name_
#ifndef _di_fss_extended_write_defines_
+ #define fss_extended_write_short_file "f"
#define fss_extended_write_short_content "c"
#define fss_extended_write_short_double "d"
- #define fss_extended_write_short_file "f"
#define fss_extended_write_short_object "o"
#define fss_extended_write_short_partial "p"
#define fss_extended_write_short_single "s"
+ #define fss_extended_write_long_file "file"
#define fss_extended_write_long_content "content"
#define fss_extended_write_long_double "double"
- #define fss_extended_write_long_file "file"
#define fss_extended_write_long_object "object"
#define fss_extended_write_long_partial "partial"
#define fss_extended_write_long_single "single"
fss_extended_write_parameter_verbosity_debug,
fss_extended_write_parameter_version,
+ fss_extended_write_parameter_file,
fss_extended_write_parameter_content,
fss_extended_write_parameter_double,
- fss_extended_write_parameter_file,
fss_extended_write_parameter_object,
fss_extended_write_parameter_partial,
fss_extended_write_parameter_single,
f_console_parameter_t_initialize(f_console_standard_short_verbose, f_console_standard_long_verbose, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_debug, f_console_standard_long_debug, 0, 0, f_console_type_inverse), \
f_console_parameter_t_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, F_false, f_console_type_inverse), \
+ f_console_parameter_t_initialize(fss_extended_write_short_file, fss_extended_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_extended_write_short_content, fss_extended_write_long_content, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_extended_write_short_double, fss_extended_write_long_double, 0, F_true, f_console_type_normal), \
- f_console_parameter_t_initialize(fss_extended_write_short_file, fss_extended_write_long_file, 0, F_true, f_console_type_normal), \
f_console_parameter_t_initialize(fss_extended_write_short_object, fss_extended_write_long_object, 0, F_false, f_console_type_normal), \
f_console_parameter_t_initialize(fss_extended_write_short_partial, fss_extended_write_long_partial, 0, F_false, f_console_type_normal), \
f_console_parameter_t_initialize(fss_extended_write_short_single, fss_extended_write_long_single, 0, F_true, f_console_type_normal), \
data.process_pipe = F_true;
}
- f_status_t status = fss_extended_write_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(fss_extended_write_main(arguments, &data))) {
return 1;
}
data.process_pipe = F_true;
}
- f_status_t status = fss_status_code_main(arguments, &data);
+ const f_status_t status = fss_status_code_main(arguments, &data);
if (F_status_is_error(status) || status == F_false) {
return 1;
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_size_by_id", F_true, arguments.argv[data->remaining.array[i]], "process", fll_error_file_type_file);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
break;
}
// Skip past empty files.
if (!total) {
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
continue;
}
status = f_file_read_until(file, total, &data->buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_until", F_true, arguments.argv[data->remaining.array[i]], "process", fll_error_file_type_file);
data.process_pipe = F_true;
}
- f_status_t status = iki_read_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(iki_read_main(arguments, &data))) {
return 1;
}
fll_program_print_help_option(file, context, iki_write_short_object, iki_write_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " The object to output.");
fll_program_print_help_option(file, context, iki_write_short_single, iki_write_long_single, f_console_symbol_short_enable, f_console_symbol_long_enable, " Use single quotes.");
- fll_program_print_help_usage(file, context, iki_write_name, "filename(s)");
+ fll_program_print_help_usage(file, context, iki_write_name, "");
fl_color_print(f_type_output, context.set.important, " Notes:");
f_string_dynamic_t escaped = f_string_dynamic_t_initialize;
if (data->process_pipe) {
- f_file_t file = f_file_t_initialize;
+ f_file_t input = f_file_t_initialize;
- file.id = f_type_descriptor_input;
- file.size_read = 1;
+ input.id = f_type_descriptor_input;
+ input.size_read = 1;
f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
f_string_dynamic_t object = f_string_dynamic_t_initialize;
for (f_status_t status_pipe = F_none; ; ) {
if (status_pipe != F_none_eof) {
- status_pipe = f_file_read(file, &buffer);
+ status_pipe = f_file_read(input, &buffer);
if (F_status_is_error(status_pipe)) {
fll_error_file_print(data->error, F_status_set_fine(status), "f_file_read_to", F_true, "-", "read", fll_error_file_type_pipe);
}
}
- status = iki_write_process(*data, object, content, quote, output.id, &escaped);
+ status = iki_write_process(*data, data->output, object, content, quote, &escaped);
if (F_status_is_error(status)) break;
- dprintf(output.id, "%c", f_string_eol[0]);
+ fprintf(output.stream, "%c", f_string_eol[0]);
object_ended = F_false;
}
content.used = strnlen(content.string, f_console_length_size);
content.size = content.used;
- status = iki_write_process(*data, object, content, quote, output.id, &escaped);
+ status = iki_write_process(*data, data->output, object, content, quote, &escaped);
if (F_status_is_error(status)) break;
- dprintf(output.id, "%c", f_string_eol[0]);
+ fprintf(output.stream, "%c", f_string_eol[0]);
} // for
// ensure there is always a newline at the end, unless in quiet mode.
if (data->parameters[iki_write_parameter_file].result == f_console_result_additional) {
if (output.id != -1) {
- f_file_close(&output.id);
+ f_file_stream_close(F_true, &output);
}
}
data.process_pipe = F_true;
}
- f_status_t status = iki_write_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(iki_write_main(arguments, &data))) {
return 1;
}
#endif
#ifndef _di_iki_write_process_
- f_return_status iki_write_process(const iki_write_data_t data, const f_string_static_t object, const f_string_static_t content, const uint8_t quote, const int output, f_string_dynamic_t *escaped) {
+ f_return_status iki_write_process(const iki_write_data_t data, const f_file_t output, const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_string_dynamic_t *escaped) {
if (!object.used) {
if (data.error.verbosity != f_console_verbosity_quiet) {
return F_status_set_error(F_failure);
}
- dprintf(output, "%s%c%c%s%c", object.string, f_iki_syntax_separator, quote, escaped->string, quote);
+ fprintf(output.stream, "%s%c%c%s%c", object.string, f_iki_syntax_separator, quote, escaped->string, quote);
return F_none;
}
*
* @param data
* The program data.
+ * @param output
+ * The file to output to.
* @param object
* The object to validate and print.
* @param content
* @param quote
* The quote character to use.
* This is either f_iki_syntax_quote_single or f_iki_syntax_quote_double.
- * @param output
- * The output file descriptor to print processed iki text to.
* @param escaped
* A string buffer used as a string cache to save the string into while escaping.
*
* F_failure (with error bit) for any othe failure.
*/
#ifndef _di_iki_write_process_
- extern f_return_status iki_write_process(const iki_write_data_t data, const f_string_static_t object, const f_string_static_t content, const uint8_t quote, const int output, f_string_dynamic_t *escaped) f_gcc_attribute_visibility_internal;
+ extern f_return_status iki_write_process(const iki_write_data_t data, const f_file_t output, const f_string_static_t object, const f_string_static_t content, const uint8_t quote, f_string_dynamic_t *escaped) f_gcc_attribute_visibility_internal;
#endif // _di_iki_write_process_
#ifdef __cplusplus
data.process_pipe = F_true;
}
- f_status_t status = init_main(arguments, &data);
-
- if (F_status_is_error(status)) {
+ if (F_status_is_error(init_main(arguments, &data))) {
return 1;
}
f_macro_file_t_reset_position(quantity, file)
- fflush(stdout);
+ fflush(data.output.stream);
status = f_file_read_until(file, quantity, buffer);
- f_file_close(&file.id);
+ f_file_stream_close(F_true, &file);
if (F_status_is_error(status)) {
status = F_status_set_fine(status);
data.process_pipe = F_true;
}
- f_status_t status = status_code_main(arguments, &data);
+ const f_status_t status = status_code_main(arguments, &data);
if (F_status_is_error(status) || status == F_false) {
return 1;