{"thread":{"id":"36855","subject":"[PATCH 3/5] Win32 dirent: change FILENAME_MAX to MAX_PATH","startedAt":"2014-06-06T13:43:16Z","lastAt":"2014-06-06T20:15:44Z","messageCount":13,"participants":["Stepan Kasal","Karsten Blees"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"243468","messageId":"1402062201-9709-1-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":null,"subject":"[PATCH 0/5] Windows dirent patches","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:16Z","receivedAt":"2014-06-06T13:43:16Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hello,\n\nThis is a series of dirent modifications, 4 tiny ones and one bigger.\nAs the date indicates, these are battle tested in mysgit for several years.\n\nRegards,\n\tStepan\n\nKarsten Blees (5):\n  Win32 dirent: remove unused dirent.d_ino member\n  Win32 dirent: remove unused dirent.d_reclen member\n  Win32 dirent: change FILENAME_MAX to MAX_PATH\n  Win32 dirent: clarify #include directives\n  Win32 dirent: improve dirent implementation\n\n compat/win32/dirent.c | 116 ++++++++++++++++++++++++--------------------------\n compat/win32/dirent.h |   8 +---\n config.mak.uname      |   2 +\n 3 files changed, 59 insertions(+), 67 deletions(-)\n\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243464","messageId":"1402062201-9709-2-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 1/5] Win32 dirent: remove unused dirent.d_ino member","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:17Z","receivedAt":"2014-06-06T13:43:17Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\n\nThere are no proper inodes on Windows, so remove dirent.d_ino and #define\nNO_D_INO_IN_DIRENT in the Makefile (this skips e.g. an ineffective qsort in\nfsck.c).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 1 -\n config.mak.uname      | 2 ++\n 2 files changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex 927a25c..b38973b 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -9,7 +9,6 @@ typedef struct DIR DIR;\n #define DT_LNK     3\n \n struct dirent {\n-\tlong d_ino;                      /* Always zero. */\n \tchar d_name[FILENAME_MAX];       /* File name. */\n \tunion {\n \t\tunsigned short d_reclen; /* Always zero. */\ndiff --git a/config.mak.uname b/config.mak.uname\nindex 1ae675b..8131c81 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -354,6 +354,7 @@ ifeq ($(uname_S),Windows)\n \tNO_POSIX_GOODIES = UnfortunatelyYes\n \tNATIVE_CRLF = YesPlease\n \tDEFAULT_HELP_FORMAT = html\n+\tNO_D_INO_IN_DIRENT = YesPlease\n \n \tCC = compat/vcbuild/scripts/clink.pl\n \tAR = compat/vcbuild/scripts/lib.pl\n@@ -503,6 +504,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tNO_INET_NTOP = YesPlease\n \tNO_POSIX_GOODIES = UnfortunatelyYes\n \tDEFAULT_HELP_FORMAT = html\n+\tNO_D_INO_IN_DIRENT = YesPlease\n \tCOMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32\n \tCOMPAT_CFLAGS += -DSTRIP_EXTENSION=\\\".exe\\\"\n \tCOMPAT_OBJS += compat/mingw.o compat/winansi.o \\\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243465","messageId":"1402062201-9709-3-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 2/5] Win32 dirent: remove unused dirent.d_reclen member","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:18Z","receivedAt":"2014-06-06T13:43:18Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\n\nRemove the union around dirent.d_type and the unused dirent.d_reclen member\n(which was necessary for compatibility with the MinGW dirent runtime, which\nis no longer used).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex b38973b..7f4e6c7 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -10,10 +10,7 @@ typedef struct DIR DIR;\n \n struct dirent {\n \tchar d_name[FILENAME_MAX];       /* File name. */\n-\tunion {\n-\t\tunsigned short d_reclen; /* Always zero. */\n-\t\tunsigned char  d_type;   /* Reimplementation adds this */\n-\t};\n+\tunsigned char d_type;      /* file type to prevent lstat after readdir */\n };\n \n DIR *opendir(const char *dirname);\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243463","messageId":"1402062201-9709-4-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 3/5] Win32 dirent: change FILENAME_MAX to MAX_PATH","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:19Z","receivedAt":"2014-06-06T13:43:19Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\n\nFILENAME_MAX and MAX_PATH are both 260 on Windows, however, MAX_PATH is\nused throughout the other Win32 code in Git, and also defines the length\nof file name buffers in the Win32 API (e.g. WIN32_FIND_DATA.cFileName,\nfrom which we're copying the dirent data).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex 7f4e6c7..8838cd6 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -9,8 +9,8 @@ typedef struct DIR DIR;\n #define DT_LNK     3\n \n struct dirent {\n-\tchar d_name[FILENAME_MAX];       /* File name. */\n \tunsigned char d_type;      /* file type to prevent lstat after readdir */\n+\tchar d_name[MAX_PATH];     /* file name */\n };\n \n DIR *opendir(const char *dirname);\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243467","messageId":"1402062201-9709-5-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 4/5] Win32 dirent: clarify #include directives","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:20Z","receivedAt":"2014-06-06T13:43:20Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\n\nGit-compat-util.h is two dirs up, and already includes <dirent.h> (which\nis the same as \"dirent.h\" due to -Icompat/win32 in the Makefile).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex 7a0debe..fac7f25 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -1,5 +1,4 @@\n-#include \"../git-compat-util.h\"\n-#include \"dirent.h\"\n+#include \"../../git-compat-util.h\"\n \n struct DIR {\n \tstruct dirent dd_dir; /* includes d_type */\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243466","messageId":"1402062201-9709-6-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 5/5] Win32 dirent: improve dirent implementation","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T13:43:21Z","receivedAt":"2014-06-06T13:43:21Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\n\nImprove the dirent implementation by removing the relics that were once\nnecessary to plug into the now unused MinGW runtime, in preparation for\nUnicode file name support.\n\nMove FindFirstFile to opendir, and FindClose to closedir, with the\nfollowing implications:\n- DIR.dd_name is no longer needed\n- chdir(one); opendir(relative); chdir(two); readdir() works as expected\n  (i.e. lists one/relative instead of two/relative)\n- DIR.dd_handle is a valid handle for the entire lifetime of the DIR struct\n- thus, all checks for dd_handle == INVALID_HANDLE_VALUE and dd_handle == 0\n  have been removed\n- the special case that the directory has been fully read (which was\n  previously explicitly tracked with dd_handle == INVALID_HANDLE_VALUE &&\n  dd_stat != 0) is now handled implicitly by the FindNextFile error\n  handling code (if a client continues to call readdir after receiving\n  NULL, FindNextFile will continue to fail with ERROR_NO_MORE_FILES, to\n  the same effect)\n- extracting dirent data from WIN32_FIND_DATA is needed in two places, so\n  moved to its own method\n- GetFileAttributes is no longer needed. The same information can be\n  obtained from the FindFirstFile error code, which is ERROR_DIRECTORY if\n  the name is NOT a directory (-> ENOTDIR), otherwise we can use\n  err_win_to_posix (e.g. ERROR_PATH_NOT_FOUND -> ENOENT). The\n  ERROR_DIRECTORY case could be fixed in err_win_to_posix, but this\n  probably breaks other functionality.\n\nRemoves the ERROR_NO_MORE_FILES check after FindFirstFile (this was\nfortunately a NOOP (searching for '*' always finds '.' and '..'),\notherwise the subsequent code would have copied data from an uninitialized\nbuffer).\n\nChanges malloc to git support function xmalloc, so opendir will die() if\nout of memory, rather than failing with ENOMEM and letting git work on\nincomplete directory listings (error handling in dir.c is quite sparse).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.c | 113 ++++++++++++++++++++++++--------------------------\n 1 file changed, 54 insertions(+), 59 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex fac7f25..82a515c 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -4,92 +4,88 @@ struct DIR {\n \tstruct dirent dd_dir; /* includes d_type */\n \tHANDLE dd_handle;     /* FindFirstFile handle */\n \tint dd_stat;          /* 0-based index */\n-\tchar dd_name[1];      /* extend struct */\n };\n \n+static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAA *fdata)\n+{\n+\t/* copy file name from WIN32_FIND_DATA to dirent */\n+\tmemcpy(ent->d_name, fdata->cFileName, sizeof(ent->d_name));\n+\n+\t/* Set file type, based on WIN32_FIND_DATA */\n+\tif (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\n+\t\tent->d_type = DT_DIR;\n+\telse\n+\t\tent->d_type = DT_REG;\n+}\n+\n DIR *opendir(const char *name)\n {\n-\tDWORD attrs = GetFileAttributesA(name);\n+\tchar pattern[MAX_PATH];\n+\tWIN32_FIND_DATAA fdata;\n+\tHANDLE h;\n \tint len;\n-\tDIR *p;\n+\tDIR *dir;\n \n-\t/* check for valid path */\n-\tif (attrs == INVALID_FILE_ATTRIBUTES) {\n-\t\terrno = ENOENT;\n+\t/* check that name is not NULL */\n+\tif (!name) {\n+\t\terrno = EINVAL;\n \t\treturn NULL;\n \t}\n-\n-\t/* check if it's a directory */\n-\tif (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {\n-\t\terrno = ENOTDIR;\n-\t\treturn NULL;\n-\t}\n-\n \t/* check that the pattern won't be too long for FindFirstFileA */\n \tlen = strlen(name);\n-\tif (is_dir_sep(name[len - 1]))\n-\t\tlen--;\n \tif (len + 2 >= MAX_PATH) {\n \t\terrno = ENAMETOOLONG;\n \t\treturn NULL;\n \t}\n-\n-\tp = malloc(sizeof(DIR) + len + 2);\n-\tif (!p)\n+\t/* copy name to temp buffer */\n+\tmemcpy(pattern, name, len + 1);\n+\n+\t/* append optional '/' and wildcard '*' */\n+\tif (len && !is_dir_sep(pattern[len - 1]))\n+\t\tpattern[len++] = '/';\n+\tpattern[len++] = '*';\n+\tpattern[len] = 0;\n+\n+\t/* open find handle */\n+\th = FindFirstFileA(pattern, &fdata);\n+\tif (h == INVALID_HANDLE_VALUE) {\n+\t\tDWORD err = GetLastError();\n+\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);\n \t\treturn NULL;\n+\t}\n \n-\tmemset(p, 0, sizeof(DIR) + len + 2);\n-\tstrcpy(p->dd_name, name);\n-\tp->dd_name[len] = '/';\n-\tp->dd_name[len+1] = '*';\n-\n-\tp->dd_handle = INVALID_HANDLE_VALUE;\n-\treturn p;\n+\t/* initialize DIR structure and copy first dir entry */\n+\tdir = xmalloc(sizeof(DIR));\n+\tdir->dd_handle = h;\n+\tdir->dd_stat = 0;\n+\tfinddata2dirent(&dir->dd_dir, &fdata);\n+\treturn dir;\n }\n \n struct dirent *readdir(DIR *dir)\n {\n-\tWIN32_FIND_DATAA buf;\n-\tHANDLE handle;\n-\n-\tif (!dir || !dir->dd_handle) {\n+\tif (!dir) {\n \t\terrno = EBADF; /* No set_errno for mingw */\n \t\treturn NULL;\n \t}\n \n-\tif (dir->dd_handle == INVALID_HANDLE_VALUE && dir->dd_stat == 0) {\n-\t\tDWORD lasterr;\n-\t\thandle = FindFirstFileA(dir->dd_name, &buf);\n-\t\tlasterr = GetLastError();\n-\t\tdir->dd_handle = handle;\n-\t\tif (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {\n-\t\t\terrno = err_win_to_posix(lasterr);\n+\t/* if first entry, dirent has already been set up by opendir */\n+\tif (dir->dd_stat) {\n+\t\t/* get next entry and convert from WIN32_FIND_DATA to dirent */\n+\t\tWIN32_FIND_DATAA fdata;\n+\t\tif (FindNextFileA(dir->dd_handle, &fdata)) {\n+\t\t\tfinddata2dirent(&dir->dd_dir, &fdata);\n+\t\t} else {\n+\t\t\tDWORD lasterr = GetLastError();\n+\t\t\t/* POSIX says you shouldn't set errno when readdir can't\n+\t\t\t   find any more files; so, if another error we leave it set. */\n+\t\t\tif (lasterr != ERROR_NO_MORE_FILES)\n+\t\t\t\terrno = err_win_to_posix(lasterr);\n \t\t\treturn NULL;\n \t\t}\n-\t} else if (dir->dd_handle == INVALID_HANDLE_VALUE) {\n-\t\treturn NULL;\n-\t} else if (!FindNextFileA(dir->dd_handle, &buf)) {\n-\t\tDWORD lasterr = GetLastError();\n-\t\tFindClose(dir->dd_handle);\n-\t\tdir->dd_handle = INVALID_HANDLE_VALUE;\n-\t\t/* POSIX says you shouldn't set errno when readdir can't\n-\t\t   find any more files; so, if another error we leave it set. */\n-\t\tif (lasterr != ERROR_NO_MORE_FILES)\n-\t\t\terrno = err_win_to_posix(lasterr);\n-\t\treturn NULL;\n \t}\n \n-\t/* We get here if `buf' contains valid data.  */\n-\tstrcpy(dir->dd_dir.d_name, buf.cFileName);\n \t++dir->dd_stat;\n-\n-\t/* Set file type, based on WIN32_FIND_DATA */\n-\tdir->dd_dir.d_type = 0;\n-\tif (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\n-\t\tdir->dd_dir.d_type |= DT_DIR;\n-\telse\n-\t\tdir->dd_dir.d_type |= DT_REG;\n-\n \treturn &dir->dd_dir;\n }\n \n@@ -100,8 +96,7 @@ int closedir(DIR *dir)\n \t\treturn -1;\n \t}\n \n-\tif (dir->dd_handle != INVALID_HANDLE_VALUE)\n-\t\tFindClose(dir->dd_handle);\n+\tFindClose(dir->dd_handle);\n \tfree(dir);\n \treturn 0;\n }\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243500","messageId":"5391ED57.1000601@gmail.com","threadId":"36855","inReplyTo":"1402062201-9709-1-git-send-email-kasal@ucw.cz","subject":"Re: [PATCH 0/5] Windows dirent patches","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-06T16:33:27Z","receivedAt":"2014-06-06T16:33:27Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 06.06.2014 15:43, schrieb Stepan Kasal:\n> Hello,\n> \n> This is a series of dirent modifications, 4 tiny ones and one bigger.\n> As the date indicates, these are battle tested in mysgit for several years.\n> \n\nThe dates are actually missing from the patches, otherwise full ack from me. Thanks!\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243516","messageId":"1402085744-15829-1-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"5391ED57.1000601@gmail.com","subject":"[PATCH 0/5] Windows dirent patches","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:39Z","receivedAt":"2014-06-06T20:15:39Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"On Fri, Jun 06, 2014 at 06:33:27PM +0200, Karsten Blees wrote:\n> The dates are actually missing from the patches, [...]\n\noops, this was first time I tried to use git-send-email.\nI hope this time it'll work better.\nStepan\n\nHello,\n\nThis is a series of dirent modifications, 4 tiny ones and one bigger.\nAs the date indicates, these are battle tested in mysgit for several years.\n\nRegards,\n\tStepan\n\nKarsten Blees (5):\n  Win32 dirent: remove unused dirent.d_ino member\n  Win32 dirent: remove unused dirent.d_reclen member\n  Win32 dirent: change FILENAME_MAX to MAX_PATH\n  Win32 dirent: clarify #include directives\n  Win32 dirent: improve dirent implementation\n\n compat/win32/dirent.c | 116 ++++++++++++++++++++++++--------------------------\n compat/win32/dirent.h |   8 +---\n config.mak.uname      |   2 +\n 3 files changed, 59 insertions(+), 67 deletions(-)\n\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243515","messageId":"1402085744-15829-2-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402085744-15829-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 1/5] Win32 dirent: remove unused dirent.d_ino member","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:40Z","receivedAt":"2014-06-06T20:15:40Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 17:34:33 +0100\n\nThere are no proper inodes on Windows, so remove dirent.d_ino and #define\nNO_D_INO_IN_DIRENT in the Makefile (this skips e.g. an ineffective qsort in\nfsck.c).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 1 -\n config.mak.uname      | 2 ++\n 2 files changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex 927a25c..b38973b 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -9,7 +9,6 @@ typedef struct DIR DIR;\n #define DT_LNK     3\n \n struct dirent {\n-\tlong d_ino;                      /* Always zero. */\n \tchar d_name[FILENAME_MAX];       /* File name. */\n \tunion {\n \t\tunsigned short d_reclen; /* Always zero. */\ndiff --git a/config.mak.uname b/config.mak.uname\nindex 1ae675b..8131c81 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -354,6 +354,7 @@ ifeq ($(uname_S),Windows)\n \tNO_POSIX_GOODIES = UnfortunatelyYes\n \tNATIVE_CRLF = YesPlease\n \tDEFAULT_HELP_FORMAT = html\n+\tNO_D_INO_IN_DIRENT = YesPlease\n \n \tCC = compat/vcbuild/scripts/clink.pl\n \tAR = compat/vcbuild/scripts/lib.pl\n@@ -503,6 +504,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tNO_INET_NTOP = YesPlease\n \tNO_POSIX_GOODIES = UnfortunatelyYes\n \tDEFAULT_HELP_FORMAT = html\n+\tNO_D_INO_IN_DIRENT = YesPlease\n \tCOMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32\n \tCOMPAT_CFLAGS += -DSTRIP_EXTENSION=\\\".exe\\\"\n \tCOMPAT_OBJS += compat/mingw.o compat/winansi.o \\\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243518","messageId":"1402085744-15829-3-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402085744-15829-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 2/5] Win32 dirent: remove unused dirent.d_reclen member","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:41Z","receivedAt":"2014-06-06T20:15:41Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 17:38:25 +0100\n\nRemove the union around dirent.d_type and the unused dirent.d_reclen member\n(which was necessary for compatibility with the MinGW dirent runtime, which\nis no longer used).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex b38973b..7f4e6c7 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -10,10 +10,7 @@ typedef struct DIR DIR;\n \n struct dirent {\n \tchar d_name[FILENAME_MAX];       /* File name. */\n-\tunion {\n-\t\tunsigned short d_reclen; /* Always zero. */\n-\t\tunsigned char  d_type;   /* Reimplementation adds this */\n-\t};\n+\tunsigned char d_type;      /* file type to prevent lstat after readdir */\n };\n \n DIR *opendir(const char *dirname);\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243514","messageId":"1402085744-15829-4-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402085744-15829-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 3/5] Win32 dirent: change FILENAME_MAX to MAX_PATH","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:42Z","receivedAt":"2014-06-06T20:15:42Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 17:43:14 +0100\n\nFILENAME_MAX and MAX_PATH are both 260 on Windows, however, MAX_PATH is\nused throughout the other Win32 code in Git, and also defines the length\nof file name buffers in the Win32 API (e.g. WIN32_FIND_DATA.cFileName,\nfrom which we're copying the dirent data).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nindex 7f4e6c7..8838cd6 100644\n--- a/compat/win32/dirent.h\n+++ b/compat/win32/dirent.h\n@@ -9,8 +9,8 @@ typedef struct DIR DIR;\n #define DT_LNK     3\n \n struct dirent {\n-\tchar d_name[FILENAME_MAX];       /* File name. */\n \tunsigned char d_type;      /* file type to prevent lstat after readdir */\n+\tchar d_name[MAX_PATH];     /* file name */\n };\n \n DIR *opendir(const char *dirname);\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243519","messageId":"1402085744-15829-5-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402085744-15829-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 4/5] Win32 dirent: clarify #include directives","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:43Z","receivedAt":"2014-06-06T20:15:43Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 17:47:41 +0100\n\nGit-compat-util.h is two dirs up, and already includes <dirent.h> (which\nis the same as \"dirent.h\" due to -Icompat/win32 in the Makefile).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex 7a0debe..fac7f25 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -1,5 +1,4 @@\n-#include \"../git-compat-util.h\"\n-#include \"dirent.h\"\n+#include \"../../git-compat-util.h\"\n \n struct DIR {\n \tstruct dirent dd_dir; /* includes d_type */\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243517","messageId":"1402085744-15829-6-git-send-email-kasal@ucw.cz","threadId":"36855","inReplyTo":"1402085744-15829-1-git-send-email-kasal@ucw.cz","subject":"[PATCH 5/5] Win32 dirent: improve dirent implementation","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T20:15:44Z","receivedAt":"2014-06-06T20:15:44Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 17:57:02 +0100\n\nImprove the dirent implementation by removing the relics that were once\nnecessary to plug into the now unused MinGW runtime, in preparation for\nUnicode file name support.\n\nMove FindFirstFile to opendir, and FindClose to closedir, with the\nfollowing implications:\n- DIR.dd_name is no longer needed\n- chdir(one); opendir(relative); chdir(two); readdir() works as expected\n  (i.e. lists one/relative instead of two/relative)\n- DIR.dd_handle is a valid handle for the entire lifetime of the DIR struct\n- thus, all checks for dd_handle == INVALID_HANDLE_VALUE and dd_handle == 0\n  have been removed\n- the special case that the directory has been fully read (which was\n  previously explicitly tracked with dd_handle == INVALID_HANDLE_VALUE &&\n  dd_stat != 0) is now handled implicitly by the FindNextFile error\n  handling code (if a client continues to call readdir after receiving\n  NULL, FindNextFile will continue to fail with ERROR_NO_MORE_FILES, to\n  the same effect)\n- extracting dirent data from WIN32_FIND_DATA is needed in two places, so\n  moved to its own method\n- GetFileAttributes is no longer needed. The same information can be\n  obtained from the FindFirstFile error code, which is ERROR_DIRECTORY if\n  the name is NOT a directory (-> ENOTDIR), otherwise we can use\n  err_win_to_posix (e.g. ERROR_PATH_NOT_FOUND -> ENOENT). The\n  ERROR_DIRECTORY case could be fixed in err_win_to_posix, but this\n  probably breaks other functionality.\n\nRemoves the ERROR_NO_MORE_FILES check after FindFirstFile (this was\nfortunately a NOOP (searching for '*' always finds '.' and '..'),\notherwise the subsequent code would have copied data from an uninitialized\nbuffer).\n\nChanges malloc to git support function xmalloc, so opendir will die() if\nout of memory, rather than failing with ENOMEM and letting git work on\nincomplete directory listings (error handling in dir.c is quite sparse).\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/win32/dirent.c | 113 ++++++++++++++++++++++++--------------------------\n 1 file changed, 54 insertions(+), 59 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex fac7f25..82a515c 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -4,92 +4,88 @@ struct DIR {\n \tstruct dirent dd_dir; /* includes d_type */\n \tHANDLE dd_handle;     /* FindFirstFile handle */\n \tint dd_stat;          /* 0-based index */\n-\tchar dd_name[1];      /* extend struct */\n };\n \n+static inline void finddata2dirent(struct dirent *ent, WIN32_FIND_DATAA *fdata)\n+{\n+\t/* copy file name from WIN32_FIND_DATA to dirent */\n+\tmemcpy(ent->d_name, fdata->cFileName, sizeof(ent->d_name));\n+\n+\t/* Set file type, based on WIN32_FIND_DATA */\n+\tif (fdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\n+\t\tent->d_type = DT_DIR;\n+\telse\n+\t\tent->d_type = DT_REG;\n+}\n+\n DIR *opendir(const char *name)\n {\n-\tDWORD attrs = GetFileAttributesA(name);\n+\tchar pattern[MAX_PATH];\n+\tWIN32_FIND_DATAA fdata;\n+\tHANDLE h;\n \tint len;\n-\tDIR *p;\n+\tDIR *dir;\n \n-\t/* check for valid path */\n-\tif (attrs == INVALID_FILE_ATTRIBUTES) {\n-\t\terrno = ENOENT;\n+\t/* check that name is not NULL */\n+\tif (!name) {\n+\t\terrno = EINVAL;\n \t\treturn NULL;\n \t}\n-\n-\t/* check if it's a directory */\n-\tif (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {\n-\t\terrno = ENOTDIR;\n-\t\treturn NULL;\n-\t}\n-\n \t/* check that the pattern won't be too long for FindFirstFileA */\n \tlen = strlen(name);\n-\tif (is_dir_sep(name[len - 1]))\n-\t\tlen--;\n \tif (len + 2 >= MAX_PATH) {\n \t\terrno = ENAMETOOLONG;\n \t\treturn NULL;\n \t}\n-\n-\tp = malloc(sizeof(DIR) + len + 2);\n-\tif (!p)\n+\t/* copy name to temp buffer */\n+\tmemcpy(pattern, name, len + 1);\n+\n+\t/* append optional '/' and wildcard '*' */\n+\tif (len && !is_dir_sep(pattern[len - 1]))\n+\t\tpattern[len++] = '/';\n+\tpattern[len++] = '*';\n+\tpattern[len] = 0;\n+\n+\t/* open find handle */\n+\th = FindFirstFileA(pattern, &fdata);\n+\tif (h == INVALID_HANDLE_VALUE) {\n+\t\tDWORD err = GetLastError();\n+\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);\n \t\treturn NULL;\n+\t}\n \n-\tmemset(p, 0, sizeof(DIR) + len + 2);\n-\tstrcpy(p->dd_name, name);\n-\tp->dd_name[len] = '/';\n-\tp->dd_name[len+1] = '*';\n-\n-\tp->dd_handle = INVALID_HANDLE_VALUE;\n-\treturn p;\n+\t/* initialize DIR structure and copy first dir entry */\n+\tdir = xmalloc(sizeof(DIR));\n+\tdir->dd_handle = h;\n+\tdir->dd_stat = 0;\n+\tfinddata2dirent(&dir->dd_dir, &fdata);\n+\treturn dir;\n }\n \n struct dirent *readdir(DIR *dir)\n {\n-\tWIN32_FIND_DATAA buf;\n-\tHANDLE handle;\n-\n-\tif (!dir || !dir->dd_handle) {\n+\tif (!dir) {\n \t\terrno = EBADF; /* No set_errno for mingw */\n \t\treturn NULL;\n \t}\n \n-\tif (dir->dd_handle == INVALID_HANDLE_VALUE && dir->dd_stat == 0) {\n-\t\tDWORD lasterr;\n-\t\thandle = FindFirstFileA(dir->dd_name, &buf);\n-\t\tlasterr = GetLastError();\n-\t\tdir->dd_handle = handle;\n-\t\tif (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {\n-\t\t\terrno = err_win_to_posix(lasterr);\n+\t/* if first entry, dirent has already been set up by opendir */\n+\tif (dir->dd_stat) {\n+\t\t/* get next entry and convert from WIN32_FIND_DATA to dirent */\n+\t\tWIN32_FIND_DATAA fdata;\n+\t\tif (FindNextFileA(dir->dd_handle, &fdata)) {\n+\t\t\tfinddata2dirent(&dir->dd_dir, &fdata);\n+\t\t} else {\n+\t\t\tDWORD lasterr = GetLastError();\n+\t\t\t/* POSIX says you shouldn't set errno when readdir can't\n+\t\t\t   find any more files; so, if another error we leave it set. */\n+\t\t\tif (lasterr != ERROR_NO_MORE_FILES)\n+\t\t\t\terrno = err_win_to_posix(lasterr);\n \t\t\treturn NULL;\n \t\t}\n-\t} else if (dir->dd_handle == INVALID_HANDLE_VALUE) {\n-\t\treturn NULL;\n-\t} else if (!FindNextFileA(dir->dd_handle, &buf)) {\n-\t\tDWORD lasterr = GetLastError();\n-\t\tFindClose(dir->dd_handle);\n-\t\tdir->dd_handle = INVALID_HANDLE_VALUE;\n-\t\t/* POSIX says you shouldn't set errno when readdir can't\n-\t\t   find any more files; so, if another error we leave it set. */\n-\t\tif (lasterr != ERROR_NO_MORE_FILES)\n-\t\t\terrno = err_win_to_posix(lasterr);\n-\t\treturn NULL;\n \t}\n \n-\t/* We get here if `buf' contains valid data.  */\n-\tstrcpy(dir->dd_dir.d_name, buf.cFileName);\n \t++dir->dd_stat;\n-\n-\t/* Set file type, based on WIN32_FIND_DATA */\n-\tdir->dd_dir.d_type = 0;\n-\tif (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\n-\t\tdir->dd_dir.d_type |= DT_DIR;\n-\telse\n-\t\tdir->dd_dir.d_type |= DT_REG;\n-\n \treturn &dir->dd_dir;\n }\n \n@@ -100,8 +96,7 @@ int closedir(DIR *dir)\n \t\treturn -1;\n \t}\n \n-\tif (dir->dd_handle != INVALID_HANDLE_VALUE)\n-\t\tFindClose(dir->dd_handle);\n+\tFindClose(dir->dd_handle);\n \tfree(dir);\n \treturn 0;\n }\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"}]}