* 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 <hde@foobar-qux.org>.
* configure.ac (AC_GNU_SOURCE): Added.
(AC_CHECK_FUNCS): Check posix_memalign and memalign for the host
type.
+2006-06-14 Yoshinori K. Okuji <okuji@enbug.org>
+
+ * 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 <hde@foobar-qux.org>.
+
+ * configure.ac (AC_GNU_SOURCE): Added.
+ (AC_CHECK_FUNCS): Check posix_memalign and memalign for the host
+ type.
+
2006-06-09 Yoshinori K. Okuji <okuji@enbug.org>
* loader/i386/pc/linux.c (grub_rescue_cmd_initrd): Make sure that
generally assist in the GRUB 2 maintainership process:
Guillem Jover <guillem@hadrons.org>
+Harley D. Eades III <hde@foobar-qux.org>
+Hollis Blanchard <hollis@penguinppc.org>
Jeroen Dekkers <jeroen@dekkers.cx>
Johan Rydberg <jrydberg@night.trouble.net>
-Hollis Blanchard <hollis@penguinppc.org>
Marco Gerards <metgerards@student.han.nl>
NIIBE Yutaka <gniibe@m17n.org>
Omniflux <omniflux@omniflux.com>
/* Define to 1 if you have the <lzo/lzo1x.h> 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 <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <ncurses.h> 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 <stdint.h> header file. */
#undef HAVE_STDINT_H
/* 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
{ (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"
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 <limits.h> declares $ac_func.
+ For example, HP-UX 11i <limits.h> 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 <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#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.
#
# 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.
# 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.
#
/*
* 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
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
+#include <unistd.h>
extern char *progname;
extern int verbosity;
*/
#include <stdlib.h>
-#include <malloc.h>
#include <sys/stat.h>
#include <argp.h>
#include <string.h>
/*
* 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
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <config.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <malloc.h>
#include <unistd.h>
#include <grub/util/misc.h>
#include <grub/term.h>
#include <grub/machine/time.h>
+/* 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 <malloc.h>
+#endif
+
char *progname = 0;
int verbosity = 0;
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");