56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
|
#include "../../include/package.h"
|
||
|
#include "../../include/types.h"
|
||
|
#include "../../include/error.h"
|
||
|
#include "../../include/util.h"
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
size_t lm_package_keep_count(lm_pkg_t *pkg){
|
||
|
size_t index = 0;
|
||
|
|
||
|
if(NULL == pkg->keeps)
|
||
|
return index;
|
||
|
|
||
|
while(pkg->keeps[index] != NULL)
|
||
|
index++;
|
||
|
|
||
|
return index;
|
||
|
}
|
||
|
|
||
|
bool lm_package_keep_add(lm_pkg_t *pkg, char *path){
|
||
|
if(NULL == path){
|
||
|
lm_error_set(LM_ERR_ArgNULL);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if(NULL == pkg->keeps){
|
||
|
pkg->keeps = malloc(sizeof(char*)*2);
|
||
|
pkg->keeps[0] = strdup(path);
|
||
|
pkg->keeps[1] = NULL;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
size_t count = lm_package_depend_count(pkg);
|
||
|
pkg->keeps = realloc(pkg->depends, sizeof(char*)*(count+2));
|
||
|
pkg->keeps[count++] = strdup(path);
|
||
|
pkg->keeps[count] = NULL;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool lm_package_keep_contains(lm_pkg_t *pkg, char *path){
|
||
|
if(NULL == pkg || NULL == path){
|
||
|
lm_error_set(LM_ERR_ArgNULL);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if(NULL == pkg->keeps)
|
||
|
return false;
|
||
|
|
||
|
for(int i = 0; NULL != pkg->keeps[i]; i++)
|
||
|
if(eq(pkg->keeps[i], path))
|
||
|
return true;
|
||
|
|
||
|
return false;
|
||
|
}
|