技术的乐趣在于分享,欢迎多多交流,多多沟通。
全部博文(877)
分类: LINUX
2014-03-27 21:04:21
原文地址:strict_strtoul 作者:chumojing
strict_strtoul — convert a string to an unsigned long strictly
int strict_strtoul ( | const char * | cp, |
unsigned int | base, | |
unsigned long * | res); |
The string to be converted
baseThe number base to use
resThe converted result value
strict_strtoul converts a string to an unsigned long only if the string is really an unsigned long string, any string containing any invalid char at the tail will be rejected and -EINVAL is returned, only a newline char at the tail is acceptible because people generally
echo 1024 > /sys/module/e1000/parameters/copybreak
echo will append a newline to the tail.
It returns 0 if conversion is successful and *res is set to the converted value, otherwise it returns -EINVAL and *res is set to 0.
simple_strtoul just ignores the successive invalid characters and return the converted value of prefix part of the string.