removed some duplicate code
This commit is contained in:
parent
4c7085f82b
commit
f07ccea799
10 changed files with 64 additions and 275 deletions
|
@ -17,6 +17,7 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <getopt.h>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/emu/misc.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/device.h>
|
||||
#include <grub/disk.h>
|
||||
|
|
157
util/misc.c
157
util/misc.c
|
@ -58,53 +58,6 @@
|
|||
#include <winioctl.h>
|
||||
#endif
|
||||
|
||||
int verbosity = 0;
|
||||
|
||||
void
|
||||
grub_util_warn (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
fprintf (stderr, _("%s: warn:"), program_name);
|
||||
fprintf (stderr, " ");
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
va_end (ap);
|
||||
fprintf (stderr, ".\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_info (const char *fmt, ...)
|
||||
{
|
||||
if (verbosity > 0)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
fprintf (stderr, _("%s: info:"), program_name);
|
||||
fprintf (stderr, " ");
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
va_end (ap);
|
||||
fprintf (stderr, ".\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_util_error (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
fprintf (stderr, _("%s: error:"), program_name);
|
||||
fprintf (stderr, " ");
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
va_end (ap);
|
||||
fprintf (stderr, ".\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
int
|
||||
grub_err_printf (const char *fmt, ...)
|
||||
|
@ -120,41 +73,6 @@ grub_err_printf (const char *fmt, ...)
|
|||
}
|
||||
#endif
|
||||
|
||||
void *
|
||||
xmalloc (size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc (size);
|
||||
if (! p)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
xrealloc (void *ptr, size_t size)
|
||||
{
|
||||
ptr = realloc (ptr, size);
|
||||
if (! ptr)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *
|
||||
xstrdup (const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char *newstr;
|
||||
|
||||
len = strlen (str);
|
||||
newstr = (char *) xmalloc (len + 1);
|
||||
memcpy (newstr, str, len + 1);
|
||||
|
||||
return newstr;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_util_get_path (const char *dir, const char *file)
|
||||
{
|
||||
|
@ -277,34 +195,6 @@ grub_register_exported_symbols (void)
|
|||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_exit (void)
|
||||
{
|
||||
exit (1);
|
||||
}
|
||||
|
||||
grub_uint32_t
|
||||
grub_get_rtc (void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday (&tv, 0);
|
||||
|
||||
return (tv.tv_sec * GRUB_TICKS_PER_SECOND
|
||||
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
|
||||
* GRUB_TICKS_PER_SECOND / 1000000));
|
||||
}
|
||||
|
||||
grub_uint64_t
|
||||
grub_get_time_ms (void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday (&tv, 0);
|
||||
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
void
|
||||
|
@ -335,53 +225,6 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
|||
}
|
||||
#endif
|
||||
|
||||
#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, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *result;
|
||||
|
||||
va_start (ap, fmt);
|
||||
if (vasprintf (&result, fmt, ap) < 0)
|
||||
{
|
||||
if (errno == ENOMEM)
|
||||
grub_util_error ("out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
void sync (void)
|
||||
|
|
85
util/mm.c
85
util/mm.c
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
grub_malloc (grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
ret = malloc (size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *
|
||||
grub_zalloc (grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = grub_malloc (size);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memset (ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_free (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_realloc (void *ptr, grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
ret = realloc (ptr, size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 *);
|
||||
if (posix_memalign (&p, align, size) != 0)
|
||||
p = 0;
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
p = memalign (align, size);
|
||||
#else
|
||||
(void) align;
|
||||
(void) size;
|
||||
grub_util_error ("grub_memalign is not supported");
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
|
||||
return p;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue