1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Provide lstat() for Windows.

Junction points will be reported with S_ISLNK(x.st_mode), simulating
POSIX lstat().  stat() will follow pseudo-symlinks, like in POSIX (but
only one level before giving up, unlike in POSIX).

This completes a TODO left by commit bed90759fc.

Tested-by: Andrew Dunstan <andrew@dunslane.net> (earlier version)
Discussion: https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com
This commit is contained in:
Thomas Munro
2022-08-06 12:00:57 +12:00
parent feb593506b
commit c5cb8f3b77
2 changed files with 123 additions and 5 deletions

View File

@@ -278,10 +278,11 @@ struct stat /* This should match struct __stat64 */
extern int _pgfstat64(int fileno, struct stat *buf);
extern int _pgstat64(const char *name, struct stat *buf);
extern int _pglstat64(const char *name, struct stat *buf);
#define fstat(fileno, sb) _pgfstat64(fileno, sb)
#define stat(path, sb) _pgstat64(path, sb)
#define lstat(path, sb) _pgstat64(path, sb)
#define lstat(path, sb) _pglstat64(path, sb)
/* These macros are not provided by older MinGW, nor by MSVC */
#ifndef S_IRUSR
@@ -327,6 +328,21 @@ extern int _pgstat64(const char *name, struct stat *buf);
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
/*
* In order for lstat() to be able to report junction points as symlinks, we
* need to hijack a bit in st_mode, since neither MSVC nor MinGW provides
* S_ISLNK and there aren't any spare bits. We'll steal the one for character
* devices, because we don't otherwise make use of those.
*/
#ifdef S_ISLNK
#error "S_ISLNK is already defined"
#endif
#ifdef S_IFLNK
#error "S_IFLNK is already defined"
#endif
#define S_IFLNK S_IFCHR
#define S_ISLNK(m) (((m) & S_IFLNK) == S_IFLNK)
/*
* Supplement to <fcntl.h>.
* This is the same value as _O_NOINHERIT in the MS header file. This is