2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <config-util.h>
2N/A
2N/A#include <grub/types.h>
2N/A#include <grub/err.h>
2N/A#include <grub/mm.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A
2N/Avoid *
2N/Agrub_malloc (grub_size_t size)
2N/A{
2N/A void *ret;
2N/A ret = malloc (size);
2N/A if (!ret)
2N/A grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
2N/A return ret;
2N/A}
2N/A
2N/Avoid *
2N/Agrub_zalloc (grub_size_t size)
2N/A{
2N/A void *ret;
2N/A
2N/A ret = grub_malloc (size);
2N/A if (!ret)
2N/A return NULL;
2N/A memset (ret, 0, size);
2N/A return ret;
2N/A}
2N/A
2N/Avoid
2N/Agrub_free (void *ptr)
2N/A{
2N/A free (ptr);
2N/A}
2N/A
2N/Avoid *
2N/Agrub_realloc (void *ptr, grub_size_t size)
2N/A{
2N/A void *ret;
2N/A ret = realloc (ptr, size);
2N/A if (!ret)
2N/A grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
2N/A return ret;
2N/A}
2N/A
2N/Avoid *
2N/Agrub_memalign (grub_size_t align, grub_size_t size)
2N/A{
2N/A void *p;
2N/A
2N/A#if defined(HAVE_POSIX_MEMALIGN)
2N/A if (align < sizeof (void *))
2N/A align = sizeof (void *);
2N/A if (posix_memalign (&p, align, size) != 0)
2N/A p = 0;
2N/A#elif defined(HAVE_MEMALIGN)
2N/A p = memalign (align, size);
2N/A#else
2N/A (void) align;
2N/A (void) size;
2N/A grub_util_error (_("grub_memalign is not supported"));
2N/A#endif
2N/A
2N/A if (!p)
2N/A grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
2N/A
2N/A return p;
2N/A}