-
Notifications
You must be signed in to change notification settings - Fork 9
/
dirent.h
executable file
·86 lines (79 loc) · 2.98 KB
/
dirent.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// =====================================================================
// dirent.h
//
// An implementation of the BSD directory routines for MS-Windows NT.
// With the alternative filesystems available under NT, filenames can
// be up to 256 character long. The berkeley routines have similar
// counterparts in the WIN32 library.
//
//
// $Revision: 1342 $
// $Date: 2003-02-11 15:21:54 -0500 (Tue, 11 Feb 2003) $
//
// Windows 3.1/NT InterViews Port
// Copyright (c) 1993 Tim Prinzing
//
// Permission to use, copy, modify, distribute, and sell this software and
// its documentation for any purpose is hereby granted without fee, provided
// that (i) the above copyright notice and this permission notice appear in
// all copies of the software and related documentation, and (ii) the name of
// Tim Prinzing may not be used in any advertising or publicity relating to
// the software without the specific, prior written permission of Tim Prinzing.
//
// THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL Tim Prinzing BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
// RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
// POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// ==========================================================================
#ifndef nt_dir_h
#define nt_dir_h
#if defined(MINGW)
#include <io.h>
#include <dirent.h>
#include <dir.h>
#include <stdlib.h>
#else
#include <io.h>
#if defined(_MSC_VER)
#define ffblk _finddata_t
#define findfirst(a,b,c) _findfirst(a,b)
#define findnext _findnext
#define ff_name name
#else
#include <dir.h>
#endif
#include <stdlib.h>
#define rewinddir(dirp) seekdir(dirp, 0L)
#define MAXNAMLEN _MAX_FNAME
struct dirent
{
int d_namlen; // length of d_name
char d_name[MAXNAMLEN + 1]; // name of the directory entry
};
// The handle returned by the _findfirst function is all that is needed
// to provide the access, but it must be swapped out to provide random
// access, so we put it inside a structure so the clients pointer can
// remain consistant. If any assumptions were made about DIR (ie clients
// of the library used more knowledge than provided in the man page),
// you're screwed because it's radically different in implementation here!
typedef struct
{
long srchHandle; // handle to use
struct ffblk data; // data of current file
struct dirent conversion; // data in dirent format (almost anyway)
short offs; // offset from first
} DIR;
// ---- prototypes ----
extern DIR *opendir(const char*);
extern struct dirent *readdir(DIR*);
extern void seekdir(DIR*, long);
extern long telldir(DIR*);
extern void closedir(DIR*);
#endif // MINGW undefined
#endif /* nt_dir_h */