summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/include/sys/dirent.h
blob: dd026178bde10f983b136a8dfc06e6ea62ef6560 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* Posix dirent.h for WIN32.

   Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2010, 2012,
   2013 Red Hat, Inc.

   This software is a copyrighted work licensed under the terms of the
   Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
   details. */

/* Including this file should not require any Windows headers.  */

#ifndef _SYS_DIRENT_H
#define _SYS_DIRENT_H

#include <sys/cdefs.h>
#include <sys/types.h>
#include <limits.h>

#define __DIRENT_VERSION	2

#ifndef __x86_64__
#pragma pack(push,4)
#endif
#define _DIRENT_HAVE_D_TYPE
struct dirent
{
  uint32_t __d_version;			/* Used internally */
  ino_t d_ino;
  unsigned char d_type;
  unsigned char __d_unused1[3];
  __uint32_t __d_internal1;
  char d_name[NAME_MAX + 1];
};
#ifndef __x86_64__
#pragma pack(pop)
#endif

#define d_fileno d_ino			/* BSD compatible definition */

#ifdef __x86_64__
#define __DIRENT_COOKIE 0xcdcd8484
#else
#define __DIRENT_COOKIE 0xdede4242
#endif

#ifndef __x86_64__
#pragma pack(push,4)
#endif
typedef struct __DIR
{
  /* This is first to set alignment in non _COMPILING_NEWLIB case.  */
  unsigned long __d_cookie;
  struct dirent *__d_dirent;
  char *__d_dirname;			/* directory name with trailing '*' */
  __int32_t __d_position;			/* used by telldir/seekdir */
  int __d_fd;
  uintptr_t __d_internal;
  void *__handle;
  void *__fh;
  unsigned __flags;
} DIR;
#ifndef __x86_64__
#pragma pack(pop)
#endif

DIR *opendir (const char *);
DIR *fdopendir (int);
struct dirent *readdir (DIR *);
int readdir_r (DIR * __restrict, struct dirent * __restrict,
	       struct dirent ** __restrict);
void rewinddir (DIR *);
int closedir (DIR *);

int dirfd (DIR *);

#if __MISC_VISIBLE || __XSI_VISIBLE
#ifndef __INSIDE_CYGWIN__
long telldir (DIR *);
void seekdir (DIR *, long loc);
#endif
#endif

#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809
int scandir (const char *__dir,
	     struct dirent ***__namelist,
	     int (*select) (const struct dirent *),
	     int (*compar) (const struct dirent **, const struct dirent **));
int alphasort (const struct dirent **__a, const struct dirent **__b);
#endif

#if __GNU_VISIBLE
int scandirat (int __dirfd, const char *__dir, struct dirent ***__namelist,
	       int (*select) (const struct dirent *),
	       int (*compar) (const struct dirent **, const struct dirent **));
#endif

#if __BSD_VISIBLE
#ifdef _DIRENT_HAVE_D_TYPE
/* File types for `d_type'.  */
enum
{
  DT_UNKNOWN = 0,
# define DT_UNKNOWN     DT_UNKNOWN
  DT_FIFO = 1,
# define DT_FIFO        DT_FIFO
  DT_CHR = 2,
# define DT_CHR         DT_CHR
  DT_DIR = 4,
# define DT_DIR         DT_DIR
  DT_BLK = 6,
# define DT_BLK         DT_BLK
  DT_REG = 8,
# define DT_REG         DT_REG
  DT_LNK = 10,
# define DT_LNK         DT_LNK
  DT_SOCK = 12,
# define DT_SOCK        DT_SOCK
  DT_WHT = 14
# define DT_WHT         DT_WHT
};

/* Convert between stat structure types and directory types.  */
# define IFTODT(mode)		(((mode) & 0170000) >> 12)
# define DTTOIF(dirtype)        ((dirtype) << 12)
#endif /* _DIRENT_HAVE_D_TYPE */
#endif /* __BSD_VISIBLE */
#endif /*_SYS_DIRENT_H*/