msvc: opendir: allocate enough memory
[git/jrn.git] / compat / msvc.c
blobc195365d2cf77348b0646f210adb984ae75d07bc
1 #include "../git-compat-util.h"
2 #include "win32.h"
3 #include <conio.h>
4 #include "../strbuf.h"
6 DIR *opendir(const char *name)
8 int len = strlen(name);
9 DIR *p;
10 p = malloc(sizeof(DIR) + len + 2);
11 if (!p)
12 return NULL;
14 memset(p, 0, sizeof(DIR) + len + 2);
15 strcpy(p->dd_name, name);
16 p->dd_name[len] = '/';
17 p->dd_name[len+1] = '*';
19 p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
21 if (p->dd_handle == -1) {
22 free(p);
23 return NULL;
25 return p;
27 int closedir(DIR *dir)
29 _findclose(dir->dd_handle);
30 free(dir);
31 return 0;
34 #include "mingw.c"