feat(utilities,basefiles): added remove function to List and BaseFileBuffer
This commit is contained in:
parent
967b79d9ba
commit
e3a2f43871
4 changed files with 38 additions and 0 deletions
|
|
@ -32,6 +32,29 @@ int list_push(List* list, void* item) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int list_remove(List* list, const void* key, int (*compare)(const void*, const void*)) {
|
||||
if (!list || !key || !compare || list->len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < list->len; i++) {
|
||||
char* current_item = (char*)list->items + (i * list->item_size);
|
||||
|
||||
if (compare(key, current_item) == 0) {
|
||||
for (size_t j = i; j < list->len - 1; j++) {
|
||||
char* dest = (char*)list->items + (j * list->item_size);
|
||||
char* src = (char*)list->items + ((j + 1) * list->item_size);
|
||||
memcpy(dest, src, list->item_size);
|
||||
}
|
||||
|
||||
list->len--;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void list_free(List* buffer) {
|
||||
if (buffer) {
|
||||
for (size_t i = 0; i < buffer->len; i++) {
|
||||
|
|
@ -347,6 +370,12 @@ void walk(char* base, char* base_rel, char* rel, FileInfoBuffer* file_infos, int
|
|||
char* get_repo_path(char* repo_root_path, char* path) {
|
||||
char* real_path = realpath(path, NULL);
|
||||
cut_path(repo_root_path, real_path);
|
||||
|
||||
size_t len = strlen(real_path);
|
||||
if (len > 1 && real_path[len - 1] == '/') {
|
||||
real_path[len - 1] = '\0';
|
||||
}
|
||||
|
||||
return real_path;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue