I maintain an open source program that builds with autoconf.
Right now I’m having a problem with some of my users. They are using a pre-distributed VM from an organization that has an incorrect prototype for strchr in it. Their prototype is:
char *strchr(char *,int c);
when of course we know it should be:
char *strchr(const char *s,int c);
(which is itself broken, as the output should really be const char *, but then you couldn’t modify what it gives you if you passed in a char * and not a const char *, but I digress.
My question: is there a way to create an autoconf macro that determines which prototype is in use and use it accordingly? I’d rather not make my code say:
v = strchr((char *)s,c);
Thanks!
You should be able to set up a configure test that attempts to call the
const char*version (NOT using a literal since there’s an implicit conversion tochar*). Configure will tell you if it compiled or not so you can#definesomething based on that and use it to make a decision in your code (preferably in some sort of wrapper/utility class).For example something like (untested):