Linux内核中的stdlib.h替代方案?

问题描述:

在Linux中开发内核模块时,不允许使用C标准库.
但是,如果需要使用strcat()之类的常用功能,该去哪里?

When developing a kernel module in Linux, using the C standard library isn't allowed.
However, in case I need to use some common functionality like strcat(), where do I need to go to?

无论Linux内核中没有实现什么,您都必须实现自己或从另一个开源内核模块中借鉴.但是,您会发现strcat是在内核中实现的.

Whatever is not implemented in the Linux kernel, you have to implement yourself or borrow from another open source kernel module. However, you'll find that strcat is implemented in the kernel.

请参见内核API 文档.具体来说,通常是基本C库函数部分,以及字符串处理部分,以解决关于strcat的特定问题.

See the kernel API documentation. Specifically the Basic C Library Functions section for your general question, and the String Manipulation section for your specific question about strcat.

您将要包含linux/string.h.

我不知道为什么内核API文档实际上并未显示要获得该功能所必须包含的头文件.但是,如果您要查找某些内容,则可以将搜索范围限制为/include/linux,因为如果头文件具有在内核的不同部分之间共享的功能,那么这就是头文件所在的地方.

I don't know why the kernel API documentation doesn't actually show the header file that you have to include to get the function. But if you're looking for something, you can restrict your search to /include/linux because that is where header files go if they have functions that are shared amongst different parts of the kernel.

/include/linux之外的头文件仅包含与头文件位于同一目录中的源文件的定义. /arch/.../include是例外,它将包含特定于体系结构的标头,而不是与平台无关的标头.

Header files outside /include/linux contain definitions only for source files residing in the same directory as the header. The exception is /arch/.../include, which will contain architecture-specific headers instead of platform independent ones.