summaryrefslogtreecommitdiff
path: root/src/win32/dir.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-13 09:53:56 -0700
committerRussell Belfer <rb@github.com>2013-08-13 09:53:56 -0700
commitee0656012c213a9589c7a0892f3e4a11caebc664 (patch)
tree1789c273dfb4a4cb06fd1a714b2a66c15b466f18 /src/win32/dir.c
parent841034a35ee34190fa1cc136acccfa1a4abaed39 (diff)
downloadlibgit2-ee0656012c213a9589c7a0892f3e4a11caebc664.tar.gz
Minor win32 fixes and improvements
This is just a bunch of small fixes that I noticed while looking at the UTF8 and UTF16 path stuff. It fixes a slowdown in looking for an empty directory (not exiting loop asap), makes the dir name in the git__DIR structure be a GIT_FLEX_ARRAY to save an allocation, and fixes some slightly odd assumptions in the cl_getenv helper.
Diffstat (limited to 'src/win32/dir.c')
-rw-r--r--src/win32/dir.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/win32/dir.c b/src/win32/dir.c
index 22050e875..b03c1d556 100644
--- a/src/win32/dir.c
+++ b/src/win32/dir.c
@@ -27,33 +27,29 @@ git__DIR *git__opendir(const char *dir)
git_win32_path_as_utf8 filter;
git_win32_path filter_w;
git__DIR *new = NULL;
+ size_t dirlen;
if (!dir || !init_filter(filter, sizeof(filter), dir))
return NULL;
- new = git__calloc(1, sizeof(*new));
+ dirlen = strlen(dir);
+
+ new = git__calloc(sizeof(*new) + dirlen + 1, 1);
if (!new)
return NULL;
-
- new->dir = git__strdup(dir);
- if (!new->dir)
- goto fail;
+ memcpy(new->dir, dir, dirlen);
git_win32_path_from_c(filter_w, filter);
new->h = FindFirstFileW(filter_w, &new->f);
if (new->h == INVALID_HANDLE_VALUE) {
giterr_set(GITERR_OS, "Could not open directory '%s'", dir);
- goto fail;
+ git__free(new);
+ return NULL;
}
new->first = 1;
return new;
-
-fail:
- git__free(new->dir);
- git__free(new);
- return NULL;
}
int git__readdir_ext(
@@ -133,8 +129,7 @@ int git__closedir(git__DIR *d)
FindClose(d->h);
d->h = INVALID_HANDLE_VALUE;
}
- git__free(d->dir);
- d->dir = NULL;
+
git__free(d);
return 0;
}