#include "config.h" #include #include #include #include #include "file.h" int main(void) { char teststr[] = "sdafsdfsdf[12345asdfddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd]"; char *name = NULL; char *sectionName=NULL; int ret=0; name = malloc(MAX_LEN_SECTIONNAME*sizeof(char)); getStrAtPos(teststr, 11, 15, &name, MAX_LEN_SECTIONNAME); sectionName = malloc(MAX_LEN_SECTIONNAME); memset(sectionName,0,MAX_LEN_SECTIONNAME); ret=checkSection(teststr,'[',']', §ionName); if(ret == FOUND_SECTION) { printf("checkSection sucessfull\nsectionName=%s\n",sectionName); } else { free(sectionName); printf("an error occured:%d\n",ret); return 1; } char testpair[] = "asifdsfo=s1254124"; char *keyName=NULL; char *keyValue=NULL; char *content=NULL; keyName = malloc(MAX_LEN_SECTIONNAME); keyValue = malloc(MAX_LEN_SECTIONNAME); memset(keyName,0,MAX_LEN_SECTIONNAME); memset(keyValue,0,MAX_LEN_SECTIONNAME); if((ret=getNameValuePair(testpair, '=',0, &keyName,&keyValue, MAX_LEN_SECTIONNAME,MAX_LEN_SECTIONNAME))==NO_ERROR) { printf("keyname:%s Value: %s\n",keyName,keyValue); }else{ printf("error getNameValuePair: %d\n",ret); } long neededSize=0; if((ret=getFile("config-segfault.cfg",NULL,0,&neededSize))==NO_ERROR) { printf("sucessfull retrieved size:%ld\n",neededSize); } else { printf("Error on getFile:%d\n",ret); return 1; } content = malloc(neededSize); printf("allocate buffer for filecontent size:%ld\n",neededSize); if(content == NULL) { int error = errno; printf("MALLOC: %d\n",error); return error; } memset(content,0,neededSize); if((ret=getFile("config-segfault.cfg",&content,neededSize,&neededSize))==NO_ERROR) { //printf("Sucessfull read file into buffer:%s|\n---\n",content); } else { printf("Error on getFile:%d\n",ret); free(content); return 1; } struct configEntry *entry=NULL; int returnedCount=0; int i=0; int count=10; entry = malloc(count*sizeof(struct configEntry)); if(entry == NULL) { int error = errno; printf("MALLOC: %d\n",error); return 0; } ret = parseConfig(content,&entry,count,&returnedCount); if(ret!=NO_ERROR) { printf("Error on parseConfig:%d\nReallocate from size %d, to %d\n",ret,count,returnedCount); } if(returnedCount > count) { for(i=0;i