读取配置文件的方法getcfg()
来源:互联网 发布:python spark z 编辑:程序博客网 时间:2024/05/15 02:51
/*******************************************************
* getcfg()
Explain:
获取配置文件信息
Param:
serv_ip 保存读取出的IP
port 保存读取出的端口
filedir 保存读取文件的目录的路径
filename 保存读取文件的名字
Return:
1 open success
-1 open file error
**************************************************************************/
int getcfg(char *serv_ip,unsigned int *port,char *filedir,char *filename)
{
FILE *pfile;
char filepath[256],buf[256];
int i=0;
int len=0;
unsigned int tm_port=0;
memset(filepath,0,sizeof(filepath));
errno = 0;
sprintf(filepath,"%s/%s",filedir,filename);
pfile = fopen(filepath,"r");
if(pfile==NULL)
{
printf("getcfg no file/n");
printf("open error:%d,%s/n",errno,strerror(errno));
return -1;
}
for(i=0;i<=100;i++)
{
memset(buf,0,sizeof(buf));
fgets(buf,256,pfile);
if(feof(pfile) && strlen(buf)<=0)
{
break;
}
len=strlen(buf);
if(len>256)
break;
if(buf[len]==0x0d || buf[len]==0x0a) /*0x0d对应'/r',0x0a对应'/n'*/
buf[len]=0;
if(buf[len-1]==0x0d || buf[len-1]==0x0a)
buf[len-1]=0;
if(i==1)
strncpy(serv_ip,buf,strlen(buf));
if(i==3)
tm_port=(unsigned int )atoi(buf);
}
fclose(pfile);
*port=tm_port;
#ifdef DEBUG
printf( "getcfg():IP_%s,port_%u/n",serv_ip,*port);
#endif
return 1;
}
- 读取配置文件的方法getcfg()
- 读取配置文件的方法
- 读取配置文件的方法案例
- 读取xml配置文件的方法
- play读取配置文件的方法
- OSGI读取配置文件的方法
- spring 读取配置文件的方法
- spring 读取配置文件的方法
- 读取配置文件properties的方法
- play读取配置文件的方法
- Spring读取配置文件的方法
- java读取配置文件的方法
- 读取配置文件properties的方法
- 配置文件读取的n种方法
- java读取配置文件的几种方法
- java应用程序读取配置文件的方法
- java读取配置文件的几种方法
- java读取配置文件的几种方法
- eclipse 快捷键导入导出
- Java面向对象编程习题总结(三)
- vim编辑器提供的色彩配置方案(转)
- ASP.NET如何实现数据类型转换
- GTK +
- 读取配置文件的方法getcfg()
- #pragma once 与 #if !defined 分开了
- 【飞秋】使用C++语言创建Silverlight中的VisualState
- 各种咖啡的说明
- sql server 2000 torn_page_detection error (error 823)
- 一些有用的类库转载
- 【飞秋】位运算与组合搜索(二)
- pku3372(找规律,公式,推理)
- Gridview用法:根据某列的值改变gridview其他列的属性