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 *buffer, unsigned long count,
void *data)
{
char procfs_buffer[PROCFS_MAX_SIZE];
/* get buffer size */
unsigned long procfs_buffer_size = count;
if (procfs_buffer_size > PROCFS_MAX_SIZE ) {
procfs_buffer_size = PROCFS_MAX_SIZE;
}
/* write data to the buffer */
if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) {
return -EFAULT;
}
int = buffer2int(procfs_buffer, procfs_buffer_size);
return procfs_buffer_size;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…