From: ghazi Date: Fri, 13 Nov 1998 16:36:04 +0000 (+0000) Subject: * configure.in: Check for calloc. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34fa88316071e4f2d3aab04444bbaa996495499c;p=platform%2Fupstream%2Flinaro-gcc.git * configure.in: Check for calloc. * calloc.c: New file. * xmalloc.c (xcalloc): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@23642 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index d4a9015..d2aaa31 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,11 @@ +Fri Nov 13 19:18:05 1998 Kaveh R. Ghazi + + * configure.in: Check for calloc. + + * calloc.c: New file. + + * xmalloc.c (xcalloc): New function. + Fri Nov 13 08:51:46 EST 1998 Andrew MacLeod *cplus-dem.c (demangle_prefix): Use the last "__" diff --git a/libiberty/calloc.c b/libiberty/calloc.c new file mode 100644 index 0000000..c8c0a78 --- /dev/null +++ b/libiberty/calloc.c @@ -0,0 +1,26 @@ +#include "ansidecl.h" +#include "libiberty.h" + +#ifdef ANSI_PROTOTYPES +#include +#else +#define size_t unsigned long +#endif + +/* For systems with larger pointers than ints, this must be declared. */ +PTR malloc PARAMS ((size_t)); + +PTR +calloc (nelem, elsize) + size_t nelem, elsize; +{ + register PTR ptr; + + if (nelem == 0 || elsize == 0) + nelem = elsize = 1; + + ptr = malloc (nelem * elsize); + if (ptr) bzero (ptr, nelem * elsize); + + return ptr; +} diff --git a/libiberty/configure b/libiberty/configure index cf36e1e..b52584e 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -1077,6 +1077,7 @@ funcs="$funcs basename" funcs="$funcs bcmp" funcs="$funcs bcopy" funcs="$funcs bzero" +funcs="$funcs calloc" funcs="$funcs clock" funcs="$funcs getcwd" funcs="$funcs getpagesize" @@ -1116,15 +1117,15 @@ checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times" # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. if test "x" = "y"; then - for ac_func in asprintf atexit basename bcmp bcopy bzero clock getcwd + for ac_func in asprintf atexit basename bcmp bcopy bzero calloc clock getcwd do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1123: checking for $ac_func" >&5 +echo "configure:1124: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1152: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1174,12 +1175,12 @@ done for ac_func in getpagesize index insque memchr memcmp memcpy memmove do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1178: checking for $ac_func" >&5 +echo "configure:1179: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1207: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1229,12 +1230,12 @@ done for ac_func in memset random rename rindex sigsetmask strcasecmp do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1233: checking for $ac_func" >&5 +echo "configure:1234: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1262: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1284,12 +1285,12 @@ done for ac_func in strchr strdup strncasecmp strrchr strstr strtod strtol do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1288: checking for $ac_func" >&5 +echo "configure:1289: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1317: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1339,12 +1340,12 @@ done for ac_func in strtoul tmpnam vasprintf vfprintf vprintf vsprintf waitpid do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1343: checking for $ac_func" >&5 +echo "configure:1344: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1372: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1406,12 +1407,12 @@ EOF for ac_func in getrusage on_exit psignal strerror strsignal sysconf times do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1410: checking for $ac_func" >&5 +echo "configure:1411: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1439: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1589,7 +1590,7 @@ EOF # We haven't set the list of objects yet. Use the standard autoconf # tests. This will only work if the compiler works. echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:1593: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:1594: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -1599,11 +1600,11 @@ ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1608: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -1623,19 +1624,19 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:1627: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:1628: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross for ac_func in $funcs do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1634: checking for $ac_func" >&5 +echo "configure:1635: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1663: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1687,19 +1688,19 @@ done # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6 -echo "configure:1691: checking for working alloca.h" >&5 +echo "configure:1692: checking for working alloca.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { char *p = alloca(2 * sizeof(int)); ; return 0; } EOF -if { (eval echo configure:1703: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1704: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* ac_cv_header_alloca_h=yes else @@ -1720,12 +1721,12 @@ EOF fi echo $ac_n "checking for alloca""... $ac_c" 1>&6 -echo "configure:1724: checking for alloca" >&5 +echo "configure:1725: checking for alloca" >&5 if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1753: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* ac_cv_func_alloca_works=yes else @@ -1780,12 +1781,12 @@ EOF echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6 -echo "configure:1784: checking whether alloca needs Cray hooks" >&5 +echo "configure:1785: checking whether alloca needs Cray hooks" >&5 if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&6 if test $ac_cv_os_cray = yes; then for ac_func in _getb67 GETB67 getb67; do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1814: checking for $ac_func" >&5 +echo "configure:1815: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1843: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1865,7 +1866,7 @@ done fi echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6 -echo "configure:1869: checking stack direction for C alloca" >&5 +echo "configure:1870: checking stack direction for C alloca" >&5 if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1873,7 +1874,7 @@ else ac_cv_c_stack_direction=0 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1897: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_c_stack_direction=1 else @@ -1914,12 +1915,12 @@ EOF fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1918: checking for ANSI C header files" >&5 +echo "configure:1919: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1927,7 +1928,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1931: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1932: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1944,7 +1945,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1962,7 +1963,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1983,7 +1984,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1994,7 +1995,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1998: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1999: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -2018,12 +2019,12 @@ EOF fi echo $ac_n "checking for pid_t""... $ac_c" 1>&6 -echo "configure:2022: checking for pid_t" >&5 +echo "configure:2023: checking for pid_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #if STDC_HEADERS @@ -2052,17 +2053,17 @@ fi ac_safe=`echo "vfork.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for vfork.h""... $ac_c" 1>&6 -echo "configure:2056: checking for vfork.h" >&5 +echo "configure:2057: checking for vfork.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2066: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2067: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -2087,18 +2088,18 @@ else fi echo $ac_n "checking for working vfork""... $ac_c" 1>&6 -echo "configure:2091: checking for working vfork" >&5 +echo "configure:2092: checking for working vfork" >&5 if eval "test \"`echo '$''{'ac_cv_func_vfork_works'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then echo $ac_n "checking for vfork""... $ac_c" 1>&6 -echo "configure:2097: checking for vfork" >&5 +echo "configure:2098: checking for vfork" >&5 if eval "test \"`echo '$''{'ac_cv_func_vfork'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2126: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_vfork=yes" else @@ -2143,7 +2144,7 @@ fi ac_cv_func_vfork_works=$ac_cv_func_vfork else cat > conftest.$ac_ext < @@ -2238,7 +2239,7 @@ main() { } } EOF -if { (eval echo configure:2242: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2243: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_func_vfork_works=yes else @@ -2265,19 +2266,19 @@ fi fi for v in $vars; do echo $ac_n "checking for $v""... $ac_c" 1>&6 -echo "configure:2269: checking for $v" >&5 +echo "configure:2270: checking for $v" >&5 if eval "test \"`echo '$''{'libiberty_cv_var_$v'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2282: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "libiberty_cv_var_$v=yes" else @@ -2303,12 +2304,12 @@ EOF for ac_func in $checkfuncs do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2307: checking for $ac_func" >&5 +echo "configure:2308: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:2336: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else diff --git a/libiberty/configure.in b/libiberty/configure.in index ee82459..78bf960 100644 --- a/libiberty/configure.in +++ b/libiberty/configure.in @@ -117,6 +117,7 @@ funcs="$funcs basename" funcs="$funcs bcmp" funcs="$funcs bcopy" funcs="$funcs bzero" +funcs="$funcs calloc" funcs="$funcs clock" funcs="$funcs getcwd" funcs="$funcs getpagesize" @@ -156,7 +157,7 @@ checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times" # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. if test "x" = "y"; then - AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero clock getcwd) + AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero calloc clock getcwd) AC_CHECK_FUNCS(getpagesize index insque memchr memcmp memcpy memmove) AC_CHECK_FUNCS(memset random rename rindex sigsetmask strcasecmp) AC_CHECK_FUNCS(strchr strdup strncasecmp strrchr strstr strtod strtol) diff --git a/libiberty/xmalloc.c b/libiberty/xmalloc.c index b88105a..4f39014 100644 --- a/libiberty/xmalloc.c +++ b/libiberty/xmalloc.c @@ -36,6 +36,7 @@ Boston, MA 02111-1307, USA. */ /* For systems with larger pointers than ints, these must be declared. */ PTR malloc PARAMS ((size_t)); PTR realloc PARAMS ((PTR, size_t)); +PTR calloc PARAMS ((size_t, size_t)); PTR sbrk PARAMS ((ptrdiff_t)); #endif @@ -95,6 +96,41 @@ xmalloc (size) } PTR +xcalloc (nelem, elsize) + size_t nelem, elsize; +{ + PTR newmem; + + if (nelem == 0 || elsize == 0) + nelem = elsize = 1; + + newmem = calloc (nelem, elsize); + if (!newmem) + { +#if ! defined (_WIN32) || defined (__CYGWIN32__) + extern char **environ; + size_t allocated; + + if (first_break != NULL) + allocated = (char *) sbrk (0) - first_break; + else + allocated = (char *) sbrk (0) - (char *) &environ; + fprintf (stderr, + "\n%s%sCan not allocate %lu bytes after allocating %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) (nelem * elsize), (unsigned long) allocated); +#else + fprintf (stderr, + "\n%s%sCan not allocate %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) (nelem * elsize)); +#endif /* ! _WIN32 || __CYGWIN32 __ */ + xexit (1); + } + return (newmem); +} + +PTR xrealloc (oldmem, size) PTR oldmem; size_t size;