mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
refactored read opertation
This commit is contained in:
parent
4396dddd2b
commit
a58d15db6a
@ -11,24 +11,23 @@
|
|||||||
#define WSFS_MAX_READ_LENGTH 4096
|
#define WSFS_MAX_READ_LENGTH 4096
|
||||||
|
|
||||||
static wsfs_status wsfs_fill_buffer(
|
static wsfs_status wsfs_fill_buffer(
|
||||||
char * buffer,
|
char * * buffer,
|
||||||
size_t buffer_size,
|
|
||||||
char const * format,
|
char const * format,
|
||||||
char const * data,
|
char const * data,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
wsfs_status status = WSFS_GOOD;
|
wsfs_status status = WSFS_GOOD;
|
||||||
|
|
||||||
size_t const copy_count = (buffer_size < count) ? buffer_size : count;
|
if (0 < count)
|
||||||
if (0 < copy_count)
|
|
||||||
{
|
{
|
||||||
|
*buffer = malloc(count);
|
||||||
if (0 == strcmp("identity", format))
|
if (0 == strcmp("identity", format))
|
||||||
{
|
{
|
||||||
strncpy(buffer, data, copy_count);
|
memcpy(*buffer, data, count);
|
||||||
}
|
}
|
||||||
else if (0 == strcmp("base64", format))
|
else if (0 == strcmp("base64", format))
|
||||||
{
|
{
|
||||||
lws_b64_decode_string(data, buffer, copy_count);
|
lws_b64_decode_string(data, *buffer, count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -58,9 +57,8 @@ static void wsfs_operation_read_finished(void * user_data, wsfs_status status, j
|
|||||||
char const * const data = json_string_value(data_holder);
|
char const * const data = json_string_value(data_holder);
|
||||||
char const * const format = json_string_value(format_holder);
|
char const * const format = json_string_value(format_holder);
|
||||||
length = (size_t) json_integer_value(count_holder);
|
length = (size_t) json_integer_value(count_holder);
|
||||||
buffer = malloc(length);
|
|
||||||
|
|
||||||
status = wsfs_fill_buffer(buffer, length, format, data, length);
|
status = wsfs_fill_buffer(&buffer, format, data, length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user