OXYGENHUB
◆ main openmsx / src / utils / win32-dirent.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef WIN32_DIRENT_HH
2
#define WIN32_DIRENT_HH
3
4
/* Copyright (C) 2001, 2006 Free Software Foundation, Inc.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
/* Directory stream type.
22
   The miscellaneous Unix `readdir' implementations read directory data
23
   into a buffer and return `struct dirent *' pointers into it.  */
24
25
// NB: Taken from http://www.koders.com/c/fid5F00BC983E0F005E15E8E590E461D363F6146CEB.aspx
26
// Slightly reformatted/simplified to fit openMSX coding style.
27
28
#ifdef _WIN32
29
30
#include <sys/types.h>
31
#include <basetsd.h> // for INT_PTR
32
#include <string>
33
34
namespace openmsx {
35
36
struct dirstream
37
{
38
	INT_PTR fd;			// File descriptor.
39
	void* data;			// Directory block.
40
	off_t filepos;		// Position of next entry to read.
41
	std::wstring mask;  // Initial file mask.
42
};
43
44
struct dirent
45
{
46
	long d_ino;
47
	off_t d_off;
48
	unsigned short d_reclen;
49
	unsigned char d_type;	// always DT_UNKNOWN in current implementation
50
	char d_name[256];
51
};
52
53
inline constexpr unsigned char DT_UNKNOWN = 0;
54
inline constexpr unsigned char DT_REG = 1;
55
inline constexpr unsigned char DT_DIR = 2;
56
57
#define d_fileno d_ino // Backwards compatibility.
58
59
// This is the data type of directory stream objects.
60
// The actual structure is opaque to users.
61
using DIR = struct dirstream;
62
63
DIR* opendir(const char* name);
64
struct dirent* readdir(DIR* dir);
65
int closedir(DIR* dir);
66
void rewinddir(DIR* dir);
67
void seekdir(DIR* dir, off_t offset);
68
off_t telldir(DIR* dir);
69
//int dirfd(DIR* dir);
70
71
} // namespace openmsx
72
73
#endif
74
75
#endif // WIN32_DIRENT_HH