path_concat
This commit is contained in:
parent
e2ecfc3d27
commit
5e35cb6721
38
src/Filesystem/filesystem.c
Normal file
38
src/Filesystem/filesystem.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "filesystem.h"
|
||||||
|
|
||||||
|
char* __path_concat(uint16 n, char* prev_part, ...){
|
||||||
|
char** parts=(char**)malloc(n*sizeof(char*));
|
||||||
|
uint32* lengths=malloc(n*sizeof(uint32));
|
||||||
|
uint32 totalLength=0;
|
||||||
|
|
||||||
|
// reading args from va_list
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, prev_part);
|
||||||
|
for(uint16 i=0; i<n; i++){
|
||||||
|
char* part=va_arg(vl,char*);
|
||||||
|
int16 length=cptr_length(part);
|
||||||
|
parts[i]=part;
|
||||||
|
lengths[i]=length;
|
||||||
|
totalLength+=length;
|
||||||
|
}
|
||||||
|
va_end(vl);
|
||||||
|
|
||||||
|
// allocating memory for output value
|
||||||
|
char* totality=malloc(totalLength+1);
|
||||||
|
const char* output=totality;
|
||||||
|
totality[totalLength]=0;
|
||||||
|
|
||||||
|
// copying content of all strings to rezult
|
||||||
|
uint16 k=0;
|
||||||
|
for(; k<n-1; k++){
|
||||||
|
memcopy(parts[k], totality, lengths[k]);
|
||||||
|
totality+=lengths[k];
|
||||||
|
*totality=path_sep;
|
||||||
|
totality++;
|
||||||
|
}
|
||||||
|
memcopy(parts[k], totality, lengths[k]);
|
||||||
|
|
||||||
|
free(parts);
|
||||||
|
free(lengths);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
22
src/Filesystem/filesystem.h
Normal file
22
src/Filesystem/filesystem.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "std.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined (_WIN64)
|
||||||
|
static const char path_sep='\\';
|
||||||
|
#else
|
||||||
|
static const char path_sep='/';
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char* __path_concat(uint16 n, char* path_start, ...);
|
||||||
|
#define path_concat(PATH_PARTS) __path_concat(count_args(PATH_PARTS), PATH_PARTS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user