Anope IRC Services  Version 2.0
dir.cpp
Go to the documentation of this file.
1  /* POSIX emulation layer for Windows.
2  *
3  * Copyright (C) 2008-2014 Anope Team <team@anope.org>
4  *
5  * Please read COPYING and README for further details.
6  */
7 
8 #include "dir.h"
9 #include <stdio.h>
10 
11 DIR *opendir(const char *path)
12 {
13  char real_path[MAX_PATH];
14  _snprintf(real_path, sizeof(real_path), "%s/*", path);
15 
16  DIR *d = new DIR();
17  d->handle = FindFirstFile(real_path, &d->data);
18  d->read_first = false;
19 
20  if (d->handle == INVALID_HANDLE_VALUE)
21  {
22  delete d;
23  return NULL;
24  }
25 
26  return d;
27 }
28 
30 {
31  if (d->read_first == false)
32  d->read_first = true;
33  else if (!FindNextFile(d->handle, &d->data))
34  return NULL;
35 
36  d->ent.d_ino = 1;
37  d->ent.d_name = d->data.cFileName;
38 
39  return &d->ent;
40 }
41 
42 int closedir(DIR *d)
43 {
44  FindClose(d->handle);
45  delete d;
46  return 0;
47 }
HANDLE handle
Definition: dir.h:19
Definition: dir.h:16
bool read_first
Definition: dir.h:21
Definition: dir.h:10
DIR * opendir(const char *path)
Definition: dir.cpp:11
dirent ent
Definition: dir.h:18
char * d_name
Definition: dir.h:13
int closedir(DIR *d)
Definition: dir.cpp:42
dirent * readdir(DIR *d)
Definition: dir.cpp:29
int d_ino
Definition: dir.h:12
WIN32_FIND_DATA data
Definition: dir.h:20