C language to determine whether the folder name is legitimate

Source: Internet
Author: User



/***************************************************************************
* Function Name:validatefoldername
* Description:the Ength of folder name should is less than 255.
* Illegal characters is \<> () []&:,/|? * ~ \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 language to determine whether the folder name is legitimate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.