My problem was to receive an absolute path ("C:\bla\ble\bli\blo\blu") and create it.
Since the directories in the middle may not exist, either, I have to iterate through the path and create the directories as they appear.
// This is a co-routine for the create Dir function
// it uses a double buffer approach to concatenate the paths
// because the cwalk library requires using a path1, path2, output_buffer architecture
char * co_append_path(char * path , char *path_end, bool initialize)
{
static char buf1[PATH_BUF_SIZE];
static char buf2[PATH_BUF_SIZE];
static char *ind[2] = { buf1,buf2 };
static int src_buf;
#define dest_buf (1-src_buf)
if (initialize)
{
int rootLen = 0;
src_buf = 0;
buf1[0] = 0;
buf2[0] = 0;
cwk_path_get_root(path, &rootLen);
strncpy_s(ind[src_buf], PATH_BUF_SIZE, path, rootLen);
}
else
{
char sep = *path_end;
*path_end = 0;
cwk_path_get_absolute(ind[src_buf], path, ind[dest_buf], PATH_BUF_SIZE);
*path_end = sep;
src_buf = dest_buf;
}
return ind[src_buf];
}
// newDir must be in absolute format
int createDir(char *newDir)
{
char *p;
struct cwk_segment segment;
p = co_append_path(newDir, NULL, true);
if (!cwk_path_get_first_segment(newDir, &segment))
{
return -1;
}
do {
p = co_append_path((char*)segment.begin,(char*)segment.end,false);
if (dirExists(p))
{
printf("dir Exists [%s]\n",p);
}
else
{
printf("dir does not Exist [%s]\n", p);
//create it
}
} while (cwk_path_get_next_segment(&segment));
return 0;
}
I needed to create this strange co-routine in order to deal with the source1,source2, target API style that you created.
Also, what #9 required makes sense, specially because you return indexes some times, so adding something from another path with begin+length, makes sense on your API.