2009-12-07 Colin Watson <cjwatson@ubuntu.com>
* configure.ac: Check for vasprintf. * util/misc.c (asprintf): Move allocation from here ... (vasprintf): ... to here. New function. (xasprintf): New function. * include/grub/util/misc.h (vasprintf, xasprintf): Add prototypes. * util/getroot.c (grub_util_get_grub_dev): Use xasprintf. * util/grub-mkfont.c (write_font): Likewise. * util/grub-probe.c (probe): Likewise. * util/hostdisk.c (make_device_name): Likewise.
This commit is contained in:
parent
de6daa8b56
commit
d6ceebf1d9
9 changed files with 68 additions and 18 deletions
36
util/misc.c
36
util/misc.c
|
@ -30,6 +30,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/misc.h>
|
||||
|
@ -370,6 +371,19 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
|||
{
|
||||
}
|
||||
|
||||
#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
|
||||
|
@ -378,11 +392,8 @@ asprintf (char **buf, const char *fmt, ...)
|
|||
int status;
|
||||
va_list ap;
|
||||
|
||||
/* Should be large enough. */
|
||||
*buf = xmalloc (512);
|
||||
|
||||
va_start (ap, fmt);
|
||||
status = vsprintf (*buf, fmt, ap);
|
||||
status = vasprintf (*buf, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return status;
|
||||
|
@ -390,6 +401,23 @@ asprintf (char **buf, const char *fmt, ...)
|
|||
|
||||
#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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue