コード例 #1
0
Internal_DirEnt* Internal_Dir_Read(_In_ Internal_Dir* self, _In_opt_z_ TChar *fileEndsWith)
{
    for(;;)
    {
#if defined(_MSC_VER)

        if (!self->firstTime)
        {
            if (_wfindnext(self->handle, &self->fileinfo) != 0)
                return NULL;
        }
        self->firstTime = 0;
        
        if( StringEndsWith(self->fileinfo.name, fileEndsWith) != 0 )
            continue;
        Wcslcpy(self->ent.name, self->fileinfo.name, PAL_MAX_PATH_SIZE);
        if( self->fileinfo.attrib & _A_SUBDIR )
            self->ent.isDir = 1;
        else
            self->ent.isDir = 0;
        
        return &self->ent;

#else
        struct dirent* p = readdir(self->dir);
        struct stat st;
        TChar filespec[PAL_MAX_PATH_SIZE];
        if (!p)
            return NULL;

        if( StringEndsWith(p->d_name, fileEndsWith) != 0 )
            continue;        

        Strlcpy(self->ent.name, p->d_name, PAL_MAX_PATH_SIZE);
        // Logic to detect Dir may not work on non-linux, non-windows platforms, in which case
        // We would need to use Isdir method.
        //self->ent.isDir = Isdir(self->ent.name);  
        if( Tcslcpy(filespec, self->dirName, PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if( Tcslcat(filespec, "/", PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if( Tcslcat(filespec, self->ent.name, PAL_MAX_PATH_SIZE) >= PAL_MAX_PATH_SIZE)
            return NULL;

        if (stat(filespec, &st) != 0)      
            return NULL;
        // self->ent.isDir = (p->d_type & DT_DIR) ? 1 : 0;
        self->ent.isDir = S_ISDIR(st.st_mode);
        return &self->ent;

#endif       
    }
}
コード例 #2
0
ファイル: provreg.c プロジェクト: HuaweiSwitch/OMI
ProvRegNamespaceNode* _FindOrCreateNamespace(
    ProvReg* self,
    MI_ConstString ns,
    MI_Boolean extraClass)
{
    ProvRegNamespaceNode* item = _FindNamespace(self,ns, extraClass);

    if (item)
        return item;

    item = (ProvRegNamespaceNode*)Batch_GetClear(
        &self->batch, sizeof(ProvRegNamespaceNode));

    if (item)
    {
        if(extraClass)
        {
            size_t size;
            size = Tcslen(ns) + 1;

            {
                ZChar* nameSpace = Batch_Get(&self->batch, size * sizeof(ZChar));
                if(nameSpace == NULL)
                {
                    trace_OutOfMemory();
                    return NULL;
                }
                Tcslcpy(nameSpace, ns, size);
                
                item->ns = nameSpace;
                item->next = self->namespacesForExtraClasses;
                self->namespacesForExtraClasses = item;
            }
        }
        else
        {
            item->ns = ns; /* no need to strdup, since it's already in batch*/
            item->next = self->namespaces;
            self->namespaces = item;
        }
    }

    return item;
}