Create libioutil, implement a filewriter
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m21s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m21s
This commit is contained in:
29
ce/ce.c
29
ce/ce.c
@@ -1,5 +1,6 @@
|
||||
#include <arena.h>
|
||||
#include <desc.h>
|
||||
#include <filewriter.h>
|
||||
#include <liballoc.h>
|
||||
#include <list.h>
|
||||
#include <minmax.h>
|
||||
@@ -546,15 +547,33 @@ static void execute_redir (struct ast_redir* redir, struct context* context) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = volume_open (volume)) < 0) {
|
||||
cprintf (context, "ERROR could not open volume '%s': %s\n", volume, str_status[-ret]);
|
||||
struct filewriter fw;
|
||||
if ((ret = filewriter_init (&fw, volume, path, FW_CREATE_FILE | FW_APPEND)) < 0) {
|
||||
cprintf (context, "ERROR could not initialize filewriter for '%s:%s'\n", volume, path);
|
||||
return;
|
||||
}
|
||||
|
||||
create_file (path);
|
||||
write_file (path, 0, (uint8_t*)context->strbuf.items, context->strbuf.count - 1);
|
||||
size_t chunk_size = 1024;
|
||||
size_t chunks = (context->strbuf.count - 1) / chunk_size;
|
||||
size_t rem = (context->strbuf.count - 1) % chunk_size;
|
||||
|
||||
volume_close ();
|
||||
for (size_t chunk = 0; chunk < chunks; chunk++) {
|
||||
if ((ret = filewriter_write (&fw, (uint8_t*)&context->strbuf.items[chunk * chunk_size],
|
||||
chunk_size)) < 0) {
|
||||
filewriter_fini (&fw);
|
||||
cprintf (context, "ERROR filewriter failed to write to '%s:%s'\n", volume, path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = filewriter_write (&fw, (uint8_t*)&context->strbuf.items[chunks * chunk_size], rem)) <
|
||||
0) {
|
||||
filewriter_fini (&fw);
|
||||
cprintf (context, "ERROR filewriter failed to write to '%s:%s'\n", volume, path);
|
||||
return;
|
||||
}
|
||||
|
||||
filewriter_fini (&fw);
|
||||
}
|
||||
|
||||
static void execute (struct ast_node* root, struct context* context) {
|
||||
|
||||
Reference in New Issue
Block a user