How convert a char[] string to int in the Linux kernel?

前端 未结 6 1102
暖寄归人
暖寄归人 2020-12-09 04:07

How convert char[] to int in linux kernel

with validation that the text entered is actually an int?

int procfile_write(struct file *file, const char          


        
6条回答
  •  攒了一身酷
    2020-12-09 04:30

    I use sscanf() (the kernel version) to scan from a string stream, and it works on 2.6.39-gentoo-r3. Frankly, I could never get simple_strtol() to work in the kernel--I am currently figuring out why this doesn't work on my box.

      ...
      memcpy(bufActual, calc_buffer, calc_buffer_size);
      /* a = simple_strtol(bufActual, NULL, 10); */ // Could not get this to work
      sscanf(bufActual, "%c%ld", &opr, &a); // places '+' in opr and a=20 for bufActual = "20+\0"
      ...
    

提交回复
热议问题