diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-12-12 21:49:52 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-12 21:49:52 -0800 |
commit | 1e86274cd4e544628d5f6e327eb62094051e7948 (patch) | |
tree | 93da98aa1cf2d76c0a1caf3266ff36e8d2a3de12 /compat/mingw.c | |
parent | cd425a1585bf0c1b92faa772b664dadd3294bf19 (diff) | |
parent | d1b6e6e015501272c7491b3a4adf3cd3904edefa (diff) | |
download | git-1e86274cd4e544628d5f6e327eb62094051e7948.tar.gz |
Merge branch 'ef/win32-dirent'
* ef/win32-dirent:
win32: use our own dirent.h
msvc: opendir: handle paths ending with a slash
win32: dirent: handle errors
msvc: opendir: do not start the search
msvc: opendir: allocate enough memory
msvc: opendir: fix malloc-failure
Conflicts:
Makefile
Diffstat (limited to 'compat/mingw.c')
-rw-r--r-- | compat/mingw.c | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index fdbf093f6e..bee6054419 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1566,63 +1566,3 @@ pid_t waitpid(pid_t pid, int *status, unsigned options) errno = EINVAL; return -1; } - -#ifndef NO_MINGW_REPLACE_READDIR -/* MinGW readdir implementation to avoid extra lstats for Git */ -struct mingw_DIR -{ - struct _finddata_t dd_dta; /* disk transfer area for this dir */ - struct mingw_dirent dd_dir; /* Our own implementation, including d_type */ - long dd_handle; /* _findnext handle */ - int dd_stat; /* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */ - char dd_name[1]; /* given path for dir with search pattern (struct is extended) */ -}; - -struct dirent *mingw_readdir(DIR *dir) -{ - WIN32_FIND_DATAA buf; - HANDLE handle; - struct mingw_DIR *mdir = (struct mingw_DIR*)dir; - - if (!dir->dd_handle) { - errno = EBADF; /* No set_errno for mingw */ - return NULL; - } - - if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0) - { - DWORD lasterr; - handle = FindFirstFileA(dir->dd_name, &buf); - lasterr = GetLastError(); - dir->dd_handle = (long)handle; - if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) { - errno = err_win_to_posix(lasterr); - return NULL; - } - } else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) { - return NULL; - } else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) { - DWORD lasterr = GetLastError(); - FindClose((HANDLE)dir->dd_handle); - dir->dd_handle = (long)INVALID_HANDLE_VALUE; - /* POSIX says you shouldn't set errno when readdir can't - find any more files; so, if another error we leave it set. */ - if (lasterr != ERROR_NO_MORE_FILES) - errno = err_win_to_posix(lasterr); - return NULL; - } - - /* We get here if `buf' contains valid data. */ - strcpy(dir->dd_dir.d_name, buf.cFileName); - ++dir->dd_stat; - - /* Set file type, based on WIN32_FIND_DATA */ - mdir->dd_dir.d_type = 0; - if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - mdir->dd_dir.d_type |= DT_DIR; - else - mdir->dd_dir.d_type |= DT_REG; - - return (struct dirent*)&dir->dd_dir; -} -#endif // !NO_MINGW_REPLACE_READDIR |