If that port is only for your kernel, then you can very well do whatever you want. If you plan on offering access to that library to your kernel users, then the interface has to be C. The implementation, however, can be any language you want.
Now for most functions, it doesn't make much sense to use a C++ function and then create a C function to access the C++ function since the function itself is not going to use C++ (at least for functions such as strlen()
, you wouldn't really need to use the std::find()
, you can rewrite that in C with a simple loop).
You could also reuse the functions you need from the GNU C library. i.e. just copy those functions to your implementation. Just make sure to keep the same license. That library has many implementations of such low level functions in various assembly languages for speed. The strlen()
function, for example, loads 64 bits and determines whether there is a 0x00 byte using logic (NOT
, AND
, XOR
...) which makes the function extremely efficient.
The GNU C library also includes special functions that call kernel functions. Those, obviously, you wouldn't want directly in your kernel (well, probably not, it will depend on your kernel).
Finally, the C library is much more complex than just a few functions like strlen()
. It has to work with thousands of software, all of which may be linked against slightly different versions. So the strlen()
may actually have 20 versions within the same C library. Probably not something you'd want to worry about for a while (until your kernel gets used by many), but it can be important for long term stability of the software running on your computer. This is particularly important if one software expects a certain function to return EINVAL
(older version) and another that returns EIO
(newer version). Such tiny difference are really important when dealing with thousands of software.
Yet again, it sounds like what you means is having helper functions in your kernel. Helper functions which are available in the C library but are not an actual C library (I don't think it's a good idea for the kernel to be linked in this way). It should be your helper function library specific to your kernel, which you link statically. Actually, you should only add functions that are used by your kernel, no more than that.
Finally, if your kernel is written in C++, then your helper functions can as well be written in C++. However, if you plan to have some small parts that use just C and some of these helper functions would be used in those small parts, then having those helper functions written in C is going to be easier. strlen()
is obviously only necessary in C since in C++ you'd like to use the std::string::length()
member of function instead.