mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
dirent emulation for MSVC
This commit is contained in:
parent
8cf9982912
commit
2cc356588e
2 changed files with 75 additions and 0 deletions
|
|
@ -20,6 +20,20 @@
|
||||||
#if HAVE_DIRENT_H
|
#if HAVE_DIRENT_H
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#include <windows.h>
|
||||||
|
#ifndef MAX_PATH
|
||||||
|
#define MAX_PATH 260
|
||||||
|
#endif
|
||||||
|
struct dirent {
|
||||||
|
char *d_name;
|
||||||
|
};
|
||||||
|
typedef struct DIR {
|
||||||
|
HANDLE dir;
|
||||||
|
struct dirent data;
|
||||||
|
int first;
|
||||||
|
char buf[MAX_PATH+1];
|
||||||
|
} DIR;
|
||||||
#else
|
#else
|
||||||
# define dirent direct
|
# define dirent direct
|
||||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||||
|
|
|
||||||
|
|
@ -314,6 +314,67 @@ int mkstemp( char * template )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <windows.h>
|
||||||
|
struct dirent {
|
||||||
|
char *d_name;
|
||||||
|
};
|
||||||
|
typedef struct DIR {
|
||||||
|
HANDLE dir;
|
||||||
|
struct dirent data;
|
||||||
|
int first;
|
||||||
|
char buf[MAX_PATH+1];
|
||||||
|
} DIR;
|
||||||
|
DIR *opendir( char *path )
|
||||||
|
{
|
||||||
|
char tmp[32768];
|
||||||
|
int len = strlen(path);
|
||||||
|
DIR *d;
|
||||||
|
HANDLE h;
|
||||||
|
WIN32_FIND_DATA data;
|
||||||
|
|
||||||
|
if (len+3 >= sizeof(tmp))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
strcpy(tmp, path);
|
||||||
|
tmp[len++] = '\\';
|
||||||
|
tmp[len++] = '*';
|
||||||
|
tmp[len] = '\0';
|
||||||
|
|
||||||
|
h = FindFirstFile( tmp, &data );
|
||||||
|
|
||||||
|
if ( h == INVALID_HANDLE_VALUE )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
d = ber_memalloc( sizeof(DIR) );
|
||||||
|
if ( !d )
|
||||||
|
return NULL;
|
||||||
|
d->dir = h;
|
||||||
|
d->data.d_name = d->buf;
|
||||||
|
d->first = 1;
|
||||||
|
strcpy(d->data.d_name, data.cFileName);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
struct dirent *readdir(DIR *dir)
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATA data;
|
||||||
|
|
||||||
|
if (dir->first) {
|
||||||
|
dir->first = 0;
|
||||||
|
} else {
|
||||||
|
if (!FindNextFile(dir->dir, &data))
|
||||||
|
return NULL;
|
||||||
|
strcpy(dir->data.d_name, data.cFileName);
|
||||||
|
}
|
||||||
|
return &dir->data;
|
||||||
|
}
|
||||||
|
void closedir(DIR *dir)
|
||||||
|
{
|
||||||
|
FindClose(dir->dir);
|
||||||
|
ber_memfree(dir);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Memory Reverse Search
|
* Memory Reverse Search
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue