php5.4.25的c核心用vs2008sp1编译无法通过。。
自己写了个c扩展,把zend改了改,vs和dev c++都能通过,但一nmake snap就无法通过,报错如下图:
但是注释了对rightJudge的调用就没问题了,说明是这个函数的问题,但搞了很多天了,实在发现不了问题,求大侠帮帮忙!
int rightJudge(char *propertiesBridgePath, char *functionName , int ringNum){
char *functionSplit=NULL,*isFunctionInRing=NULL,*ringFunction=NULL;
char ring[20],ringSuffix[20];
do{
strcpy(ring,"ring_");
//itoa(ringNum,ringSuffix,10);
//strcat(ring,ringSuffix);
sprintf(ring, "%s%d", "ring_", ringNum);
ringFunction =getKeyValueInIni(propertiesBridgePath,"function-ring",ring);
isFunctionInRing=strstr(ringFunction,functionName);
//free(ringFunction);
if(isFunctionInRing!=NULL){
return 0;
}else{
return -1;
}
}while(ringNum++);
return -1;
}
char* getKeyValueInIni(char *filename, char *section, char *key){
char line[255];
char sectname[255];
char *skey=NULL;
char *s=NULL;
char *seps = "=";
int flag = 0,length=0;
FILE *fp = fopen(filename,"r");
assert(fp != NULL);
//process the section and line
memset(line,0,255);
memset(sectname,'\0',sizeof(sectname));
memset(res,'\0',sizeof(res));
if (!strchr(section, '['))
{
strcpy(sectname,"[");
strcat(sectname,section);
strcat(sectname,"]");
}
else
{
strcpy(sectname,section);
}
if(!strchr(sectname, '\n')){
strcat(sectname,"\n");
}
while (fgets(line, 255, fp) != NULL)
{
if (flag)
{
skey = strtok(line, seps);
if (strcmp(skey , key) == 0)
{
s = strtok(NULL,seps);
if(s!=NULL){
// res = (char*)malloc(strlen(s)*sizeof(char));
strcpy(res,s);
fclose(fp);
return res;
}else{
fclose(fp);
return NULL;
}
}
}
else
{
if (strcmp(sectname,line) == 0)
{
flag = 1;
}
}
}
fclose(fp);
return NULL;
}
还有个问题就是不知道为啥在getKeyValueInIni函数中的res变量只能使用数组形式,指针形式在dev c++下会直接停止,vs下没问题。。。
谢谢啦!!
------解决方案--------------------
楼主说的用指针会直接停止具体是什么情况,内存申请成功了吗?
------解决方案--------------------
rightJudge被你注释的那些行,不会影响其他功能么?