add path impl for linux
This commit is contained in:
parent
ab099339b2
commit
e42a53786a
44
fs_linux.c
Normal file
44
fs_linux.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* fs_linux.c
|
||||
*
|
||||
* Created on: 20.10.2017
|
||||
* Author: julian
|
||||
*/
|
||||
#include "fs.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void create_path(struct path * p, const char * fsPath) {
|
||||
free_path(p);
|
||||
|
||||
const char *start = fsPath, *current = fsPath;
|
||||
|
||||
if (*start == '/') {
|
||||
// absolute path
|
||||
p->absolute = 1;
|
||||
current = ++start;
|
||||
}
|
||||
|
||||
for (;*current != '\0'; ++current) {
|
||||
if (*current == '/') {
|
||||
p->entries = realloc(p->entries, sizeof(p->entries[0]) * (p->len+1));
|
||||
p->entries[p->len] = strndup(start, current-start);
|
||||
|
||||
// skip delimiter
|
||||
start = current+1;
|
||||
p->len++;
|
||||
}
|
||||
}
|
||||
|
||||
if (start != current) {
|
||||
p->entries = realloc(p->entries, sizeof(p->entries[0]) *(p->len+1));
|
||||
p->entries[p->len] = strdup(start);
|
||||
p->len++;
|
||||
}
|
||||
}
|
||||
|
||||
FILE * path_fopen(struct path * p, const char * flags) {
|
||||
// reconstruct system path
|
||||
return NULL;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user