summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 20c6788)
raw | patch | inline | side by side (parent: 20c6788)
author | Erik Faye-Lund <kusmabite@gmail.com> | |
Tue, 23 Nov 2010 18:38:27 +0000 (19:38 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 24 Nov 2010 00:06:47 +0000 (16:06 -0800) |
Previously all error conditions were ignored. Be nice, and set errno
when we should.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
when we should.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c | patch | blob | history | |
compat/msvc.c | patch | blob | history |
diff --git a/compat/mingw.c b/compat/mingw.c
index 29f403649f0e3c6d4240fc93e6fa1787a017b9ea..9f8f37f062fb532a2b91490e924f5fb4ea9df0c2 100644 (file)
--- a/compat/mingw.c
+++ b/compat/mingw.c
HANDLE handle;
struct mingw_DIR *mdir = (struct mingw_DIR*)dir;
- if (!dir->dd_handle) {
+ if (!dir || !dir->dd_handle) {
errno = EBADF; /* No set_errno for mingw */
return NULL;
}
diff --git a/compat/msvc.c b/compat/msvc.c
index 88c6093258eaa117996668026734ea8e6eb2761a..199eb220f42032c1b50dd226dbea084cc10ccd38 100644 (file)
--- a/compat/msvc.c
+++ b/compat/msvc.c
DIR *opendir(const char *name)
{
- int len = strlen(name);
+ DWORD attrs = GetFileAttributes(name);
+ int len;
DIR *p;
+
+ /* check for valid path */
+ if (attrs == INVALID_FILE_ATTRIBUTES) {
+ errno = ENOENT;
+ return NULL;
+ }
+
+ /* check if it's a directory */
+ if (!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
+ errno = ENOTDIR;
+ return NULL;
+ }
+
+ /* check that the pattern won't be too long for FindFirstFileA */
+ len = strlen(name);
+ if (len + 2 >= MAX_PATH) {
+ errno = ENAMETOOLONG;
+ return NULL;
+ }
+
p = malloc(sizeof(DIR) + len + 2);
if (!p)
return NULL;
}
int closedir(DIR *dir)
{
+ if (!dir) {
+ errno = EBADF;
+ return -1;
+ }
+
if (dir->dd_handle != (long)INVALID_HANDLE_VALUE)
FindClose((HANDLE)dir->dd_handle);
free(dir);