2019-03-26 14:35:33 +00:00
|
|
|
#include "wsfs/provider/impl/dirbuffer.h"
|
2019-03-03 12:34:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
struct wsfsp_dirbuffer * wsfsp_impl_dirbuffer_create(void)
|
2019-03-03 12:34:43 +00:00
|
|
|
{
|
|
|
|
struct wsfsp_dirbuffer * buffer = malloc(sizeof(struct wsfsp_dirbuffer));
|
|
|
|
if (NULL != buffer)
|
|
|
|
{
|
|
|
|
buffer->entries = json_array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
void wsfsp_impl_dirbuffer_dispose(
|
2019-03-03 12:34:43 +00:00
|
|
|
struct wsfsp_dirbuffer * buffer)
|
|
|
|
{
|
|
|
|
if (NULL != buffer->entries)
|
|
|
|
{
|
|
|
|
json_decref(buffer->entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
void wsfsp_impl_dirbuffer_add(
|
2019-03-03 12:34:43 +00:00
|
|
|
struct wsfsp_dirbuffer * buffer,
|
|
|
|
char const * name,
|
|
|
|
ino_t inode)
|
|
|
|
{
|
|
|
|
json_t * entry = json_object();
|
|
|
|
json_object_set_new(entry, "name", json_string(name));
|
|
|
|
json_object_set_new(entry, "inode", json_integer(inode));
|
|
|
|
|
2019-03-03 14:15:55 +00:00
|
|
|
json_array_append_new(buffer->entries, entry);
|
2019-03-03 12:34:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
json_t * wsfsp_impl_dirbuffer_take(
|
2019-03-03 12:34:43 +00:00
|
|
|
struct wsfsp_dirbuffer * buffer)
|
|
|
|
{
|
|
|
|
json_t * entries = buffer->entries;
|
|
|
|
|
|
|
|
buffer->entries = NULL;
|
|
|
|
return entries;
|
|
|
|
}
|