| 1 | dnl See whether strncmp reads past the end of its string parameters. |
| 2 | dnl On some versions of SunOS4 at least, strncmp reads a word at a time |
| 3 | dnl but erroneously reads past the end of strings. This can cause |
| 4 | dnl a SEGV in some cases. |
| 5 | AC_DEFUN(libiberty_AC_FUNC_STRNCMP, |
| 6 | [AC_REQUIRE([AC_FUNC_MMAP]) |
| 7 | AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, |
| 8 | [AC_TRY_RUN([ |
| 9 | /* Test by Jim Wilson and Kaveh Ghazi. |
| 10 | Check whether strncmp reads past the end of its string parameters. */ |
| 11 | #include <sys/types.h> |
| 12 | |
| 13 | #ifdef HAVE_FCNTL_H |
| 14 | #include <fcntl.h> |
| 15 | #endif |
| 16 | |
| 17 | #ifdef HAVE_SYS_MMAN_H |
| 18 | #include <sys/mman.h> |
| 19 | #endif |
| 20 | |
| 21 | #ifndef MAP_ANON |
| 22 | #ifdef MAP_ANONYMOUS |
| 23 | #define MAP_ANON MAP_ANONYMOUS |
| 24 | #else |
| 25 | #define MAP_ANON MAP_FILE |
| 26 | #endif |
| 27 | #endif |
| 28 | |
| 29 | #ifndef MAP_FILE |
| 30 | #define MAP_FILE 0 |
| 31 | #endif |
| 32 | #ifndef O_RDONLY |
| 33 | #define O_RDONLY 0 |
| 34 | #endif |
| 35 | |
| 36 | #define MAP_LEN 0x10000 |
| 37 | |
| 38 | main () |
| 39 | { |
| 40 | #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) |
| 41 | char *p; |
| 42 | int dev_zero; |
| 43 | |
| 44 | dev_zero = open ("/dev/zero", O_RDONLY); |
| 45 | if (dev_zero < 0) |
| 46 | exit (1); |
| 47 | |
| 48 | p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, |
| 49 | MAP_ANON|MAP_PRIVATE, dev_zero, 0); |
| 50 | if (p == (char *)-1) |
| 51 | exit (2); |
| 52 | else |
| 53 | { |
| 54 | char *string = "__si_type_info"; |
| 55 | char *q = (char *) p + MAP_LEN - strlen (string) - 2; |
| 56 | char *r = (char *) p + 0xe; |
| 57 | |
| 58 | strcpy (q, string); |
| 59 | strcpy (r, string); |
| 60 | strncmp (r, q, 14); |
| 61 | } |
| 62 | #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ |
| 63 | exit (0); |
| 64 | } |
| 65 | ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, |
| 66 | ac_cv_func_strncmp_works=no) |
| 67 | rm -f core core.* *.core]) |
| 68 | if test $ac_cv_func_strncmp_works = no ; then |
| 69 | LIBOBJS="$LIBOBJS strncmp.o" |
| 70 | fi |
| 71 | ]) |
| 72 | |
| 73 | dnl See if errno must be declared even when <errno.h> is included. |
| 74 | AC_DEFUN(libiberty_AC_DECLARE_ERRNO, |
| 75 | [AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, |
| 76 | [AC_TRY_COMPILE( |
| 77 | [#include <errno.h>], |
| 78 | [int x = errno;], |
| 79 | libiberty_cv_declare_errno=no, |
| 80 | libiberty_cv_declare_errno=yes)]) |
| 81 | if test $libiberty_cv_declare_errno = yes |
| 82 | then AC_DEFINE(NEED_DECLARATION_ERRNO, 1, |
| 83 | [Define if errno must be declared even when <errno.h> is included.]) |
| 84 | fi |
| 85 | ]) |