-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ add_library(${NAME} STATIC | |
debug.c | ||
epoll.c | ||
fuse.c | ||
list.c | ||
map.c | ||
panic.c | ||
pool.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <string.h> | ||
#include <fuse/fuse.h> | ||
|
||
// Private includes | ||
#include "list.h" | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
fuse_list_t *fuse_list_new_ex(fuse_t *fuse, const char *file, int line) | ||
{ | ||
assert(fuse); | ||
|
||
// Create the list | ||
struct fuse_list_instance *self = fuse_alloc_ex(fuse, sizeof(struct fuse_list_instance), file, line); | ||
if (self == NULL) | ||
{ | ||
return NULL; | ||
} | ||
|
||
// Set the instance properties | ||
self->count = 0; | ||
self->first = NULL; | ||
self->last = NULL; | ||
|
||
// Return success | ||
return self; | ||
} | ||
|
||
void fuse_list_destroy(fuse_t *fuse, fuse_list_t *self) | ||
{ | ||
assert(fuse); | ||
assert(self); | ||
|
||
// Free the instance | ||
fuse_free(fuse, self); | ||
} | ||
|
||
inline size_t fuse_list_count(fuse_list_t *self) | ||
{ | ||
assert(self); | ||
return self->count; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(NAME "list") | ||
add_executable(${NAME} | ||
main.c | ||
) | ||
|
||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../../include | ||
) | ||
|
||
target_link_libraries(${NAME} | ||
fuse | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
#include <fuse/fuse.h> | ||
|
||
int TEST_001() | ||
{ | ||
fuse_debugf(NULL, "Creating a fuse application\n"); | ||
fuse_t *fuse = fuse_new(FUSE_FLAG_DEBUG); | ||
assert(fuse); | ||
|
||
// Create a list | ||
fuse_debugf(NULL, "Creating an empty list\n"); | ||
fuse_list_t *list = fuse_list_new(fuse); | ||
assert(list); | ||
assert(fuse_list_count(list) == 0); | ||
|
||
// Destroy the list | ||
fuse_list_destroy(fuse, list); | ||
|
||
// Return | ||
return fuse_destroy(fuse); | ||
} | ||
|
||
int TEST_002() | ||
{ | ||
fuse_debugf(NULL, "Creating a fuse application\n"); | ||
fuse_t *fuse = fuse_new(FUSE_FLAG_DEBUG); | ||
assert(fuse); | ||
|
||
// Create a list | ||
fuse_debugf(NULL, "Creating a list\n"); | ||
fuse_list_t *list = fuse_list_new(fuse); | ||
assert(list); | ||
assert(fuse_list_count(list) == 0); | ||
|
||
// Push 10 items into the list | ||
fuse_debugf(NULL, "Pushing 10 items into the list\n"); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
fuse_list_push(list, (void *)(i + 1)); | ||
assert(fuse_list_count(list) == i + 1); | ||
} | ||
|
||
// Destroy the list | ||
fuse_list_destroy(fuse, list); | ||
|
||
// Return | ||
return fuse_destroy(fuse); | ||
} | ||
|
||
int main() | ||
{ | ||
assert(TEST_001() == 0); | ||
assert(TEST_002() == 0); | ||
|
||
// Return success | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters