Esempio n. 1
0
IoObject *IoDirectory_itemForDirent_(IoDirectory *self, struct dirent *dp)
{
    IoSymbol *pathString;
    int isDir;
    UArray *path = IoSeq_rawUArray(DATA(self)->path);
    UArray *ba = UArray_clone(path);

    /*
    printf("IoDirectory_itemForDirent_ path = \"%s\" %i\n", p, path->itemSize);
    printf("IoDirectory_itemForDirent_ ba = \"%s\" %i\n", UArray_asCString(ba), ba->itemSize);
    */
    if (UArray_size(ba) && !IS_PATH_SEPERATOR(UArray_longAt_(ba, UArray_size(ba) - 1)))
    {
        UArray_appendCString_(ba, IO_PATH_SEPARATOR);
    }

    UArray_appendCString_(ba, dp->d_name);
    pathString = IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);

    isDir = isDirectory(dp, CSTRING(pathString));

    if (isDir)
    {
        return IoDirectory_newWithPath_(IOSTATE, pathString);
    }

    return IoFile_newWithPath_(IOSTATE, pathString);
}
Esempio n. 2
0
void UArray_appendPath_(UArray *self, const UArray *path)
{
	const UArray sep = UArray_stackAllocedWithCString_(IO_PATH_SEPARATOR);

	int selfEndsWithSep   = IS_PATH_SEPERATOR(UArray_lastLong(self));
	int pathStartsWithSep = IS_PATH_SEPERATOR(UArray_firstLong(path));

	if (!selfEndsWithSep && !pathStartsWithSep)
	{
		if(self->size != 0) UArray_append_(self, &sep);
		UArray_append_(self, path);
	}
	else if (selfEndsWithSep && pathStartsWithSep)
	{
		const UArray pathPart = UArray_stackRange(path, 1, path->size - 1);
		UArray_append_(self, &pathPart);
	}
	else
	{
		UArray_append_(self, path);
	}
}