Skip to content

Commit 87e6ed7

Browse files
committed
Add d_type to our Windows dirent emulation.
This allows us to skip some stat calls, by extending commit 861c6e7 to cover Windows systems. Author: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Magnus Hagander <magnus@hagander.net> Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKG%2BFzxupGGN4GpUdbzZN%2Btn6FQPHo8w0Q%2BAPH5Wz8RG%2Bww%40mail.gmail.com
1 parent 74ff281 commit 87e6ed7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/include/port/win32_msvc/dirent.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct dirent
1010
{
1111
long d_ino;
1212
unsigned short d_reclen;
13+
unsigned char d_type;
1314
unsigned short d_namlen;
1415
char d_name[MAX_PATH];
1516
};
@@ -20,4 +21,14 @@ DIR *opendir(const char *);
2021
struct dirent *readdir(DIR *);
2122
int closedir(DIR *);
2223

24+
/* File types for 'd_type'. */
25+
#define DT_UNKNOWN 0
26+
#define DT_FIFO 1
27+
#define DT_CHR 2
28+
#define DT_DIR 4
29+
#define DT_BLK 6
30+
#define DT_REG 8
31+
#define DT_LNK 10
32+
#define DT_SOCK 12
33+
#define DT_WHT 14
2334
#endif

src/port/dirent.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ opendir(const char *dirname)
6969
d->handle = INVALID_HANDLE_VALUE;
7070
d->ret.d_ino = 0; /* no inodes on win32 */
7171
d->ret.d_reclen = 0; /* not used on win32 */
72+
d->ret.d_type = DT_UNKNOWN;
7273

7374
return d;
7475
}
@@ -105,6 +106,15 @@ readdir(DIR *d)
105106
}
106107
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH long */
107108
d->ret.d_namlen = strlen(d->ret.d_name);
109+
/* The only identified types are: directory, regular file or symbolic link */
110+
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
111+
d->ret.d_type = DT_DIR;
112+
/* For reparse points dwReserved0 field will contain the ReparseTag */
113+
else if ((fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0 &&
114+
(fd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT))
115+
d->ret.d_type = DT_LNK;
116+
else
117+
d->ret.d_type = DT_REG;
108118

109119
return &d->ret;
110120
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy