diff --git a/ChangeLog b/ChangeLog index 2478f6e53..dffb7f538 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-06-14 Yoshinori K. Okuji + + * util/misc.c: Include config.h. + [!HAVE_MEMALIGN]: Do not include malloc.h. + (grub_memalign): Use posix_memalign, if present. Then, use + memalign, if present. Otherwise, emit an error. + + * util/grub-emu.c: Do not include malloc.h. + + * include/grub/util/misc.h: Include unistd.h. This is required for + FreeBSD, because off_t is defined in unistd.h. Reported by Harley + D. Eades III . + + * configure.ac (AC_GNU_SOURCE): Added. + (AC_CHECK_FUNCS): Check posix_memalign and memalign for the host + type. + 2006-06-09 Yoshinori K. Okuji * loader/i386/pc/linux.c (grub_rescue_cmd_initrd): Make sure that diff --git a/THANKS b/THANKS index 82252cfb7..a80082949 100644 --- a/THANKS +++ b/THANKS @@ -7,9 +7,10 @@ time and energy in helping to track down bugs, add new features, and generally assist in the GRUB 2 maintainership process: Guillem Jover +Harley D. Eades III +Hollis Blanchard Jeroen Dekkers Johan Rydberg -Hollis Blanchard Marco Gerards NIIBE Yutaka Omniflux diff --git a/config.h.in b/config.h.in index ba432ac15..c22d5b12b 100644 --- a/config.h.in +++ b/config.h.in @@ -31,6 +31,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LZO_LZO1X_H +/* Define to 1 if you have the `memalign' function. */ +#undef HAVE_MEMALIGN + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H @@ -40,6 +43,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NCURSES_H +/* Define to 1 if you have the `posix_memalign' function. */ +#undef HAVE_POSIX_MEMALIGN + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H @@ -101,5 +107,10 @@ /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif + /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES diff --git a/configure b/configure index c42ed892c..9aa7b714e 100644 --- a/configure +++ b/configure @@ -2710,6 +2710,12 @@ echo "$as_me: error: GCC is required" >&2;} { (exit 1); exit 1; }; } +cat >>confdefs.h <<\_ACEOF +#define _GNU_SOURCE 1 +_ACEOF + + + # Check whether --enable-largefile or --disable-largefile was given. if test "${enable_largefile+set}" = set; then enableval="$enable_largefile" @@ -5392,6 +5398,111 @@ fi done +# Check for functions. + + +for ac_func in posix_memalign memalign +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + # # Check for target programs. # diff --git a/configure.ac b/configure.ac index c9a2bd785..42a053146 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,7 @@ AC_PROG_CC # Must be GCC. test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required]) +AC_GNU_SOURCE AC_SYS_LARGEFILE # Identify characteristics of the host architecture. @@ -152,6 +153,9 @@ AC_SUBST(LIBCURSES) # Check for headers. AC_CHECK_HEADERS(ncurses/curses.h ncurses.h curses.h) +# Check for functions. +AC_CHECK_FUNCS(posix_memalign memalign) + # # Check for target programs. # diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 73060f5ad..76393159d 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include #include #include +#include extern char *progname; extern int verbosity; diff --git a/util/grub-emu.c b/util/grub-emu.c index 602098f1d..2ef485736 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/util/misc.c b/util/misc.c index 21857916b..5f6327558 100644 --- a/util/misc.c +++ b/util/misc.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005 Free Software Foundation, Inc. + * Copyright (C) 2002,2003,2005,2006 Free Software Foundation, Inc. * * GRUB is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + #include #include #include @@ -24,7 +26,6 @@ #include #include #include -#include #include #include @@ -32,6 +33,12 @@ #include #include +/* Include malloc.h, only if memalign is available. It is known that + memalign is declared in malloc.h in all systems, if present. */ +#ifdef HAVE_MEMALIGN +# include +#endif + char *progname = 0; int verbosity = 0; @@ -228,8 +235,16 @@ void * grub_memalign (grub_size_t align, grub_size_t size) { void *p; - + +#if defined(HAVE_POSIX_MEMALIGN) + if (posix_memalign (&p, align, size) != 0) + p = 0; +#elif defined(HAVE_MEMALIGN) p = memalign (align, size); +#else + grub_util_error ("grub_memalign is not supported"); +#endif + if (! p) grub_util_error ("out of memory");