What is the Linux kernel equivalent to the memset function?

Dr.Knowitall picture Dr.Knowitall · Mar 27, 2012 · Viewed 15.4k times · Source

I'm writing a driver that requires me to clear all the memory allocated to zero. memset is a userspace function, but I would like to know if the kernel provides a macro that helps me do this.

Answer

Chrysanthemumer picture Chrysanthemumer · Mar 29, 2013

It's true memset() in

include <string.h >

not supposed to appear in kernel code.And the fact is it may cost you a lot to trace down where memset() is included during driver development. Actually memset() is defined in

#include<linux/string.h>

it says:

#ifndef __KERNEL__
#include <string.h>
#else
/* We don't want strings.h stuff being used by user stuff by accident */

Hope this help you type down 'memset()' with 100% sure :)