It sounds like what you want to do is produce a single library binary that can be used in both freestanding (embedded) and hosted (non-embedded) environments. This is tricky but possible.
If you are building a static library (which it probably needs to be anyways -- generally shared libraries will not be useful in an embedded environment), you can just use malloc in part of your library and, as long as that part is not used by the application, it will not be included and all will be fine. If an embedded application uses the thing that requires malloc, they'll then get a link-time error if the embedded environment does not provide it.
So what you end up needing to do is offer two entry points for your library -- one that requires malloc and one that does not -- and the user (application writer) needs to call the one that is appropriate for their environment. You need to make sure that these two entry points are included in the library such that only one needs to be linked (generally, just make sure they are in different compilation units).
But I do not want the library itself to load 'stdlib.h'
This statement indicates a fundamental misunderstanding about what is going on. stdlib.h is a header file, not a library, so you do not (and cannot) "load" it. You can include it in your source code, but that just gives you the declarations for what is in the library; it does not include any of the library in your library. If you don't use anything from the header, it will have no effect. If you do use things from the header, that will create dependencies in your library on the standard library that will need to be resolved at (application) link time.
malloc()functionality "for free" (may not be available in freestanding implementations).malloc, but only if the user has implicitly provided access to its prototype prior to including your header? Forgive me, but that is (a) incredibly brittle, and (b) trivially circumventable. Perhaps I misunderstood the question.mallocit might not have other functions. (e.g.) Most but not all impl havestrdup. Look at whatautoconfdoes. It creates tiny test programs to probe for functions (or.hfiles or libraries, etc). It compiles them. If they compile and link cleanly, then the [given] function is provided. If it found thatstrdupwas available, it would output (e.g.)#define HAVE_STRDUP 1to a "features" file (e.g.features.h). Include that. There are other such defines (e.g.HAVE_STDIO_HorHAVE_LIBC_SO)malloc.hbut the C standard doesn't mentionmalloc.h. I don't know what is sufficient to test for functionmalloc()orstdlib.hhence no answer. With MS VC your_STDLIB_Hisn't known whether or not I#include <stdlib.h>It has a header guard but that is only set if the header is included, not whether available. The comment was to show that a conforming implementation does not need to providemalloc().