solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
win32_dirent.h
Go to the documentation of this file.
1/*
2MIT License
3Copyright (c) 2019 win32ports
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18SOFTWARE.
19*/
20
26#pragma once
27
28#ifndef __DIRENT_H_9DE6B42C_8D0C_4D31_A8EF_8E4C30E6C46A__
29#define __DIRENT_H_9DE6B42C_8D0C_4D31_A8EF_8E4C30E6C46A__
30
31#ifndef _WIN32
32#pragma message("this dirent.h implementation is for Windows only!")
33#else /* _WIN32 */
34
35#ifdef __cplusplus
36extern "C" {
37#endif /* __cplusplus */
38
39#include <errno.h>
40#include <stdint.h>
41#include <sys/types.h>
42#include <windows.h>
43
44/*
45 * Constants and Macros
46 */
47
48#ifndef NAME_MAX
49#define NAME_MAX 260
50#endif /* NAME_MAX */
51
52#ifndef DT_UNKNOWN
53#define DT_UNKNOWN 0
54#endif /* DT_UNKNOWN */
55
56#ifndef DT_FIFO
57#define DT_FIFO 1
58#endif /* DT_FIFO */
59
60#ifndef DT_CHR
61#define DT_CHR 2
62#endif /* DT_CHR */
63
64#ifndef DT_DIR
65#define DT_DIR 4
66#endif /* DT_DIR */
67
68#ifndef DT_BLK
69#define DT_BLK 6
70#endif /* DT_BLK */
71
72#ifndef DT_REG
73#define DT_REG 8
74#endif /* DT_REF */
75
76#ifndef DT_LNK
77#define DT_LNK 10
78#endif /* DT_LNK */
79
80#ifndef DT_SOCK
81#define DT_SOCK 12
82#endif /* DT_SOCK */
83
84#ifndef DT_WHT
85#define DT_WHT 14
86#endif /* DT_WHT */
87
88#ifndef _DIRENT_HAVE_D_NAMLEN
89#define _DIRENT_HAVE_D_NAMLEN 1
90#endif /* _DIRENT_HAVE_D_NAMLEN */
91
92#ifndef _DIRENT_HAVE_D_RECLEN
93#define _DIRENT_HAVE_D_RECLEN 1
94#endif /* _DIRENT_HAVE_D_RECLEN */
95
96#ifndef _DIRENT_HAVE_D_OFF
97#define _DIRENT_HAVE_D_OFF 1
98#endif /* _DIRENT_HAVE_D_OFF */
99
100#ifndef _DIRENT_HAVE_D_TYPE
101#define _DIRENT_HAVE_D_TYPE 1
102#endif /* _DIRENT_HAVE_D_TYPE */
103
104#ifndef NTFS_MAX_PATH
105#define NTFS_MAX_PATH 32768
106#endif /* NTFS_MAX_PATH */
107
108#ifndef FSCTL_GET_REPARSE_POINT
109#define FSCTL_GET_REPARSE_POINT 0x900a8
110#endif /* FSCTL_GET_REPARSE_POINT */
111
112#ifndef FILE_NAME_NORMALIZED
113#define FILE_NAME_NORMALIZED 0
114#endif /* FILE_NAME_NORMALIZED */
115
116/* Opaque directory stream handle */
117typedef void* DIR;
118
119/* Inode structure for Windows */
120typedef struct ino_t {
121 unsigned long long serial;
122 unsigned char fileid[16];
123} __ino_t;
124
125/* Directory entry structure */
126struct dirent {
127 __ino_t d_ino; /* File serial number */
128 off_t d_off; /* Offset to the next dirent */
129 unsigned short d_reclen; /* Length of this record */
130 unsigned char d_namelen; /* Length of the name */
131 unsigned char d_type; /* Type of file (DT_*) */
132 char d_name[NAME_MAX]; /* Null-terminated filename */
133};
134
135/*
136 * Function Prototypes
137 */
138
145DIR* opendir(const char* name);
146
153DIR* _wopendir(const wchar_t* name);
154
161DIR* fdopendir(intptr_t fd);
162
169int closedir(DIR* dirp);
170
177struct dirent* readdir(DIR* dirp);
178
187int readdir_r(DIR* dirp, struct dirent* entry, struct dirent** result);
188
194void rewinddir(DIR* dirp);
195
202void seekdir(DIR* dirp, long int offset);
203
210long int telldir(DIR* dirp);
211
218intptr_t dirfd(DIR* dirp);
219
229int scandir(const char* dirp, struct dirent*** namelist, int (*filter)(const struct dirent*),
230 int (*compar)(const struct dirent**, const struct dirent**));
231
236int alphasort(const void* a, const void* b);
237
242int versionsort(const void* a, const void* b);
243
244#ifdef __cplusplus
245}
246#endif /* __cplusplus */
247
248#endif /* _WIN32 */
249
250#endif /* __DIRENT_H_9DE6B42C_8D0C_4D31_A8EF_8E4C30E6C46A__ */