免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 16274 | 回复: 1

请问这个函数是怎么用的?unsigned long simple_strtoul() [复制链接]

论坛徽章:
0
发表于 2007-10-19 11:36 |显示全部楼层
unsigned long simple_stroul(const char *cp,char **endp,unsigned int base);

函数原形如上,请问这个函数的具体功能是什么呢,谢谢

论坛徽章:
0
发表于 2007-10-21 19:35 |显示全部楼层
就是解析字符串cp 中 8,10,16 进制数字  ,返回值是解析的数字,endp 指向字符串起始处,base :进制
看看 内核中的函数:proc_scsi_write 就知道了。
unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
{
        unsigned long result = 0,value;

        if (!base) {
                base = 10;
                if (*cp == '0') {
                        base = 8;
                        cp++;
                        if ((*cp == 'x') && isxdigit(cp[1])) {
                                cp++;
                                base = 16;
                        }
                }
        }
        while (isxdigit(*cp) &&
               (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
                result = result*base + value;
                cp++;
        }
        if (endp)
                *endp = (char *)cp;
        return result;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP