Yes, you can use #if
to produce different code where necessary. You will probably have to define your own -D
or #define
to control whether the library is "kernel" or "user mode".
It is often best to separate out the "functions that aren't generic" into one or a few modules (and including the files, say "usermode-stuff.c" and "kernel-stuff.c", respectively as part of the project source files), where the same type of function is declared for generic use. This avoids having a huge number of #if KERNEL_MODE
all over the code, which can get quite messy after a while.
Obviously, that in itself doesn't necessarily mean that you can do all the things you need, or that your project can be achieved - there isn't enough details in your question to answer that.