]>
git.proxmox.com Git - libgit2.git/blob - src/win32/dir.c
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #define GIT__WIN32_NO_WRAP_DIR
10 static int init_filter(char *filter
, size_t n
, const char *dir
)
12 size_t len
= strlen(dir
);
18 if (len
&& dir
[len
-1] != '/')
25 git__DIR
*git__opendir(const char *dir
)
30 if (!dir
|| !init_filter(filter
, sizeof(filter
), dir
))
33 new = git__malloc(sizeof(*new));
37 new->dir
= git__malloc(strlen(dir
)+1);
42 strcpy(new->dir
, dir
);
44 new->h
= FindFirstFile(filter
, &new->f
);
45 if (new->h
== INVALID_HANDLE_VALUE
) {
55 struct git__dirent
*git__readdir(git__DIR
*d
)
57 if (!d
|| d
->h
== INVALID_HANDLE_VALUE
)
63 if (!FindNextFile(d
->h
, &d
->f
))
67 if (strlen(d
->f
.cFileName
) >= sizeof(d
->entry
.d_name
))
71 strcpy(d
->entry
.d_name
, d
->f
.cFileName
);
76 void git__rewinddir(git__DIR
*d
)
81 if (d
->h
!= INVALID_HANDLE_VALUE
)
83 d
->h
= INVALID_HANDLE_VALUE
;
85 if (init_filter(filter
, sizeof(filter
), d
->dir
)) {
86 d
->h
= FindFirstFile(filter
, &d
->f
);
87 if (d
->h
!= INVALID_HANDLE_VALUE
)
93 int git__closedir(git__DIR
*d
)
96 if (d
->h
!= INVALID_HANDLE_VALUE
)