
int get_prefixname_from_filename(char *fileName, char *prefixName)
{
char *tmpIn = NULL;
char *tmpOut = NULL;
char *tmpPointer = NULL;
if ((NULL == fileName) || (NULL == prefixName))
{
printf("[%s +%d %s] (NULL == fileName) || (NULL == prefixName) failed\n", __FILE__, __LINE__, __func__);
return -1;
}
//printf("[%s +%d %s] fileName=%s prefixName=%s\n", __FILE__, __LINE__, __func__, fileName, prefixName);
tmpIn = fileName;
if(('.' == *tmpIn) && ('/' == *(tmpIn+1)))
{
tmpIn = fileName + 2;
}
else if(('.' == *tmpIn) && ('.' == *(tmpIn+1)) && ('/' == *(tmpIn+2)))
{
tmpIn = fileName + 3;
}
else
{
//if(('.' == *tmpIn) && (('.' != *(tmpIn+1)) || ('/' != *(tmpIn+1))))
if(('.' == *tmpIn) && ('.' == *(tmpIn+1)))
{
printf("[%s +%d %s] fileName=%s tmpIn=%s\n", __FILE__, __LINE__, __func__, fileName, tmpIn);
printf("[%s +%d %s] ('.' == *tmpIn) && ('.' == *(tmpIn+1)) failed\n", __FILE__, __LINE__, __func__);
return -1;
}
tmpIn = fileName;
}
tmpOut = strchr(tmpIn, '/');
while(1)
{
if(NULL == tmpOut)
{
break;
}
else
{
tmpIn = tmpOut + 1;
//printf("[%s +%d %s] fileName=%s tmpIn=%s\n", __FILE__, __LINE__, __func__, fileName, tmpIn);
}
tmpOut = strchr(tmpIn, '/');
}
fileName = tmpIn;
tmpPointer = tmpIn;
while(NULL != tmpIn)
{
tmpOut = strchr(tmpIn, '.');
if(NULL == tmpOut)
{
break;
}
tmpIn = tmpOut + 1;
tmpPointer = tmpIn;
}
//printf("[%s +%d %s] fileName=%s tmpPointer=%s\n", __FILE__, __LINE__, __func__, fileName, tmpPointer);
memcpy(prefixName, fileName, tmpPointer - fileName - 1);
return 0;
}原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。