removed some duplicate code

This commit is contained in:
BVK Chaitanya 2010-04-27 20:55:12 +05:30
parent 4c7085f82b
commit f07ccea799
10 changed files with 64 additions and 275 deletions

View file

@ -62,70 +62,14 @@ grub_util_error (const char *fmt, ...)
exit (1);
}
void *
grub_malloc (grub_size_t size)
{
return malloc (size);
}
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = malloc (size);
memset (ret, 0, size);
return ret;
}
void
grub_free (void *ptr)
{
free (ptr);
}
void *
grub_realloc (void *ptr, grub_size_t size)
{
return realloc (ptr, size);
}
void *
grub_memalign (grub_size_t align, grub_size_t size)
{
void *p;
#if defined(HAVE_POSIX_MEMALIGN)
if (align < sizeof (void *))
align = sizeof (void *);
else if (align % sizeof (void *))
grub_fatal ("bad alignment");
if (posix_memalign (&p, align, size) != 0)
p = 0;
#elif defined(HAVE_MEMALIGN)
p = memalign (align, size);
#else
(void) align;
(void) size;
grub_fatal ("grub_memalign is not supported");
#endif
if (! p)
grub_fatal ("out of memory");
return p;
}
void *
xmalloc (grub_size_t size)
{
void *p;
p = grub_malloc (size);
p = malloc (size);
if (! p)
grub_fatal ("out of memory");
grub_util_error ("out of memory");
return p;
}
@ -133,9 +77,9 @@ xmalloc (grub_size_t size)
void *
xrealloc (void *ptr, grub_size_t size)
{
ptr = grub_realloc (ptr, size);
ptr = realloc (ptr, size);
if (! ptr)
grub_fatal ("out of memory");
grub_util_error ("out of memory");
return ptr;
}
@ -146,13 +90,43 @@ xstrdup (const char *str)
size_t len;
char *newstr;
len = grub_strlen (str);
len = strlen (str);
newstr = (char *) xmalloc (len + 1);
grub_memcpy (newstr, str, len + 1);
memcpy (newstr, str, len + 1);
return newstr;
}
#ifndef HAVE_VASPRINTF
int
vasprintf (char **buf, const char *fmt, va_list ap)
{
/* Should be large enough. */
*buf = xmalloc (512);
return vsprintf (*buf, fmt, ap);
}
#endif
#ifndef HAVE_ASPRINTF
int
asprintf (char **buf, const char *fmt, ...)
{
int status;
va_list ap;
va_start (ap, fmt);
status = vasprintf (*buf, fmt, ap);
va_end (ap);
return status;
}
#endif
char *
xasprintf (const char *fmt, ...)
{