aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/opendir.c
blob: 669a04a2e621e001728403b1bdaf4e72a6de892a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * opendir.c
 */

#include <dirent.h>
#include <stdio.h>
#include <errno.h>

#include <com32.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

DIR *opendir(const char *pathname)
{
    DIR *newdir = NULL;
    com32sys_t regs;
	
    strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);

    regs.eax.w[0] = 0x0020;
    regs.esi.w[0] = OFFS(__com32.cs_bounce);
    regs.es = SEG(__com32.cs_bounce);

    __com32.cs_intcall(0x22, &regs, &regs);
	
    if (!(regs.eflags.l & EFLAGS_CF)) {
        /* Initialization: malloc() then zero */
        newdir = calloc(1, sizeof(DIR));
        strcpy(newdir->dd_name, pathname);
        newdir->dd_sect = regs.eax.l;
        newdir->dd_offset = 0;
        newdir->dd_stat = 0;
    }

    /* We're done */
    return newdir;
}