ok, here is the code (forgive me):
Code:
/* give sort of posix function support for directory manipulation.... in win32~!!! */
#ifndef DIRENT_C
#define DIRENT_C
/* OH NOS I HAET YOU WINDOWS YOU @#^$ERES YUO DO NOT LET TEH DIRECTORIUES L:IST : ^_^ */
#include "dirent.h"
/*
struct dirent {
char d_name[260];
};
typedef struct {
unsigned long _d_hdir;
char *_d_dirname;
unsigned _d_magic;
unsigned _d_nfiles;
char _d_buf[sizeof(WIN32_FIND_DATA)];
} DIR;
typedef struct _WIN32_FIND_DATA { // wfd
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;
*/
/* open up a directory.... POSIX STYLE! LOR~ (BUT NOT COMPLIANT OH NOS) */
DIR *opendir(const char *dirname)
{
DIR *t; WIN32_FIND_DATA *d;
char feh[4096];
t = (DIR *) malloc(sizeof(DIR));
if(t == NULL) return t;
d = (WIN32_FIND_DATA *) &t->_d_buf;
/* try to grab directory handle */
t->harhar = FindFirstFile(dirname, d);
if(t->harhar == INVALID_HANDLE_VALUE)
{ free(t); return NULL; };
/* is this even a directory? (is that air you're breathing? h4w h4w) */
if(!(d->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{ free(t); return NULL; };
/* copy in some basic information */
t->_d_dirname = (char *) malloc(sizeof(char) * strlen(dirname) + 1);
if(t->_d_dirname == NULL) { free(t); return NULL; };
strcpy(t->_d_dirname, dirname);
memcpy(&t->_d_hdir, &t->harhar, sizeof(unsigned long)); /* stall0wned, beey0tch compiler!!1 */
/* prep up the clue train!!!1 */
strcpy(d->cFileName, t->_d_dirname);
strcat(d->cFileName, "/*");
/* count all of the files! ONE TWO THREE */
t->_d_nfiles = 0;
while(FindNextFile(t->harhar, d) != 0)
{
strcpy(d->cFileName, t->_d_dirname);
strcat(d->cFileName, "/*");
++t->_d_nfiles;
};
#include <stdio.h>
printf("haha! the number of files are %d\n", t->_d_nfiles);
printf("lookie here!@: %s\n", d->cFileName);
/* victory! */
return t;
};
struct dirent *readdir(DIR *dir)
{
struct dirent *dent;
return dent;
};
/* close our directory handle */
int closedir(DIR *dir)
{
if(FindClose(dir->harhar) == -1)
return -1;
free(dir->_d_dirname); free(dir);
return 0;
};
void rewinddir(DIR *dir)
{
return;
};
#endif
the struct definitions from the header file are in the comments on top..
the problem, besides my stupidity, is that findnextfile doesn't seem to work as documented. i took it that calling it with the same search handle but replacing the name field with a wildcard "*" would do the trick of just grabbing the next file entry from the same directory, but it didn't work. i tried some other things along the same line, but no results....