msvc: opendir: fix malloc-failure
[git/dscho.git] / compat / msvc.c
blobd6096e4bd96ddb82da7eb653cbde0e73172e0391
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;
9 DIR *p;
10 p = malloc(sizeof(DIR));
11 if (!p)
12 return NULL;
14 memset(p, 0, sizeof(DIR));
15 strncpy(p->dd_name, name, PATH_MAX);
16 len = strlen(p->dd_name);
17 p->dd_name[len] = '/';
18 p->dd_name[len+1] = '*';
20 p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
22 if (p->dd_handle == -1) {
23 free(p);
24 return NULL;
26 return p;
28 int closedir(DIR *dir)
30 _findclose(dir->dd_handle);
31 free(dir);
32 return 0;
35 #include "mingw.c"