strdup() function

Usually, you just use an #if to define the function you want when under a certain compiler. If the built-in library doesn’t define strdup, there is no problem in defining it yourself (other than if they do define it in the future, you’ll have to take it out.)

// Only define strdup for platforms that are missing it..
#if COMPILER_XYZ || COMPILER_ABC
char *strdup(const char *)
{
   // ....
}
#endif

Leave a Comment