--- win32stat.c.bak	2022-08-11 17:15:10.775412600 +0700
+++ win32stat.c	2022-08-11 16:47:41.992805700 +0700
@@ -186,9 +186,12 @@
 {
 	int			loops = 0;
 	int			ret;
+	char		curr[MAXPGPATH];
 
 	ret = _pglstat64(name, buf);
 
+	strlcpy(curr, name, MAXPGPATH);
+
 	/* Do we need to follow a symlink (junction point)? */
 	while (ret == 0 && S_ISLNK(buf->st_mode))
 	{
@@ -211,7 +214,7 @@
 		 * That could be optimized, but stat() on symlinks is probably rare
 		 * and this way is simple.
 		 */
-		size = readlink(name, next, sizeof(next));
+		size = readlink(curr, next, sizeof(next));
 		if (size < 0)
 		{
 			if (errno == EACCES &&
@@ -230,6 +233,7 @@
 		next[size] = 0;
 
 		ret = _pglstat64(next, buf);
+		strcpy(curr, next);
 	}
 
 	return ret;
