Detect obsolete and incorrect function prototypes with autoconf

I support an open source program that builds using autoconf.

Now I have problems with some of my users. They use a pre-distributed virtual machine from an organization that has the wrong prototype for strchr. Their prototype:

char *strchr(char *,int c);

when, of course, we know what it should be:

char *strchr(const char *s,int c);

(which in itself is broken, since the conclusion must be valid const char *, but then you could not change what it gives you if you passed in char *, not const char *, but I got distracted.

My question is: is there a way to create an autoconf macro that determines which prototype is being used and use it appropriately? I do not want my code to say:

v = strchr((char *)s,c);

Thank!

+3
1

, const char* ( , char*). , , #define - ( - /).

, - (untested):

AC_TRY_COMPILE([#include <cstring>],
 [const char* str = "Test"; strchr(str, 't');],
 conforming_strchr=yes,
 conforming_strchr=no)
if test "$conforming_strchr" = yes; then
  AC_DEFINE(HAVE_CONFORMING_STRCHR, 1,
   [define to 1 if strchr takes const char*])
fi
+4

Source: https://habr.com/ru/post/1771976/


All Articles