aa2ba5b91033f09bcf7693edbbcc30f0af87a644
[profile/ivi/syslinux.git] / com32 / lib / opendir.c
1 /*
2  * opendir.c
3  */
4
5 #include <dirent.h>
6 #include <stdio.h>
7 #include <errno.h>
8
9 #include <com32.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13
14
15 DIR *opendir(const char *pathname)
16 {
17         DIR *newdir;
18         com32sys_t regs;
19
20         newdir = NULL;
21
22         strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
23
24         regs.eax.w[0] = 0x0020;
25         regs.esi.w[0] = OFFS(__com32.cs_bounce);
26         regs.es = SEG(__com32.cs_bounce);
27
28         __com32.cs_intcall(0x22, &regs, &regs);
29
30         if (!(regs.eflags.l & EFLAGS_CF)) {
31                 /* Initialization: malloc() then zero */
32                 newdir = calloc(1, sizeof(DIR));
33                 strcpy(newdir->dd_name, pathname);
34                 newdir->dd_fd = regs.esi.w[0];
35                 newdir->dd_sect = regs.eax.l;
36                 newdir->dd_stat = 0;
37         }
38
39         /* We're done */
40         return newdir;
41 }