简体   繁体   English

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

[英]stdlib.h alternative in Linux kernel?

When developing a kernel module in Linux, using the C standard library isn't allowed. 在Linux中开发内核模块时,不允许使用C标准库。
However, in case I need to use some common functionality like strcat() , where do I need to go to? 但是,如果我需要使用一些常见的功能,例如strcat() ,我应该去哪里?

Whatever is not implemented in the Linux kernel, you have to implement yourself or borrow from another open source kernel module. 无论Linux内核中没有实现什么,您都必须实现自己或从另一个开源内核模块中借鉴。 However, you'll find that strcat is implemented in the kernel. 但是,您会发现strcat是在内核中实现的。

See the kernel API documentation. 请参阅内核API文档。 Specifically the Basic C Library Functions section for your general question, and the String Manipulation section for your specific question about strcat . 特别是关于您的一般问题的“ 基本C库函数”部分,以及有关strcat的特定问题的“ 字符串处理”部分。

You'll want to include linux/string.h . 您将要包含linux/string.h

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. 我不知道为什么内核API文档实际上没有显示要获得该功能必须包含的头文件。 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因为如果头文件具有在内核的不同部分之间共享的功能,那么这就是头文件所在的位置。

Header files outside /include/linux contain definitions only for source files residing in the same directory as the header. /include/linux之外的头文件仅包含与头文件位于同一目录中的源文件的定义。 The exception is /arch/.../include , which will contain architecture-specific headers instead of platform independent ones. /arch/.../include/arch/.../include例外,它将包含特定于体系结构的头文件,而不是平台无关的头文件。

Sorry @eq - thinking of another function. 抱歉@eq-考虑另一个功能。

Why not 为什么不

void (char *d, const char *s);
{
   if (*d)
   { 
       for (; *d; ++d) {} ;
      --d;
   }
   strcpy(d, s);
}

I could do strcpy if you wish 我能做strcpy ,如果你想

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM