FileSystemIndexer v0.1.2-beta
File System Indexer - An API to index files from your system
Loading...
Searching...
No Matches
FSI_dirUtils_posix.c File Reference
Include dependency graph for FSI_dirUtils_posix.c:

Go to the source code of this file.

Functions

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.

Function Documentation

◆ fsi_closeDir()

void fsi_closeDir ( FSI_DirData * d)

Get the directory data to deallocate memory.

Parameters
dObject to deallocate

Definition at line 41 of file FSI_dirUtils_posix.c.

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}
#define FSI_FREE(x)

References FSI_DirData_POSIX::dir, FSI_FREE, FSI_DirData::impl, and FSI_DirData_POSIX::path.

◆ fsi_openDir()

int fsi_openDir ( FSI_DirData * d,
const char * path )

Open directory as read only.

Parameters
dDirectory data
pathPath to open dir
Returns
Status (1 if worked, 0 if failed)

Definition at line 9 of file FSI_dirUtils_posix.c.

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}

References FSI_DirData_POSIX::dir, FSI_DirData_POSIX::dirfd, and FSI_DirData::impl.