{"thread":{"id":"25822","subject":"[RFC PATCH 2/6] msvc: opendir: allocate enough memory","startedAt":"2010-11-23T17:30:38Z","lastAt":"2010-11-23T18:12:08Z","messageCount":18,"participants":["Erik Faye-Lund","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"156406","messageId":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":null,"subject":"[RFC PATCH 0/6] win32-dirent","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:38Z","receivedAt":"2010-11-23T17:30:38Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"This series is against 'next', and fixes the problem on Windows introduced\nby commit 3ba7a06 (\"A loose object is not corrupt if it cannot be read due\nto EMFILE\").\n\nIt unifies the dirent-emulation in compat/mingw.[ch] and compat/msvc.c,\ngiving us a custom implementation of opendir, readdir and closedir that\ndoes not incorrectly set errno to 0.\n\nErik Faye-Lund (6):\n  msvc: opendir: use xmalloc\n  msvc: opendir: allocate enough memory\n  msvc: opendir: do not start the search\n  win32: dirent: handle errors\n  msvc: opendir: handle paths ending with a slash\n  win32: use our own dirent.h\n\n Makefile                        |    7 ++-\n compat/mingw.c                  |   60 ------------------\n compat/mingw.h                  |   29 ---------\n compat/msvc.c                   |   29 ---------\n compat/vcbuild/include/dirent.h |  128 ---------------------------------------\n compat/win32/dirent.c           |  105 ++++++++++++++++++++++++++++++++\n compat/win32/dirent.h           |   24 +++++++\n 7 files changed, 134 insertions(+), 248 deletions(-)\n delete mode 100644 compat/vcbuild/include/dirent.h\n create mode 100644 compat/win32/dirent.c\n create mode 100644 compat/win32/dirent.h\n\n-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156407","messageId":"1290533444-3404-2-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:39Z","receivedAt":"2010-11-23T17:30:39Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/msvc.c |    5 +----\n 1 files changed, 1 insertions(+), 4 deletions(-)\n\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex ac04a4c..db3df51 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -7,16 +7,13 @@ DIR *opendir(const char *name)\n {\n \tint len;\n \tDIR *p;\n-\tp = (DIR*)malloc(sizeof(DIR));\n+\tp = xmalloc(sizeof(DIR));\n \tmemset(p, 0, sizeof(DIR));\n \tstrncpy(p->dd_name, name, PATH_MAX);\n \tlen = strlen(p->dd_name);\n \tp->dd_name[len] = '/';\n \tp->dd_name[len+1] = '*';\n \n-\tif (p == NULL)\n-\t\treturn NULL;\n-\n \tp->dd_handle = _findfirst(p->dd_name, &p->dd_dta);\n \n \tif (p->dd_handle == -1) {\n-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156405","messageId":"1290533444-3404-3-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 2/6] msvc: opendir: allocate enough memory","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:40Z","receivedAt":"2010-11-23T17:30:40Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"The defintion of DIR expects the allocating function to extend\ndd_name by over-allocating. This is not currently done in our\nimplementation of opendir. Fix this.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/msvc.c |    9 ++++-----\n 1 files changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex db3df51..205304e 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -5,12 +5,11 @@\n \n DIR *opendir(const char *name)\n {\n-\tint len;\n+\tint len = strlen(p->dd_name);\n \tDIR *p;\n-\tp = xmalloc(sizeof(DIR));\n-\tmemset(p, 0, sizeof(DIR));\n-\tstrncpy(p->dd_name, name, PATH_MAX);\n-\tlen = strlen(p->dd_name);\n+\tp = xmalloc(sizeof(DIR) + len + 2);\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-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156410","messageId":"1290533444-3404-4-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 3/6] msvc: opendir: do not start the search","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:41Z","receivedAt":"2010-11-23T17:30:41Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"compat/mingw.c's readdir expects to be the one that starts the search,\nand if it isn't, then the first entry will be missing or incorrect.\n\nFix this by removing the call to _findfirst, and initializing dd_handle\nto INVALID_HANDLE_VALUE.\n\nAt the same time, make sure we use FindClose instead of _findclose,\nwhich is symmetric to readdir's FindFirstFile. Take into account that\nthe find-handle might already be closed by readdir.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/msvc.c |   10 +++-------\n 1 files changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex 205304e..38f2d92 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -13,17 +13,13 @@ DIR *opendir(const char *name)\n \tp->dd_name[len] = '/';\n \tp->dd_name[len+1] = '*';\n \n-\tp->dd_handle = _findfirst(p->dd_name, &p->dd_dta);\n-\n-\tif (p->dd_handle == -1) {\n-\t\tfree(p);\n-\t\treturn NULL;\n-\t}\n+\tp->dd_handle = (long)INVALID_HANDLE_VALUE;\n \treturn p;\n }\n int closedir(DIR *dir)\n {\n-\t_findclose(dir->dd_handle);\n+\tif (dir->dd_handle != (long)INVALID_HANDLE_VALUE)\n+\t\tFindClose((HANDLE)dir->dd_handle);\n \tfree(dir);\n \treturn 0;\n }\n-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156408","messageId":"1290533444-3404-5-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 4/6] win32: dirent: handle errors","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:42Z","receivedAt":"2010-11-23T17:30:42Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Previously all error conditions were ignored. Be nice, and set errno\nwhen we should.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/mingw.c |    2 +-\n compat/msvc.c  |   28 +++++++++++++++++++++++++++-\n 2 files changed, 28 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex fdbf093..d8fd5d8 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1584,7 +1584,7 @@ struct dirent *mingw_readdir(DIR *dir)\n \tHANDLE handle;\n \tstruct mingw_DIR *mdir = (struct mingw_DIR*)dir;\n \n-\tif (!dir->dd_handle) {\n+\tif (!dir || !dir->dd_handle) {\n \t\terrno = EBADF; /* No set_errno for mingw */\n \t\treturn NULL;\n \t}\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex 38f2d92..8417fd3 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -5,8 +5,29 @@\n \n DIR *opendir(const char *name)\n {\n-\tint len = strlen(p->dd_name);\n+\tDWORD attrs = GetFileAttributes(name);\n+\tint len;\n \tDIR *p;\n+\n+\t/* check for valid path */\n+\tif (attrs == INVALID_FILE_ATTRIBUTES) {\n+\t\terrno = ENOENT;\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 (len + 2 >= MAX_PATH) {\n+\t\terrno = ENAMETOOLONG;\n+\t\treturn NULL;\n+\t}\n+\n \tp = xmalloc(sizeof(DIR) + len + 2);\n \tmemset(p, 0, sizeof(DIR) + len + 2);\n \tstrcpy(p->dd_name, name);\n@@ -18,6 +39,11 @@ DIR *opendir(const char *name)\n }\n int closedir(DIR *dir)\n {\n+\tif (!dir) {\n+\t\terrno = EBADF;\n+\t\treturn -1;\n+\t}\n+\n \tif (dir->dd_handle != (long)INVALID_HANDLE_VALUE)\n \t\tFindClose((HANDLE)dir->dd_handle);\n \tfree(dir);\n-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156412","messageId":"1290533444-3404-6-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 5/6] msvc: opendir: handle paths ending with a slash","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:43Z","receivedAt":"2010-11-23T17:30:43Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/msvc.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex 8417fd3..29fd877 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -23,6 +23,8 @@ DIR *opendir(const char *name)\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-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156411","messageId":"1290533444-3404-7-git-send-email-kusmabite@gmail.com","threadId":"25822","inReplyTo":"1290533444-3404-1-git-send-email-kusmabite@gmail.com","subject":"[RFC PATCH 6/6] win32: use our own dirent.h","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:30:44Z","receivedAt":"2010-11-23T17:30:44Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"The mingw-runtime implemenation of opendir, readdir and closedir\nsets errno to 0 on success, something that POSIX explicitly\nforbids. 3ba7a06 (\"A loose object is not corrupt if it cannot be\nread due to EMFILE\") introduce a dependency on this behaviour,\nleading to a broken \"git clone\" on Windows.\n\ncompat/mingw.c contains an implementation of readdir, and\ncompat/msvc.c contains implementations of opendir and closedir.\n\nMove these to compat/win32/dirent.[ch], and change to our own DIR\nstructure at the same time.\n\nThis provides a generic Win32-implementation of opendir, readdir\nand closedir which works on both MinGW and MSVC and does not reset\nerrno, and as a result git clone is working again on Windows.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n Makefile                        |    7 ++-\n compat/mingw.c                  |   60 ------------------\n compat/mingw.h                  |   29 ---------\n compat/msvc.c                   |   49 ---------------\n compat/vcbuild/include/dirent.h |  128 ---------------------------------------\n compat/win32/dirent.c           |  105 ++++++++++++++++++++++++++++++++\n compat/win32/dirent.h           |   24 +++++++\n 7 files changed, 134 insertions(+), 268 deletions(-)\n delete mode 100644 compat/vcbuild/include/dirent.h\n create mode 100644 compat/win32/dirent.c\n create mode 100644 compat/win32/dirent.h\n\ndiff --git a/Makefile b/Makefile\nindex ca1d1fe..765aad4 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -499,6 +499,7 @@ LIB_H += compat/mingw.h\n LIB_H += compat/win32/pthread.h\n LIB_H += compat/win32/syslog.h\n LIB_H += compat/win32/sys/poll.h\n+LIB_H += compat/win32/dirent.h\n LIB_H += csum-file.h\n LIB_H += decorate.h\n LIB_H += delta.h\n@@ -1086,7 +1087,9 @@ ifeq ($(uname_S),Windows)\n \tAR = compat/vcbuild/scripts/lib.pl\n \tCFLAGS =\n \tBASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE\n-\tCOMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o compat/win32/pthread.o compat/win32/syslog.o compat/win32/sys/poll.o\n+\tCOMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o \\\n+\t\tcompat/win32/pthread.o compat/win32/syslog.o \\\n+\t\tcompat/win32/sys/poll.o compat/win32/dirent.o\n \tCOMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -Icompat/win32 -DSTRIP_EXTENSION=\\\".exe\\\"\n \tBASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib\n \tEXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib\n@@ -1158,7 +1161,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tCOMPAT_CFLAGS += -DSTRIP_EXTENSION=\\\".exe\\\"\n \tCOMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \\\n \t\tcompat/win32/pthread.o compat/win32/syslog.o \\\n-\t\tcompat/win32/sys/poll.o\n+\t\tcompat/win32/sys/poll.o compat/win32/dirent.o\n \tEXTLIBS += -lws2_32\n \tPTHREAD_LIBS =\n \tX = .exe\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex d8fd5d8..bee6054 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1566,63 +1566,3 @@ pid_t waitpid(pid_t pid, int *status, unsigned options)\n \terrno = EINVAL;\n \treturn -1;\n }\n-\n-#ifndef NO_MINGW_REPLACE_READDIR\n-/* MinGW readdir implementation to avoid extra lstats for Git */\n-struct mingw_DIR\n-{\n-\tstruct _finddata_t\tdd_dta;\t\t/* disk transfer area for this dir */\n-\tstruct mingw_dirent\tdd_dir;\t\t/* Our own implementation, including d_type */\n-\tlong\t\t\tdd_handle;\t/* _findnext handle */\n-\tint\t\t\tdd_stat; \t/* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */\n-\tchar\t\t\tdd_name[1]; \t/* given path for dir with search pattern (struct is extended) */\n-};\n-\n-struct dirent *mingw_readdir(DIR *dir)\n-{\n-\tWIN32_FIND_DATAA buf;\n-\tHANDLE handle;\n-\tstruct mingw_DIR *mdir = (struct mingw_DIR*)dir;\n-\n-\tif (!dir || !dir->dd_handle) {\n-\t\terrno = EBADF; /* No set_errno for mingw */\n-\t\treturn NULL;\n-\t}\n-\n-\tif (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0)\n-\t{\n-\t\tDWORD lasterr;\n-\t\thandle = FindFirstFileA(dir->dd_name, &buf);\n-\t\tlasterr = GetLastError();\n-\t\tdir->dd_handle = (long)handle;\n-\t\tif (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) {\n-\t\t\terrno = err_win_to_posix(lasterr);\n-\t\t\treturn NULL;\n-\t\t}\n-\t} else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) {\n-\t\treturn NULL;\n-\t} else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) {\n-\t\tDWORD lasterr = GetLastError();\n-\t\tFindClose((HANDLE)dir->dd_handle);\n-\t\tdir->dd_handle = (long)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-\tmdir->dd_dir.d_type = 0;\n-\tif (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\n-\t\tmdir->dd_dir.d_type |= DT_DIR;\n-\telse\n-\t\tmdir->dd_dir.d_type |= DT_REG;\n-\n-\treturn (struct dirent*)&dir->dd_dir;\n-}\n-#endif // !NO_MINGW_REPLACE_READDIR\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 35d9813..2283071 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -322,35 +322,6 @@ int main(int argc, const char **argv) \\\n } \\\n static int mingw_main(c,v)\n \n-#ifndef NO_MINGW_REPLACE_READDIR\n-/*\n- * A replacement of readdir, to ensure that it reads the file type at\n- * the same time. This avoid extra unneeded lstats in git on MinGW\n- */\n-#undef DT_UNKNOWN\n-#undef DT_DIR\n-#undef DT_REG\n-#undef DT_LNK\n-#define DT_UNKNOWN\t0\n-#define DT_DIR\t\t1\n-#define DT_REG\t\t2\n-#define DT_LNK\t\t3\n-\n-struct mingw_dirent\n-{\n-\tlong\t\td_ino;\t\t\t/* Always zero. */\n-\tunion {\n-\t\tunsigned short\td_reclen;\t/* Always zero. */\n-\t\tunsigned char   d_type;\t\t/* Reimplementation adds this */\n-\t};\n-\tunsigned short\td_namlen;\t\t/* Length of name in d_name. */\n-\tchar\t\td_name[FILENAME_MAX];\t/* File name. */\n-};\n-#define dirent mingw_dirent\n-#define readdir(x) mingw_readdir(x)\n-struct dirent *mingw_readdir(DIR *dir);\n-#endif // !NO_MINGW_REPLACE_READDIR\n-\n /*\n  * Used by Pthread API implementation for Windows\n  */\ndiff --git a/compat/msvc.c b/compat/msvc.c\nindex 29fd877..71843d7 100644\n--- a/compat/msvc.c\n+++ b/compat/msvc.c\n@@ -3,53 +3,4 @@\n #include <conio.h>\n #include \"../strbuf.h\"\n \n-DIR *opendir(const char *name)\n-{\n-\tDWORD attrs = GetFileAttributes(name);\n-\tint len;\n-\tDIR *p;\n-\n-\t/* check for valid path */\n-\tif (attrs == INVALID_FILE_ATTRIBUTES) {\n-\t\terrno = ENOENT;\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 = xmalloc(sizeof(DIR) + len + 2);\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 = (long)INVALID_HANDLE_VALUE;\n-\treturn p;\n-}\n-int closedir(DIR *dir)\n-{\n-\tif (!dir) {\n-\t\terrno = EBADF;\n-\t\treturn -1;\n-\t}\n-\n-\tif (dir->dd_handle != (long)INVALID_HANDLE_VALUE)\n-\t\tFindClose((HANDLE)dir->dd_handle);\n-\tfree(dir);\n-\treturn 0;\n-}\n-\n #include \"mingw.c\"\ndiff --git a/compat/vcbuild/include/dirent.h b/compat/vcbuild/include/dirent.h\ndeleted file mode 100644\nindex 440618d..0000000\n--- a/compat/vcbuild/include/dirent.h\n+++ /dev/null\n@@ -1,128 +0,0 @@\n-/*\n- * DIRENT.H (formerly DIRLIB.H)\n- * This file has no copyright assigned and is placed in the Public Domain.\n- * This file is a part of the mingw-runtime package.\n- *\n- * The mingw-runtime package and its code is distributed in the hope that it\n- * will be useful but WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESSED OR\n- * IMPLIED ARE HEREBY DISCLAIMED.  This includes but is not limited to\n- * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n- *\n- * You are free to use this package and its code without limitation.\n- */\n-#ifndef _DIRENT_H_\n-#define _DIRENT_H_\n-#include <io.h>\n-\n-#define PATH_MAX 512\n-\n-#define __MINGW_NOTHROW\n-\n-#ifndef RC_INVOKED\n-\n-#ifdef __cplusplus\n-extern \"C\" {\n-#endif\n-\n-struct dirent\n-{\n-\tlong\t\td_ino;\t\t/* Always zero. */\n-\tunsigned short\td_reclen;\t/* Always zero. */\n-\tunsigned short\td_namlen;\t/* Length of name in d_name. */\n-\tchar\t\td_name[FILENAME_MAX]; /* File name. */\n-};\n-\n-/*\n- * This is an internal data structure. Good programmers will not use it\n- * except as an argument to one of the functions below.\n- * dd_stat field is now int (was short in older versions).\n- */\n-typedef struct\n-{\n-\t/* disk transfer area for this dir */\n-\tstruct _finddata_t\tdd_dta;\n-\n-\t/* dirent struct to return from dir (NOTE: this makes this thread\n-\t * safe as long as only one thread uses a particular DIR struct at\n-\t * a time) */\n-\tstruct dirent\t\tdd_dir;\n-\n-\t/* _findnext handle */\n-\tlong\t\t\tdd_handle;\n-\n-\t/*\n-\t * Status of search:\n-\t *   0 = not started yet (next entry to read is first entry)\n-\t *  -1 = off the end\n-\t *   positive = 0 based index of next entry\n-\t */\n-\tint\t\t\tdd_stat;\n-\n-\t/* given path for dir with search pattern (struct is extended) */\n-\tchar\t\t\tdd_name[PATH_MAX+3];\n-} DIR;\n-\n-DIR* __cdecl __MINGW_NOTHROW opendir (const char*);\n-struct dirent* __cdecl __MINGW_NOTHROW readdir (DIR*);\n-int __cdecl __MINGW_NOTHROW closedir (DIR*);\n-void __cdecl __MINGW_NOTHROW rewinddir (DIR*);\n-long __cdecl __MINGW_NOTHROW telldir (DIR*);\n-void __cdecl __MINGW_NOTHROW seekdir (DIR*, long);\n-\n-\n-/* wide char versions */\n-\n-struct _wdirent\n-{\n-\tlong\t\td_ino;\t\t/* Always zero. */\n-\tunsigned short\td_reclen;\t/* Always zero. */\n-\tunsigned short\td_namlen;\t/* Length of name in d_name. */\n-\twchar_t\t\td_name[FILENAME_MAX]; /* File name. */\n-};\n-\n-/*\n- * This is an internal data structure. Good programmers will not use it\n- * except as an argument to one of the functions below.\n- */\n-typedef struct\n-{\n-\t/* disk transfer area for this dir */\n-\t//struct _wfinddata_t\tdd_dta;\n-\n-\t/* dirent struct to return from dir (NOTE: this makes this thread\n-\t * safe as long as only one thread uses a particular DIR struct at\n-\t * a time) */\n-\tstruct _wdirent\t\tdd_dir;\n-\n-\t/* _findnext handle */\n-\tlong\t\t\tdd_handle;\n-\n-\t/*\n-\t * Status of search:\n-\t *   0 = not started yet (next entry to read is first entry)\n-\t *  -1 = off the end\n-\t *   positive = 0 based index of next entry\n-\t */\n-\tint\t\t\tdd_stat;\n-\n-\t/* given path for dir with search pattern (struct is extended) */\n-\twchar_t\t\t\tdd_name[1];\n-} _WDIR;\n-\n-\n-\n-_WDIR* __cdecl __MINGW_NOTHROW _wopendir (const wchar_t*);\n-struct _wdirent*  __cdecl __MINGW_NOTHROW _wreaddir (_WDIR*);\n-int __cdecl __MINGW_NOTHROW _wclosedir (_WDIR*);\n-void __cdecl __MINGW_NOTHROW _wrewinddir (_WDIR*);\n-long __cdecl __MINGW_NOTHROW _wtelldir (_WDIR*);\n-void __cdecl __MINGW_NOTHROW _wseekdir (_WDIR*, long);\n-\n-\n-#ifdef\t__cplusplus\n-}\n-#endif\n-\n-#endif\t/* Not RC_INVOKED */\n-\n-#endif\t/* Not _DIRENT_H_ */\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nnew file mode 100644\nindex 0000000..659e1d7\n--- /dev/null\n+++ b/compat/win32/dirent.c\n@@ -0,0 +1,105 @@\n+#include \"../git-compat-util.h\"\n+#include \"dirent.h\"\n+\n+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+DIR *opendir(const char *name)\n+{\n+\tDWORD attrs = GetFileAttributesA(name);\n+\tint len;\n+\tDIR *p;\n+\n+\t/* check for valid path */\n+\tif (attrs == INVALID_FILE_ATTRIBUTES) {\n+\t\terrno = ENOENT;\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 = xmalloc(sizeof(DIR) + len + 2);\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+}\n+\n+struct dirent *readdir(DIR *dir)\n+{\n+\tWIN32_FIND_DATAA buf;\n+\tHANDLE handle;\n+\n+\tif (!dir || !dir->dd_handle) {\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\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+int closedir(DIR *dir)\n+{\n+\tif (!dir) {\n+\t\terrno = EBADF;\n+\t\treturn -1;\n+\t}\n+\n+\tif (dir->dd_handle != INVALID_HANDLE_VALUE)\n+\t\tFindClose(dir->dd_handle);\n+\tfree(dir);\n+\treturn 0;\n+}\ndiff --git a/compat/win32/dirent.h b/compat/win32/dirent.h\nnew file mode 100644\nindex 0000000..927a25c\n--- /dev/null\n+++ b/compat/win32/dirent.h\n@@ -0,0 +1,24 @@\n+#ifndef DIRENT_H\n+#define DIRENT_H\n+\n+typedef struct DIR DIR;\n+\n+#define DT_UNKNOWN 0\n+#define DT_DIR     1\n+#define DT_REG     2\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. */\n+\t\tunsigned char  d_type;   /* Reimplementation adds this */\n+\t};\n+};\n+\n+DIR *opendir(const char *dirname);\n+struct dirent *readdir(DIR *dir);\n+int closedir(DIR *dir);\n+\n+#endif /* DIRENT_H */\n-- \n1.7.3.2.493.ge4bf7\n"},{"id":"156413","messageId":"20101123174050.GB12113@burratino","threadId":"25822","inReplyTo":"1290533444-3404-2-git-send-email-kusmabite@gmail.com","subject":"Re: [RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-23T17:40:50Z","receivedAt":"2010-11-23T17:40:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Erik Faye-Lund wrote:\n\n> --- a/compat/msvc.c\n> +++ b/compat/msvc.c\n> @@ -7,16 +7,13 @@ DIR *opendir(const char *name)\n>  {\n>  \tint len;\n>  \tDIR *p;\n> -\tp = (DIR*)malloc(sizeof(DIR));\n> +\tp = xmalloc(sizeof(DIR));\n>  \tmemset(p, 0, sizeof(DIR));\n>  \tstrncpy(p->dd_name, name, PATH_MAX);\n>  \tlen = strlen(p->dd_name);\n>  \tp->dd_name[len] = '/';\n>  \tp->dd_name[len+1] = '*';\n>  \n> -\tif (p == NULL)\n> -\t\treturn NULL;\n\nA behavior change but maybe a good one.  For example, the\nprune_packed_objects() loop currently skips object dirs it can't open,\neven if that is due to memory exhaustion, but this changes it to error\nout.\n\nWhat is the motivation?\n"},{"id":"156414","messageId":"20101123174215.GC12113@burratino","threadId":"25822","inReplyTo":"1290533444-3404-3-git-send-email-kusmabite@gmail.com","subject":"Re: [RFC PATCH 2/6] msvc: opendir: allocate enough memory","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-23T17:42:16Z","receivedAt":"2010-11-23T17:42:16Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Erik Faye-Lund wrote:\n\n> --- a/compat/msvc.c\n> +++ b/compat/msvc.c\n> @@ -5,12 +5,11 @@\n>  \n>  DIR *opendir(const char *name)\n>  {\n> -\tint len;\n> +\tint len = strlen(p->dd_name);\n>  \tDIR *p;\n\nDoes this work?\n"},{"id":"156415","messageId":"20101123174351.GD12113@burratino","threadId":"25822","inReplyTo":"1290533444-3404-6-git-send-email-kusmabite@gmail.com","subject":"Re: [RFC PATCH 5/6] msvc: opendir: handle paths ending with a slash","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-23T17:43:51Z","receivedAt":"2010-11-23T17:43:51Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Erik Faye-Lund wrote:\n\n> --- a/compat/msvc.c\n> +++ b/compat/msvc.c\n> @@ -23,6 +23,8 @@ DIR *opendir(const char *name)\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\nI assume len can't be 0?\n"},{"id":"156417","messageId":"AANLkTiknTQp96PeiBd+MqCO6uEs1mCzFYDsW8NwYpBsm@mail.gmail.com","threadId":"25822","inReplyTo":"20101123174050.GB12113@burratino","subject":"Re: [RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:45:07Z","receivedAt":"2010-11-23T17:45:07Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 6:40 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Erik Faye-Lund wrote:\n>\n>> --- a/compat/msvc.c\n>> +++ b/compat/msvc.c\n>> @@ -7,16 +7,13 @@ DIR *opendir(const char *name)\n>>  {\n>>       int len;\n>>       DIR *p;\n>> -     p = (DIR*)malloc(sizeof(DIR));\n>> +     p = xmalloc(sizeof(DIR));\n>>       memset(p, 0, sizeof(DIR));\n>>       strncpy(p->dd_name, name, PATH_MAX);\n>>       len = strlen(p->dd_name);\n>>       p->dd_name[len] = '/';\n>>       p->dd_name[len+1] = '*';\n>>\n>> -     if (p == NULL)\n>> -             return NULL;\n>\n> A behavior change but maybe a good one.  For example, the\n> prune_packed_objects() loop currently skips object dirs it can't open,\n> even if that is due to memory exhaustion, but this changes it to error\n> out.\n>\n> What is the motivation?\n>\n\nThe motivation is just to avoid having to deal with the error, like we\ndo other places. It's not a big deal though. I could also set errno to\nENOMEM and return NULL if that's preferable. I just don't see how it\nis.\n\nI also slightly dislike setting an error not listed in POSIX'\ndocumentation of opendir, even though it's probably allowed.\n"},{"id":"156416","messageId":"20101123174519.GE12113@burratino","threadId":"25822","inReplyTo":"1290533444-3404-7-git-send-email-kusmabite@gmail.com","subject":"Re: [RFC PATCH 6/6] win32: use our own dirent.h","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-23T17:45:19Z","receivedAt":"2010-11-23T17:45:19Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Erik Faye-Lund wrote:\n\n> This provides a generic Win32-implementation of opendir, readdir\n> and closedir which works on both MinGW and MSVC and does not reset\n> errno, and as a result git clone is working again on Windows.\n\nNice!  Thanks.\n\n>  Makefile                        |    7 ++-\n>  compat/mingw.c                  |   60 ------------------\n>  compat/mingw.h                  |   29 ---------\n>  compat/msvc.c                   |   49 ---------------\n>  compat/vcbuild/include/dirent.h |  128 ---------------------------------------\n>  compat/win32/dirent.c           |  105 ++++++++++++++++++++++++++++++++\n>  compat/win32/dirent.h           |   24 +++++++\n>  7 files changed, 134 insertions(+), 268 deletions(-)\n>  delete mode 100644 compat/vcbuild/include/dirent.h\n>  create mode 100644 compat/win32/dirent.c\n>  create mode 100644 compat/win32/dirent.h\n\nDoes this diff get smaller with -M -C -C -C?\n"},{"id":"156418","messageId":"AANLkTi=jYXbaw5kKtbhr9rPYe+DYxrbF2NA76eQD_uz+@mail.gmail.com","threadId":"25822","inReplyTo":"20101123174215.GC12113@burratino","subject":"Re: [RFC PATCH 2/6] msvc: opendir: allocate enough memory","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:46:45Z","receivedAt":"2010-11-23T17:46:45Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 6:42 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Erik Faye-Lund wrote:\n>\n>> --- a/compat/msvc.c\n>> +++ b/compat/msvc.c\n>> @@ -5,12 +5,11 @@\n>>\n>>  DIR *opendir(const char *name)\n>>  {\n>> -     int len;\n>> +     int len = strlen(p->dd_name);\n>>       DIR *p;\n>\n> Does this work?\n>\n\nWhoops. It does work for me, but it shouldn't. I guess malloc is\nover-allocating, and git is only using short paths.\n\nThanks for catching it.\n"},{"id":"156419","messageId":"AANLkTi=Yg2Dz7DgtixWBbvbUn_rrdJcgqMYiBqHFwosb@mail.gmail.com","threadId":"25822","inReplyTo":"20101123174351.GD12113@burratino","subject":"Re: [RFC PATCH 5/6] msvc: opendir: handle paths ending with a slash","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:47:51Z","receivedAt":"2010-11-23T17:47:51Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 6:43 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Erik Faye-Lund wrote:\n>\n>> --- a/compat/msvc.c\n>> +++ b/compat/msvc.c\n>> @@ -23,6 +23,8 @@ DIR *opendir(const char *name)\n>>\n>>       /* check that the pattern won't be too long for FindFirstFileA */\n>>       len = strlen(name);\n>> +     if (is_dir_sep(name[len - 1]))\n>> +             len--;\n>\n> I assume len can't be 0?\n>\n\nNope, in that case GetFileAttributesA would have errore out.\n"},{"id":"156420","messageId":"AANLkTinvtdwP_C1PcFkOXfFEHfOAj3dPAfa1xyUrttEu@mail.gmail.com","threadId":"25822","inReplyTo":"20101123174519.GE12113@burratino","subject":"Re: [RFC PATCH 6/6] win32: use our own dirent.h","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T17:51:42Z","receivedAt":"2010-11-23T17:51:42Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 6:45 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Erik Faye-Lund wrote:\n>\n>> This provides a generic Win32-implementation of opendir, readdir\n>> and closedir which works on both MinGW and MSVC and does not reset\n>> errno, and as a result git clone is working again on Windows.\n>\n> Nice!  Thanks.\n>\n>>  Makefile                        |    7 ++-\n>>  compat/mingw.c                  |   60 ------------------\n>>  compat/mingw.h                  |   29 ---------\n>>  compat/msvc.c                   |   49 ---------------\n>>  compat/vcbuild/include/dirent.h |  128 ---------------------------------------\n>>  compat/win32/dirent.c           |  105 ++++++++++++++++++++++++++++++++\n>>  compat/win32/dirent.h           |   24 +++++++\n>>  7 files changed, 134 insertions(+), 268 deletions(-)\n>>  delete mode 100644 compat/vcbuild/include/dirent.h\n>>  create mode 100644 compat/win32/dirent.c\n>>  create mode 100644 compat/win32/dirent.h\n>\n> Does this diff get smaller with -M -C -C -C?\n>\n\nNope. I guess the reason is that I've adjusted the code a bit while\nmoving it, because I didn't need to cast back and forth between HANDLE\nanymore.\n"},{"id":"156421","messageId":"AANLkTin01j-yb1j7WsCkZ2MThJ80qbcOw5yjE5LxrqJZ@mail.gmail.com","threadId":"25822","inReplyTo":"AANLkTiknTQp96PeiBd+MqCO6uEs1mCzFYDsW8NwYpBsm@mail.gmail.com","subject":"Re: [RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T18:00:28Z","receivedAt":"2010-11-23T18:00:28Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 6:45 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:\n> On Tue, Nov 23, 2010 at 6:40 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>> Erik Faye-Lund wrote:\n>>\n>>> --- a/compat/msvc.c\n>>> +++ b/compat/msvc.c\n>>> @@ -7,16 +7,13 @@ DIR *opendir(const char *name)\n>>>  {\n>>>       int len;\n>>>       DIR *p;\n>>> -     p = (DIR*)malloc(sizeof(DIR));\n>>> +     p = xmalloc(sizeof(DIR));\n>>>       memset(p, 0, sizeof(DIR));\n>>>       strncpy(p->dd_name, name, PATH_MAX);\n>>>       len = strlen(p->dd_name);\n>>>       p->dd_name[len] = '/';\n>>>       p->dd_name[len+1] = '*';\n>>>\n>>> -     if (p == NULL)\n>>> -             return NULL;\n>>\n>> A behavior change but maybe a good one.  For example, the\n>> prune_packed_objects() loop currently skips object dirs it can't open,\n>> even if that is due to memory exhaustion, but this changes it to error\n>> out.\n>>\n>> What is the motivation?\n>>\n>\n> The motivation is just to avoid having to deal with the error, like we\n> do other places. It's not a big deal though. I could also set errno to\n> ENOMEM and return NULL if that's preferable. I just don't see how it\n> is.\n>\n> I also slightly dislike setting an error not listed in POSIX'\n> documentation of opendir, even though it's probably allowed.\n>\n\nOf course, I don't have to set errno; malloc would already have done\nthat. All I need to do is move the check for NULL a bit earlier, so it\nwon't segfault on ENOMEM. I'll change it for the next round.\n"},{"id":"156422","messageId":"20101123180250.GF12113@burratino","threadId":"25822","inReplyTo":"AANLkTiknTQp96PeiBd+MqCO6uEs1mCzFYDsW8NwYpBsm@mail.gmail.com","subject":"Re: [RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-23T18:02:50Z","receivedAt":"2010-11-23T18:02:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Erik Faye-Lund wrote:\n\n> The motivation is just to avoid having to deal with the error, like we\n> do other places. It's not a big deal though. I could also set errno to\n> ENOMEM and return NULL if that's preferable. I just don't see how it\n> is.\n\nI don't disagree; just fishing for a commit message. :)\n\n> I also slightly dislike setting an error not listed in POSIX'\n> documentation of opendir, even though it's probably allowed.\n\nFor future reference, here's what POSIX has to say.\n\n\tImplementations shall not generate a different error\n\tnumber from one required by this volume of\n\tPOSIX.1-2008 for an error condition described in this\n\tvolume of POSIX.1-2008, but may generate additional\n\terrors unless explicitly disallowed for a particular\n\tfunction.\n\nSo ENOMEM would have been allowed from that front.\n"},{"id":"156423","messageId":"AANLkTimXgnYePPwZNDapS53JSnmO-D-xLxHbLaP8HVv0@mail.gmail.com","threadId":"25822","inReplyTo":"20101123180250.GF12113@burratino","subject":"Re: [RFC PATCH 1/6] msvc: opendir: use xmalloc","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2010-11-23T18:12:08Z","receivedAt":"2010-11-23T18:12:08Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Tue, Nov 23, 2010 at 7:02 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Erik Faye-Lund wrote:\n>\n>> The motivation is just to avoid having to deal with the error, like we\n>> do other places. It's not a big deal though. I could also set errno to\n>> ENOMEM and return NULL if that's preferable. I just don't see how it\n>> is.\n>\n> I don't disagree; just fishing for a commit message. :)\n>\n\nYes, but after stopping to think about it a tad more, I tend to like\nit working more similar to existing POSIX implementations.\n\nI am adding a commit message this time, though! ;)\n\n>> I also slightly dislike setting an error not listed in POSIX'\n>> documentation of opendir, even though it's probably allowed.\n>\n> For future reference, here's what POSIX has to say.\n>\n>        Implementations shall not generate a different error\n>        number from one required by this volume of\n>        POSIX.1-2008 for an error condition described in this\n>        volume of POSIX.1-2008, but may generate additional\n>        errors unless explicitly disallowed for a particular\n>        function.\n>\n> So ENOMEM would have been allowed from that front.\n>\n\nThanks for the clarification.\n"}]}