Commit d96c3863a50f2a9b0f33735911e5472fec3ad288

Carlos Martín Nieto 2012-08-02T01:56:02

win32: set errno to ENOENT or ENOTDIR when appropriate in do_lstat

diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 4e0150f..e1471ca 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -60,6 +60,7 @@ GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft)
 static int do_lstat(const char *file_name, struct stat *buf)
 {
 	WIN32_FILE_ATTRIBUTE_DATA fdata;
+	DWORD last_error;
 	wchar_t* fbuf = gitwin_to_utf16(file_name);
 	if (!fbuf)
 		return -1;
@@ -93,6 +94,12 @@ static int do_lstat(const char *file_name, struct stat *buf)
 		return 0;
 	}
 
+	last_error = GetLastError();
+	if (last_error == ERROR_FILE_NOT_FOUND)
+		errno = ENOENT;
+	else if (last_error == ERROR_PATH_NOT_FOUND)
+		errno = ENOTDIR;
+
 	git__free(fbuf);
 	return -1;
 }