diff options
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/dir.c | 2 | ||||
-rw-r--r-- | src/win32/error.c | 2 | ||||
-rw-r--r-- | src/win32/findfile.c | 1 | ||||
-rw-r--r-- | src/win32/git2.rc | 10 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 141 | ||||
-rw-r--r-- | src/win32/pthread.c | 24 | ||||
-rw-r--r-- | src/win32/pthread.h | 11 |
7 files changed, 112 insertions, 79 deletions
diff --git a/src/win32/dir.c b/src/win32/dir.c index 95ae5060e..8c51d8378 100644 --- a/src/win32/dir.c +++ b/src/win32/dir.c @@ -32,7 +32,7 @@ git__DIR *git__opendir(const char *dir) if (!dir || !init_filter(filter, sizeof(filter), dir)) return NULL; - new = git__malloc(sizeof(*new)); + new = git__calloc(1, sizeof(*new)); if (!new) return NULL; diff --git a/src/win32/error.c b/src/win32/error.c index 4a9a0631f..a62a07e82 100644 --- a/src/win32/error.c +++ b/src/win32/error.c @@ -12,7 +12,9 @@ # include <winhttp.h> #endif +#ifndef WC_ERR_INVALID_CHARS #define WC_ERR_INVALID_CHARS 0x80 +#endif char *git_win32_get_error_message(DWORD error_code) { diff --git a/src/win32/findfile.c b/src/win32/findfile.c index bc36b6b45..5dd3de13d 100644 --- a/src/win32/findfile.c +++ b/src/win32/findfile.c @@ -235,4 +235,3 @@ int git_win32__find_xdg_dirs(git_buf *out) return win32_find_existing_dirs(out, global_tmpls, temp); } - diff --git a/src/win32/git2.rc b/src/win32/git2.rc index 436913228..22c63f695 100644 --- a/src/win32/git2.rc +++ b/src/win32/git2.rc @@ -1,10 +1,8 @@ #include <winver.h> #include "../../include/git2/version.h" -#ifndef INCLUDE_LIB -#define LIBGIT2_FILENAME "git2.dll" -#else -#define LIBGIT2_FILENAME "libgit2.dll" +#ifndef LIBGIT2_FILENAME +# define LIBGIT2_FILENAME "git2" #endif VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE @@ -27,9 +25,9 @@ BEGIN BEGIN VALUE "FileDescription", "libgit2 - the Git linkable library\0" VALUE "FileVersion", LIBGIT2_VERSION "\0" - VALUE "InternalName", LIBGIT2_FILENAME "\0" + VALUE "InternalName", LIBGIT2_FILENAME ".dll\0" VALUE "LegalCopyright", "Copyright (C) the libgit2 contributors. All rights reserved.\0" - VALUE "OriginalFilename", LIBGIT2_FILENAME "\0" + VALUE "OriginalFilename", LIBGIT2_FILENAME ".dll\0" VALUE "ProductName", "libgit2\0" VALUE "ProductVersion", LIBGIT2_VERSION "\0" VALUE "Comments", "For more information visit http://libgit2.github.com/\0" diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 4d56299f7..f04974428 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -5,6 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ #include "../posix.h" +#include "../fileops.h" #include "path.h" #include "utf-conv.h" #include "repository.h" @@ -295,7 +296,18 @@ int p_getcwd(char *buffer_out, size_t size) int p_stat(const char* path, struct stat* buf) { - return do_lstat(path, buf, 0); + char target[GIT_WIN_PATH]; + int error = 0; + + error = do_lstat(path, buf, 0); + + /* We need not do this in a loop to unwind chains of symlinks since + * p_readlink calls GetFinalPathNameByHandle which does it for us. */ + if (error >= 0 && S_ISLNK(buf->st_mode) && + (error = p_readlink(path, target, GIT_WIN_PATH)) >= 0) + error = do_lstat(target, buf, 0); + + return error; } int p_chdir(const char* path) @@ -314,9 +326,20 @@ int p_chmod(const char* path, mode_t mode) int p_rmdir(const char* path) { + int error; wchar_t buf[GIT_WIN_PATH]; git__utf8_to_16(buf, GIT_WIN_PATH, path); - return _wrmdir(buf); + + error = _wrmdir(buf); + + /* _wrmdir() is documented to return EACCES if "A program has an open + * handle to the directory." This sounds like what everybody else calls + * EBUSY. Let's convert appropriate error codes. + */ + if (GetLastError() == ERROR_SHARING_VIOLATION) + errno = EBUSY; + + return error; } int p_hide_directory__w32(const char *path) @@ -457,29 +480,29 @@ int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags) * Borrowed from http://old.nabble.com/Porting-localtime_r-and-gmtime_r-td15282276.html * On Win32, `gmtime_r` doesn't exist but `gmtime` is threadsafe, so we can use that */ -struct tm * -p_localtime_r (const time_t *timer, struct tm *result) -{ - struct tm *local_result; - local_result = localtime (timer); - - if (local_result == NULL || result == NULL) - return NULL; - - memcpy (result, local_result, sizeof (struct tm)); - return result; -} -struct tm * -p_gmtime_r (const time_t *timer, struct tm *result) -{ - struct tm *local_result; - local_result = gmtime (timer); - - if (local_result == NULL || result == NULL) - return NULL; - - memcpy (result, local_result, sizeof (struct tm)); - return result; +struct tm * +p_localtime_r (const time_t *timer, struct tm *result) +{ + struct tm *local_result; + local_result = localtime (timer); + + if (local_result == NULL || result == NULL) + return NULL; + + memcpy (result, local_result, sizeof (struct tm)); + return result; +} +struct tm * +p_gmtime_r (const time_t *timer, struct tm *result) +{ + struct tm *local_result; + local_result = gmtime (timer); + + if (local_result == NULL || result == NULL) + return NULL; + + memcpy (result, local_result, sizeof (struct tm)); + return result; } #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) @@ -492,44 +515,44 @@ p_gmtime_r (const time_t *timer, struct tm *result) #define _TIMEZONE_DEFINED struct timezone { - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ }; #endif - + int p_gettimeofday(struct timeval *tv, struct timezone *tz) { - FILETIME ft; - unsigned __int64 tmpres = 0; - static int tzflag; - - if (NULL != tv) - { - GetSystemTimeAsFileTime(&ft); - - tmpres |= ft.dwHighDateTime; - tmpres <<= 32; - tmpres |= ft.dwLowDateTime; - - /*converting file time to unix epoch*/ - tmpres /= 10; /*convert into microseconds*/ - tmpres -= DELTA_EPOCH_IN_MICROSECS; - tv->tv_sec = (long)(tmpres / 1000000UL); - tv->tv_usec = (long)(tmpres % 1000000UL); - } - - if (NULL != tz) - { - if (!tzflag) - { - _tzset(); - tzflag++; - } - tz->tz_minuteswest = _timezone / 60; - tz->tz_dsttime = _daylight; - } - - return 0; + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres /= 10; /*convert into microseconds*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; } int p_inet_pton(int af, const char* src, void* dst) diff --git a/src/win32/pthread.c b/src/win32/pthread.c index 105f4b89e..2f263b3e0 100644 --- a/src/win32/pthread.c +++ b/src/win32/pthread.c @@ -14,22 +14,30 @@ int pthread_create( void *GIT_RESTRICT arg) { GIT_UNUSED(attr); - *thread = (pthread_t) CreateThread( + *thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); return *thread ? 0 : -1; } int pthread_join(pthread_t thread, void **value_ptr) { - int ret; - ret = WaitForSingleObject(thread, INFINITE); - if (ret && value_ptr) - GetExitCodeThread(thread, (void*) value_ptr); - return -(!!ret); + DWORD ret = WaitForSingleObject(thread, INFINITE); + + if (ret == WAIT_OBJECT_0) { + if (value_ptr != NULL) { + *value_ptr = NULL; + GetExitCodeThread(thread, (void *)value_ptr); + } + CloseHandle(thread); + return 0; + } + + return -1; } -int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex, - const pthread_mutexattr_t *GIT_RESTRICT mutexattr) +int pthread_mutex_init( + pthread_mutex_t *GIT_RESTRICT mutex, + const pthread_mutexattr_t *GIT_RESTRICT mutexattr) { GIT_UNUSED(mutexattr); InitializeCriticalSection(mutex); diff --git a/src/win32/pthread.h b/src/win32/pthread.h index a219a0137..8277ecf6e 100644 --- a/src/win32/pthread.h +++ b/src/win32/pthread.h @@ -25,13 +25,16 @@ typedef HANDLE pthread_cond_t; #define PTHREAD_MUTEX_INITIALIZER {(void*)-1}; -int pthread_create(pthread_t *GIT_RESTRICT, - const pthread_attr_t *GIT_RESTRICT, - void *(*start_routine)(void*), void *__restrict); +int pthread_create( + pthread_t *GIT_RESTRICT, + const pthread_attr_t *GIT_RESTRICT, + void *(*start_routine)(void*), + void *__restrict); int pthread_join(pthread_t, void **); -int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT, const pthread_mutexattr_t *GIT_RESTRICT); +int pthread_mutex_init( + pthread_mutex_t *GIT_RESTRICT, const pthread_mutexattr_t *GIT_RESTRICT); int pthread_mutex_destroy(pthread_mutex_t *); int pthread_mutex_lock(pthread_mutex_t *); int pthread_mutex_unlock(pthread_mutex_t *); |