systemd-gotify/config.c

42 lines
776 B
C
Raw Normal View History

2024-09-11 08:14:55 +00:00
#include"config.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
int loadConfig(char *file, char **str_entry,int size)
{
int i=0;
bool terminate=false;
FILE *f_config;
2024-09-11 09:31:04 +00:00
char temp_str[256];
2024-09-11 08:14:55 +00:00
2024-09-11 08:54:21 +00:00
printf("\nopening config file\n");
2024-09-11 08:14:55 +00:00
f_config = fopen("config","r");
if(f_config != NULL)
{
2024-09-11 08:54:21 +00:00
for(i=0;i<size;i++)
2024-09-11 08:14:55 +00:00
{
2024-09-11 08:54:21 +00:00
printf("for loop:%d\n",i);
printf("str:%s\n",str_entry[i]);
2024-09-11 09:31:04 +00:00
if(fgets(temp_str,256,f_config)!=NULL)
2024-09-11 08:14:55 +00:00
{
2024-09-11 09:31:04 +00:00
temp_str[strcspn(temp_str,"\n")]=0;
2024-09-11 08:54:21 +00:00
str_entry[i]=strdup(temp_str);
2024-09-11 09:14:30 +00:00
printf("module path:%s",str_entry[i]);
2024-09-11 08:14:55 +00:00
}
else
{
2024-09-11 08:54:21 +00:00
break;
2024-09-11 08:14:55 +00:00
fclose(f_config);
}
}
}
else
{
fprintf(stderr,"error opening file");
}
return 0;
}