add file operation

This commit is contained in:
jonathan santis
2025-05-13 13:49:10 +02:00
parent 3afd472bbd
commit 631fc8322a
3 changed files with 84 additions and 0 deletions

23
test.c
View File

@@ -1,6 +1,7 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include "file.h"
int main(void)
{
@@ -24,6 +25,7 @@ int main(void)
char testpair[] = "asifdsfo=s1254124";
char *keyName=NULL;
char *keyValue=NULL;
char *content=NULL;
keyName = malloc(MAX_LEN_SECTIONNAME);
keyValue = malloc(MAX_LEN_SECTIONNAME);
@@ -37,6 +39,26 @@ int main(void)
}else{
printf("error getNameValuePair: %d\n",ret);
}
long neededSize=0;
if((ret=getFile("config.cfg",NULL,0,&neededSize))==NO_ERROR)
{
printf("sucessfull retrieved size:%ld\n",neededSize);
}
else {
printf("Error on getFile:%d\n",ret);
}
content = malloc(neededSize);
if((ret=getFile("config.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(keyValue);
free(keyName);
@@ -44,3 +66,4 @@ int main(void)
}