4 // First microsoft compilers
14 #include <sys/types.h>
16 #include <libtarint/filesystem.h>
19 kwDirectory
* kwOpenDir(const char* name
)
21 // struct _KWDIR ssss;
23 size_t n
= strlen(name
);
24 kwDirectory
* dir
= (kwDirectory
*)malloc(sizeof (kwDirectory
));
29 dir
->EOD
=0; //not the end of directory
30 if ( name
[n
- 1] == '/' )
32 buf
= (char*) malloc(n
+ 1 + 1);
33 // buf = new char[n + 1 + 1];
34 sprintf(buf
, "%s*", name
);
38 buf
= (char*)malloc(n
+ 2 + 1);
39 // buf = new char[n + 2 + 1];
40 sprintf(buf
, "%s/*", name
);
43 // Now put them into the file array
44 dir
->SrchHandle
= _findfirst(buf
, &dir
->Entry
);
47 if ( dir
->SrchHandle
== -1 )
55 kwDirEntry
* kwReadDir(kwDirectory
* dir
)
57 static kwDirEntry entry
;
58 if(!dir
|| dir
->EOD
==1)
62 strncpy(entry
.d_name
,dir
->Entry
.name
,TAR_MAXPATHLEN
-1);
63 if(_findnext(dir
->SrchHandle
, &dir
->Entry
) == -1)
68 // It is both stupid and dangerous to return a pointer to a static like this.
69 // This can only be called by one caller at a time: i.e., it's not thread safe.
70 // On the other hand, it mimics the documented behavior of "readdir" which is
71 // what it's implemented to replace for platforms that do not have readdir.
72 // Memory leaks are also stupid and dangerous... perhaps this is less so.
77 int kwCloseDir(kwDirectory
* dir
)
82 r
=_findclose(dir
->SrchHandle
);