stdlib.h alternative in Linux kernel?

放肆的年华 提交于 2020-06-21 11:44:05

问题


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?


回答1:


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.

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.

You'll want to include 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. 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.

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.




回答2:


Sorry @eq - thinking of another function.

Why not

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

I could do strcpy if you wish



来源:https://stackoverflow.com/questions/12011075/stdlib-h-alternative-in-linux-kernel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!