File: win32_dirent.h

package info (click to toggle)
glut 3.7-14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 12,556 kB
  • ctags: 45,170
  • sloc: ansic: 148,716; makefile: 35,208; ada: 2,062; yacc: 473; fortran: 290; lex: 131; csh: 51; sed: 49; sh: 33
file content (51 lines) | stat: -rw-r--r-- 955 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __win32_dirent__
#define __win32_dirent__

/* For Win32 that lacks Unix direct support. */

#include <windows.h>
#include <string.h>

struct dirent {
  char d_name[MAX_PATH];
};

typedef struct {
  WIN32_FIND_DATA wfd;
  HANDLE hFind;
  struct dirent de;
} DIR;

static DIR *
opendir(char *pSpec)
{
  DIR *pDir = malloc(sizeof(DIR));
  /* XXX Windows 95 has problems opening up "." though Windows NT does this
     fine?  Open "*" instead of "." to be safe. -mjk */
  pDir->hFind = FindFirstFile(strcmp(pSpec, ".") ? pSpec : "*",
    &pDir->wfd);
  return pDir;
}

static void
closedir(DIR * pDir)
{
  FindClose(pDir);
  free(pDir);
}

static struct dirent *
readdir(DIR *pDir)
{
  if (pDir->hFind) {
    strcpy(pDir->de.d_name, pDir->wfd.cFileName);
    if (!FindNextFile(pDir->hFind, &pDir->wfd))
      pDir->hFind = NULL;
    return &pDir->de;
  }
  return NULL;
}

#define fclose(f)  { if (f!=NULL) fclose(f); }

#endif /* __win32_dirent__ */