From b5ff856f47d8e54d12c568462a06351633c29610 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 Nov 2011 17:29:16 -0500 Subject: Windows --- src/win32/dir/dir.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/win32/dir/dir.h | 26 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/win32/dir/dir.cpp create mode 100644 src/win32/dir/dir.h (limited to 'src/win32/dir') diff --git a/src/win32/dir/dir.cpp b/src/win32/dir/dir.cpp new file mode 100644 index 000000000..28a54be98 --- /dev/null +++ b/src/win32/dir/dir.cpp @@ -0,0 +1,47 @@ + /* POSIX emulation layer for Windows. + * + * Copyright (C) 2008-2011 Anope Team + * + * Please read COPYING and README for further details. + */ + +#include "dir.h" +#include + +DIR *opendir(const char *path) +{ + char real_path[MAX_PATH]; + _snprintf(real_path, sizeof(real_path), "%s/*", path); + + DIR *d = new DIR(); + d->handle = FindFirstFile(real_path, &d->data); + d->read_first = false; + + if (d->handle == INVALID_HANDLE_VALUE) + { + delete d; + return NULL; + } + + return d; +} + +dirent *readdir(DIR *d) +{ + if (d->read_first == false) + d->read_first = true; + else if (!FindNextFile(d->handle, &d->data)) + return NULL; + + d->ent.d_ino = 1; + d->ent.d_name = d->data.cFileName; + + return &d->ent; +} + +int closedir(DIR *d) +{ + FindClose(d->handle); + delete d; + return 0; +} diff --git a/src/win32/dir/dir.h b/src/win32/dir/dir.h new file mode 100644 index 000000000..8e04c01cc --- /dev/null +++ b/src/win32/dir/dir.h @@ -0,0 +1,26 @@ + /* POSIX emulation layer for Windows. + * + * Copyright (C) 2008-2011 Anope Team + * + * Please read COPYING and README for further details. + */ + +#include + +struct dirent +{ + int d_ino; + char *d_name; +}; + +struct DIR +{ + dirent ent; + HANDLE handle; + WIN32_FIND_DATA data; + bool read_first; +}; + +DIR *opendir(const char *); +dirent *readdir(DIR *); +int closedir(DIR *); -- cgit