FileSystemIndexer v0.1.2-beta
File System Indexer - An API to index files from your system
Loading...
Searching...
No Matches
FSI_dirUtils_posix.c
Go to the documentation of this file.
2
3#ifndef FSI_OS_WIN32
4
6
7#include <stdlib.h>
8
9int fsi_openDir(FSI_DirData *d, const char *path)
10{
11 const int dirFD = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
12
13 if (dirFD < 0) return 0;
14
15 DIR *dir = fdopendir(dirFD);
16
17 if (!dir)
18 {
19 close(dirFD);
20
21 return 0;
22 }
23
24 FSI_DirData_POSIX *p = malloc(sizeof(*p));
25
26 if (!p)
27 {
28 closedir(dir);
29
30 return 0;
31 }
32
33 p->dir = dir;
34 p->dirfd = dirFD;
35
36 d->impl = p;
37
38 return 1;
39}
40
42{
43 FSI_DirData_POSIX *p = d->impl;
44
45 cstr_destroy(&p->path);
46
47 // Closes FD variable too
48 closedir(p->dir);
49
50 FSI_FREE(p);
51}
52
53#endif // FSI_OS_WIN32
54
void fsi_closeDir(FSI_DirData *d)
Get the directory data to deallocate memory.
int fsi_openDir(FSI_DirData *d, const char *path)
Open directory as read only.
#define FSI_FREE(x)