首页 > 编程语言 > 详细

C语言判断文件夹名是否合法

时间:2015-02-28 20:21:37      阅读:271      评论:0      收藏:0      [点我收藏+]


/***************************************************************************
 * Function Name: validateFoldername
 * Description:  The ength of folder name should be less than 255.
 *                      Illegal characters are \<>()[]&:,/|?* \0 ~ \31
 * Return: 0 for success, otherwise 1.
 ****************************************************************************/

#define MAX_FOLDER_NAME_LEN 255

int validateFoldername(char *pName)
{
    int ret = 0;
    unsigned int u32Length = 0, u32Index = 0;
    unsigned char u8SpecialChar[] = {‘\\‘,‘<‘,‘>‘,‘(‘,‘)‘,‘[‘,‘]‘,‘&‘,‘:‘,‘,‘,‘/‘,‘|‘,‘?‘,‘*‘};
    unsigned char u8CtrlCharBegin = 0x0, u8CtrlCharEnd = 0x31;
   
    if (pName == NULL)
    {
        ret = 1;
    }
    else
    {
        u32Length = strlen(pName);
        if ( u32Length >= MAX_FOLDER_NAME_LEN)
            ret= 1;
    }

    for (u32Index = 0; (u32Index < u32Length) && (ret== 0);
        u32Index ++)
    {
        if (u8CtrlCharBegin <= pName[u32Index] <= u8CtrlCharEnd)
        {
            ret= 1;
        }
        else if (strchr(u8SpecialChar,pName[u32Index]) != NULL)
        {
            ret= 1;
        }
    }

    return ret;

}

C语言判断文件夹名是否合法

原文:http://blog.csdn.net/wei_gw2012/article/details/43988529

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!