libmp/src/package/keep.c

69 lines
1.4 KiB
C

#include "../../include/package.h"
#include "../../include/error.h"
#include "../../include/util.h"
#include <stdlib.h>
#include <string.h>
size_t lm_package_data_keep_count(lm_pkg_data_t *data){
size_t index = 0;
if(NULL == data->keeps)
return index;
while(data->keeps[index] != NULL)
index++;
return index;
}
bool lm_package_data_keep_add(lm_pkg_data_t *data, char *path){
if(NULL == path){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
if(NULL == data->keeps){
data->keeps = malloc(sizeof(char*)*2);
data->keeps[0] = strdup(path);
data->keeps[1] = NULL;
return true;
}
size_t count = lm_package_data_depend_count(data);
data->keeps = realloc(data->depends, sizeof(char*)*(count+2));
data->keeps[count++] = strdup(path);
data->keeps[count] = NULL;
return true;
}
bool lm_package_data_keep_contains(lm_pkg_data_t *data, char *path){
if(NULL == data || NULL == path){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
if(NULL == data->keeps)
return false;
for(int i = 0; NULL != data->keeps[i]; i++)
if(eq(data->keeps[i], path))
return true;
return false;
}
void lm_package_data_keep_free(lm_pkg_data_t *data){
if(NULL == data)
return;
if(NULL == data->keeps)
return;
for(int i = 0; data->keeps[i] != NULL; i++)
free(data->keeps[i]);
free(data->keeps);
data->keeps = NULL;
}