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.
This commit is contained in:
okuji 2006-06-13 22:50:01 +00:00
parent fd39d4da42
commit 4889bdeca3
8 changed files with 165 additions and 6 deletions

View file

@ -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 <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@ -24,7 +26,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <malloc.h>
#include <unistd.h>
#include <grub/util/misc.h>
@ -32,6 +33,12 @@
#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;
@ -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");