Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8622 Boppan 1
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
2
 
3
#include 
4
#include 
5
#include 
6
#include 
7
#include 
8
 
9
#define CHECK_DIR_ERR() if(_ksys_work_files(&inf)){ \
10
                            free((void*)inf.p16); \
11
                            errno = ENOTDIR; \
12
                            return NULL; \
13
                        }
14
 
15
DIR* opendir(const char* path)
16
{
17
    DIR* list = malloc(sizeof(DIR));
18
    if(list==NULL){
19
        errno = ENOMEM;
20
        return NULL;
21
    }
22
 
23
    list->pos=0;
24
    unsigned num_of_file=0;
25
    ksys70_t inf;
26
 
27
    inf.p00 = 1;
28
    inf.p04 = 0;
29
    inf.p12 = 2;
30
    inf.p16 = (unsigned) malloc(32+inf.p12*560);
31
    inf.p20 = 0;
32
    inf.p21 = (char*)path;
33
 
34
    CHECK_DIR_ERR();
35
 
36
    num_of_file = *(unsigned*)(inf.p16+8);
37
    inf.p12 = num_of_file;
38
    free((void*)inf.p16);
39
    inf.p16 = (unsigned) malloc(32+inf.p12*560);
40
    list->objs = (struct dirent*)malloc(num_of_file*sizeof(struct dirent));
41
 
42
    CHECK_DIR_ERR();
43
 
44
    for(int i=0; i
45
       list->objs[i].d_ino  = i;
46
       list->objs[i].d_type = *(unsigned*)(inf.p16+32+(264+40)*i);
47
       strcpy(list->objs[i].d_name,(char*)(inf.p16+32+40+(264+40)*i));
48
    }
49
    list->num_objs = num_of_file;
50
    return list;
51
}
52