From c2408a698ad395c8bd84297de839080d131c6d6d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 1 Nov 2013 17:03:01 -0400 Subject: [PATCH] preserve windows error numbers as well --- src/common.h | 24 ++++++++++++++++++++++++ src/fileops.c | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/common.h b/src/common.h index 02d9ce9b6..159d31b2e 100644 --- a/src/common.h +++ b/src/common.h @@ -73,6 +73,30 @@ void giterr_set(int error_class, const char *string, ...); */ int giterr_set_regex(const regex_t *regex, int error_code); +/** + * Gets the system error code for this thread. + */ +GIT_INLINE(int) giterr_system_last(void) +{ +#ifdef GIT_WIN32 + return GetLastError(); +#else + return errno; +#endif +} + +/** + * Sets the system error code for this thread. + */ +GIT_INLINE(void) giterr_system_set(int code) +{ +#ifdef GIT_WIN32 + SetLastError(code); +#else + errno = code; +#endif +} + /** * Check a versioned structure for validity */ diff --git a/src/fileops.c b/src/fileops.c index 17007f823..54bf5d850 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -343,11 +343,11 @@ int git_futils_mkdir( /* make directory */ if (p_mkdir(make_path.ptr, mode) < 0) { - int tmp_errno = errno; + int tmp_errno = giterr_system_last(); /* ignore error if directory already exists */ if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) { - errno = tmp_errno; + giterr_system_set(tmp_errno); giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path.ptr); goto done; }