Index: trunk/src/lib/nt/fts-nt.c
===================================================================
--- trunk/src/lib/nt/fts-nt.c	(revision 3000)
+++ trunk/src/lib/nt/fts-nt.c	(revision 3001)
@@ -85,4 +85,5 @@
 #include "nthlp.h"
 #include "ntdir.h"
+#include <stdio.h>//debug
 
 static FTSENT	*fts_alloc(FTS *sp, char const *name, size_t namelen, wchar_t const *wcsname, size_t cwcname);
@@ -116,6 +117,4 @@
 #define MAX(a, b)  ( (a) >= (b) ? (a) : (b) )
 
-#define AT_SYMLINK_NOFOLLOW 1
-#define fstatat(hDir, pszPath, pStat, fFlags) birdStatAt((hDir), (pszPath), (pStat), (fFlags) != AT_SYMLINK_NOFOLLOW)
 #define FTS_NT_DUMMY_SYMFD_VALUE 	((HANDLE)~(intptr_t)(2)) /* current process */
 
@@ -313,5 +312,5 @@
 	 * known that the path will fit.
 	 */
-    if (!(sp->fts_options & FTS_NO_ANSI)) {
+	if (!(sp->fts_options & FTS_NO_ANSI)) {
 		char *cp;
 		len = p->fts_pathlen = p->fts_namelen;
@@ -711,21 +710,24 @@
 		if (cur->fts_parent->fts_dirfd != INVALID_HANDLE_VALUE) {
 			/* (This works fine for symlinks too, since we follow them.) */
-			cur->fts_dirfd = birdOpenFileEx(cur->fts_parent->fts_dirfd,
-											cur->fts_name,
-											FILE_READ_DATA | SYNCHRONIZE,
-											FILE_ATTRIBUTE_NORMAL,
-											FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
-											FILE_OPEN,
-											FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
-											OBJ_CASE_INSENSITIVE);
+			cur->fts_dirfd = birdOpenFileExW(cur->fts_parent->fts_dirfd,
+			                                 cur->fts_wcsname,
+			                                 FILE_READ_DATA | SYNCHRONIZE,
+			                                 FILE_ATTRIBUTE_NORMAL,
+			                                 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+			                                 FILE_OPEN,
+			                                 FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
+			                                 OBJ_CASE_INSENSITIVE);
 		} else {
-			cur->fts_dirfd = birdOpenFile(cur->fts_accpath,
-										  FILE_READ_DATA | SYNCHRONIZE,
-										  FILE_ATTRIBUTE_NORMAL,
-										  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
-										  FILE_OPEN,
-										  FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
-										  OBJ_CASE_INSENSITIVE);
-		}
+			cur->fts_dirfd = birdOpenFileW(cur->fts_wcsaccpath,
+			                               FILE_READ_DATA | SYNCHRONIZE,
+			                               FILE_ATTRIBUTE_NORMAL,
+			                               FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+			                               FILE_OPEN,
+			                               FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
+			                               OBJ_CASE_INSENSITIVE);
+		}
+		if (cur->fts_dirfd != INVALID_HANDLE_VALUE) { /* likely */ }
+		else goto l_open_err;
+
 	} else {
 		fDirOpenFlags |= BIRDDIR_F_RESTART_SCAN;
@@ -733,4 +735,5 @@
 	dirp = birdDirOpenFromHandle(cur->fts_dirfd, NULL, fDirOpenFlags);
 	if (dirp == NULL) {
+l_open_err:
 		if (type == BREAD) {
 			cur->fts_info = FTS_DNR;
@@ -866,10 +869,10 @@
 {
 	int saved_errno;
-	const char *path;
+	const wchar_t *wcspath;
 
 	if (dfd == INVALID_HANDLE_VALUE) {
-		path = p->fts_accpath;
+		wcspath = p->fts_wcsaccpath;
 	} else {
-		path = p->fts_name;
+		wcspath = p->fts_wcsname;
 	}
 
@@ -880,7 +883,7 @@
 	 */
 	if (ISSET(FTS_LOGICAL) || follow) {
-		if (fstatat(dfd, path, &p->fts_stat, 0)) {
+		if (birdStatAtW(dfd, wcspath, &p->fts_stat, 1 /*fFollowLink*/)) {
 			saved_errno = errno;
-			if (fstatat(dfd, path, &p->fts_stat, AT_SYMLINK_NOFOLLOW)) {
+			if (birdStatAtW(dfd, wcspath, &p->fts_stat, 0 /*fFollowLink*/)) {
 				p->fts_errno = saved_errno;
 				goto err;
@@ -890,5 +893,5 @@
 				return (FTS_SLNONE);
 		}
-	} else if (fstatat(dfd, path, &p->fts_stat, AT_SYMLINK_NOFOLLOW)) {
+	} else if (birdStatAtW(dfd, wcspath, &p->fts_stat, 0 /*fFollowLink*/)) {
 		p->fts_errno = errno;
 err:		memset(&p->fts_stat, 0, sizeof(struct stat));
@@ -1009,5 +1012,5 @@
 		p->fts_wcsname = (wchar_t *)(p + 1);
 		memcpy(p->fts_wcsname, wcsname, cwcname * sizeof(wchar_t));
-		p->fts_wcsname[cwcname];
+		p->fts_wcsname[cwcname] = '\0';
 		p->fts_cwcname = cwcname;
 		if (!(sp->fts_options & FTS_NO_ANSI)) {
