Linux内核函数转换
程序员文章站
2022-07-13 22:08:30
...
要求输入字符串 int str = "75,89,788,75514"
输出数组{75, 89, 788, 75514}
函数实现:
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/string.h>
char * atoi(char *str,int * val)
{
int value = 0;
if (NULL != str)
{
while (*str>='0' && *str<='9')
{
value *= 10;
value += *str - '0';
str++;
}
}
*val = value;
return str;
}
int alsps_table_reconfig(char *str, unsigned int *val)
{
int i = 0;
char *result = str;
printk("Jason str:%s\n", str);
if ( result != NULL)
{
while(*result != '\0')
{
result = atoi(result,val+i);
printk("Jason result:%s,val[%d]:%d\n", result, i, *(val+i));
if(*result != '\0')
result++;
i++;
}
}
return 0;
}
EXPORT_SYMBOL(alsps_table_reconfig);
函数调用
#define AGOLD_ALS_LEVEL 0,1300,2700,4800,8700,10500,12100,22000,64000,65535,65535,65535,65535,65535,65535
#ifdef AGOLD_ALS_LEVEL
alsps_table_reconfig((char *)AGOLD_ALS_LEVEL, hw->als_level);
#endif
下一篇: 使用systemtap调试Linux内核
推荐阅读