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.
1
#include "
../../../inc/fsi/FSIpredefines.h
"
2
3
#ifndef FSI_OS_WIN32
4
5
#include "
../../../inc/fsi/core/interfaces/FSI_dirUtils_posix.h
"
6
7
#include <stdlib.h>
8
9
int
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
41
void
fsi_closeDir
(
FSI_DirData
*d)
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
fsi_closeDir
void fsi_closeDir(FSI_DirData *d)
Get the directory data to deallocate memory.
Definition
FSI_dirUtils_posix.c:41
fsi_openDir
int fsi_openDir(FSI_DirData *d, const char *path)
Open directory as read only.
Definition
FSI_dirUtils_posix.c:9
FSI_dirUtils_posix.h
FSIpredefines.h
FSI_FREE
#define FSI_FREE(x)
Definition
FSIpredefines.h:45
FSI_DirData_POSIX
Definition
FSI_dirUtils_posix.h:28
FSI_DirData_POSIX::dirfd
int dirfd
Definition
FSI_dirUtils_posix.h:32
FSI_DirData_POSIX::dir
DIR * dir
Definition
FSI_dirUtils_posix.h:29
FSI_DirData_POSIX::path
CSTR path
Definition
FSI_dirUtils_posix.h:30
FSI_DirData
Definition
FSI_dirUtils.h:27
FSI_DirData::impl
void * impl
Definition
FSI_dirUtils.h:28
src
core
interfaces
FSI_dirUtils_posix.c
Generated by
1.16.1