mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
made static_filesystem private (used for test purposes only)
This commit is contained in:
@@ -1,116 +0,0 @@
|
||||
#include "webfuse/core/path.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WF_PATH_DEFAULT_CAPACITY (8)
|
||||
|
||||
struct wf_path
|
||||
{
|
||||
char * * elements;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
static void
|
||||
wf_path_add(
|
||||
struct wf_path * path,
|
||||
char const * element,
|
||||
size_t element_size)
|
||||
{
|
||||
if (0 < element_size)
|
||||
{
|
||||
if (path->count >= path->capacity)
|
||||
{
|
||||
size_t new_capacity = 2 * path->capacity;
|
||||
size_t new_size = sizeof(char*) * new_capacity;
|
||||
|
||||
char * * elements = realloc(path->elements, new_size);
|
||||
if (NULL != elements)
|
||||
{
|
||||
path->elements = elements;
|
||||
path->capacity = new_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
if (path->count < path->capacity)
|
||||
{
|
||||
path->elements[path->count] = strndup(element, element_size);
|
||||
path->count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct wf_path *
|
||||
wf_path_create(
|
||||
char const * value)
|
||||
{
|
||||
struct wf_path * path = malloc(sizeof(struct wf_path));
|
||||
if (NULL != path)
|
||||
{
|
||||
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
|
||||
path->capacity = WF_PATH_DEFAULT_CAPACITY;
|
||||
path->count = 0;
|
||||
|
||||
char const * remainder = value;
|
||||
char const * pos = strchr(remainder, '/');
|
||||
while (NULL != pos)
|
||||
{
|
||||
wf_path_add(path, remainder, (pos - remainder));
|
||||
remainder = pos + 1;
|
||||
pos = strchr(remainder, '/');
|
||||
}
|
||||
|
||||
wf_path_add(path, remainder, strlen(remainder));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void
|
||||
wf_path_dispose(
|
||||
struct wf_path * path)
|
||||
{
|
||||
for(size_t i = 0; i < path->count; i++)
|
||||
{
|
||||
free(path->elements[i]);
|
||||
}
|
||||
|
||||
free(path->elements);
|
||||
free(path);
|
||||
(void) path;
|
||||
}
|
||||
|
||||
size_t
|
||||
wf_path_element_count(
|
||||
struct wf_path * path)
|
||||
{
|
||||
return path->count;
|
||||
}
|
||||
|
||||
char const *
|
||||
wf_path_get_element(
|
||||
struct wf_path * path,
|
||||
size_t i)
|
||||
{
|
||||
char const * result = NULL;
|
||||
if (i < path->count)
|
||||
{
|
||||
result = path->elements[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char const *
|
||||
wf_path_get_filename(
|
||||
struct wf_path * path)
|
||||
{
|
||||
char const * result = NULL;
|
||||
|
||||
if (0 < path->count)
|
||||
{
|
||||
result = path->elements[path->count - 1];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef WF_PATH_H
|
||||
#define WF_PATH_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
using ::std::size_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_path;
|
||||
|
||||
extern struct wf_path *
|
||||
wf_path_create(
|
||||
char const * value);
|
||||
|
||||
extern void
|
||||
wf_path_dispose(
|
||||
struct wf_path * path);
|
||||
|
||||
extern size_t
|
||||
wf_path_element_count(
|
||||
struct wf_path * path);
|
||||
|
||||
extern char const *
|
||||
wf_path_get_element(
|
||||
struct wf_path * path,
|
||||
size_t i);
|
||||
|
||||
extern char const *
|
||||
wf_path_get_filename(
|
||||
struct wf_path * path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user