资源描述:
《文件传输测试源码c.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include"file_transfer.h"/***********************************//******客户端,向中石化发送文件****//**********************************//**********取时间函数***********/voidvGetHostTime(char*pszTime>{time_tt。structtmtm。t=time(NULL>。memcpy(&tm,localtime(&t>,sizeof(structtm>>。s
2、printf(pszTime,"%04d%02d%02d%02d%02d%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec>。}/************输出日志信息****************/voidmylog(char*buf>{charszTime[15]。charlogpath[256]。charlogname[256]。FILE*logfp。charlogdir[256]。memset(logp
3、ath,0,sizeof(logpath>>。memset(logname,0,sizeof(logname>>。memset(szTime,0,sizeof(szTime>>。memset(logdir,0,sizeof(logdir>>。vGetHostTime(szTime>。ReadString("file_transfer.cfg","ZSHFILEDIR","WKLOG",logdir>。b5E2RGbCAPmemcpy(logname,szTime,8>。sprintf(logpath,"%s/
4、wk2zhs%s.log",logdir,logname>。logfp=fopen(logpath,"a+">。memset(szTime,0,sizeof(szTime>>。vGetHostTime(szTime>。fprintf(logfp,"[%s]:%s",szTime,buf>。fflush(logfp>。fclose(logfp>。}/*转换正则表达式*/voidStr2Regular(char*s>{char*ptr。inti,iLen。charsbuf[255],*p。9/9memset(sb
5、uf,0,sizeof(sbuf>>。ptr=sbuf。iLen=strlen(s>。p=s。for(i=0。i{if(*p=='*'>{//if(i=0>*ptr++='.'。}elseif(*p=='.'>{*ptr++='\'。}*ptr++=*p。}sprintf(s,"%s",sbuf>。return。}/********文件名匹配<正则表达式)*************/intRegComp(char*string,char*sCurParam>{FILE*fp。si
6、ze_tlen。/*storeerrormessagelength*/regex_tre。/*storecompilnedregularexpression*/p1EanqFDPwregmatch_tsubs[10]。/*storematchedstringposition*/DXDiTa9E3dcharmatched[1024]。/*storematchedstrings*/charerrbuf[255]。/*storeerrormessage*/interr,i。charpattern[255]。mems
7、et(pattern,0,sizeof(pattern>>。sprintf(pattern,"%s",sCurParam>。/*转换为正则表达式*/Str2Regular(pattern>。/*compileregularexpression*/err=regcomp(&re,pattern,REG_EXTENDED
8、REG_ICASE>。RTCrpUDGiTif(err>{len=regerror(err,&re,errbuf,sizeof(errbuf>>。5PCzVD7HxAfprintf(stderr
9、,"error:regcomp:[%s]",errbuf>。return-1。}/*executepatternmatch*/9/9memset(&subs,0,sizeof(subs>>。err=regexec(&re,string,(size_t>10,subs,0>。if(err==REG_NOMATCH>{//showmsg(ERROR,"nomatch...">。regfree(&re