2012-06-01 19:23:34 +00:00
|
|
|
/*
|
|
|
|
* Ullrich von Bassewitz, 2012-05-30. Based on code by Groepaz.
|
|
|
|
*/
|
|
|
|
|
2012-05-30 19:37:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "dir.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DIR* __fastcall__ opendir (const char*)
|
2012-06-03 13:59:31 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[32];
|
2012-05-30 19:37:57 +00:00
|
|
|
DIR* dir = 0;
|
2012-06-01 19:23:34 +00:00
|
|
|
DIR d;
|
2012-05-30 19:37:57 +00:00
|
|
|
|
|
|
|
/* Setup file name and offset */
|
|
|
|
d.name[0] = '$';
|
|
|
|
d.name[1] = '\0';
|
2012-06-02 22:56:14 +00:00
|
|
|
d.off = 0;
|
2012-05-30 19:37:57 +00:00
|
|
|
|
|
|
|
/* Open the directory on disk for reading */
|
|
|
|
d.fd = open (d.name, O_RDONLY);
|
|
|
|
if (d.fd >= 0) {
|
|
|
|
|
|
|
|
/* Skip the disk header */
|
2012-06-03 13:59:31 +00:00
|
|
|
if (_dirread (&d, buf, 32)) {
|
2012-05-30 19:37:57 +00:00
|
|
|
|
|
|
|
/* Allocate memory for the DIR structure returned */
|
|
|
|
dir = malloc (sizeof (*dir));
|
|
|
|
|
|
|
|
/* Copy the contents of d */
|
|
|
|
if (dir) {
|
|
|
|
memcpy (dir, &d, sizeof (d));
|
|
|
|
} else {
|
|
|
|
/* Set an appropriate error code */
|
|
|
|
errno = ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|