- 论坛徽章:
- 0
|
#include"common.h"
int configuration(int *port ,char *path)
{
int i;
char *ch;
FILE *fp;
char *p;
char buf[1024]="0";
fp=open("./config.ini",O_RDONLY);
if(fp==NULL){
perror("fail to open config.ini");
return -1;
}
ch=fgets(buf,50,fp);//这里出现段错误??????/
while(ch!=NULL){
if(buf[strlen(buf)-1]!='\n'){
printf("error in config.ini\n");
return -1;
}else
buf[strlen(buf)-1]='\0';
if(strstr(buf,"port")==buf){
if((p=strchr(buf,':'))==NULL){
printf("config.ini except ':'\n");
}
*port=atoi(p+2);
if(*port<=0){
printf("error port\n");
return -1;
}
}
else if (strstr(buf,"root-path")==buf){
if((p=strchr(buf,':'))==NULL){
printf("config.ini except ':'\n");
return -1;
}
strcpy(path,p);
}
}
return 0;
} |
|