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
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
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.
|
||||
|
||||
2009-12-06 David S. Miller <davem@sunset.davemloft.net>
|
||||
|
||||
* disk/ieee1275/ofdisk.c (grub_ofdisk_iterate): Recognize
|
||||
|
|
|
@ -194,7 +194,7 @@ else
|
|||
fi
|
||||
|
||||
# Check for functions.
|
||||
AC_CHECK_FUNCS(posix_memalign memalign asprintf)
|
||||
AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf)
|
||||
|
||||
# For grub-mkisofs
|
||||
AC_HEADER_MAJOR
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -57,12 +58,20 @@ void grub_util_write_image (const char *img, size_t size, FILE *out);
|
|||
void grub_util_write_image_at (const void *img, size_t size, off_t offset,
|
||||
FILE *out);
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
|
||||
int vasprintf (char **buf, const char *fmt, va_list ap);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
|
||||
int asprintf (char **buf, const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
char *xasprintf (const char *fmt, ...);
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
#define fseeko fseeko64
|
||||
|
|
|
@ -546,7 +546,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
if (q)
|
||||
*q = ',';
|
||||
|
||||
asprintf (&grub_dev, "md%s", p);
|
||||
grub_dev = xasprintf ("md%s", p);
|
||||
free (p);
|
||||
}
|
||||
else if (os_dev[7] == '/' && os_dev[8] == 'd')
|
||||
|
@ -561,7 +561,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
if (q)
|
||||
*q = ',';
|
||||
|
||||
asprintf (&grub_dev, "md%s", p);
|
||||
grub_dev = xasprintf ("md%s", p);
|
||||
free (p);
|
||||
}
|
||||
else if (os_dev[7] >= '0' && os_dev[7] <= '9')
|
||||
|
@ -574,7 +574,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
if (q)
|
||||
*q = ',';
|
||||
|
||||
asprintf (&grub_dev, "md%s", p);
|
||||
grub_dev = xasprintf ("md%s", p);
|
||||
free (p);
|
||||
}
|
||||
else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
|
||||
|
@ -587,7 +587,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
if (q)
|
||||
*q = ',';
|
||||
|
||||
asprintf (&grub_dev, "md%s", p);
|
||||
grub_dev = xasprintf ("md%s", p);
|
||||
free (p);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -107,7 +107,7 @@ create_envblk_file (const char *name)
|
|||
if (! buf)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
asprintf (&namenew, "%s.new", name);
|
||||
namenew = xasprintf ("%s.new", name);
|
||||
fp = fopen (namenew, "wb");
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open the file %s", namenew);
|
||||
|
|
|
@ -366,8 +366,8 @@ write_font (struct grub_font_info *font_info, char *output_file)
|
|||
if (! style_name[0])
|
||||
strcpy (style_name, " Regular");
|
||||
|
||||
asprintf (&font_name, "%s %s %d", font_info->name, &style_name[1],
|
||||
font_info->size);
|
||||
font_name = xasprintf ("%s %s %d", font_info->name, &style_name[1],
|
||||
font_info->size);
|
||||
|
||||
write_string_section ("NAME", font_name, &offset, file);
|
||||
write_string_section ("FAMI", font_info->name, &offset, file);
|
||||
|
|
|
@ -254,7 +254,7 @@ probe (const char *path, char *device_name)
|
|||
filebuf_via_sys = grub_util_read_image (path);
|
||||
|
||||
rel_path = make_system_path_relative_to_its_root (path);
|
||||
asprintf (&grub_path, "(%s)%s", drive_name, rel_path);
|
||||
grub_path = xasprintf ("(%s)%s", drive_name, rel_path);
|
||||
free (rel_path);
|
||||
grub_util_info ("reading %s via GRUB facilities", grub_path);
|
||||
file = grub_file_open (grub_path);
|
||||
|
|
|
@ -679,14 +679,14 @@ make_device_name (int drive, int dos_part, int bsd_part)
|
|||
char *bsd_part_str = NULL;
|
||||
|
||||
if (dos_part >= 0)
|
||||
asprintf (&dos_part_str, ",%d", dos_part + 1);
|
||||
dos_part_str = xasprintf (",%d", dos_part + 1);
|
||||
|
||||
if (bsd_part >= 0)
|
||||
asprintf (&bsd_part_str, ",%c", dos_part + 'a');
|
||||
bsd_part_str = xasprintf (",%c", dos_part + 'a');
|
||||
|
||||
asprintf (&ret, "%s%s%s", map[drive].drive,
|
||||
dos_part_str ? : "",
|
||||
bsd_part_str ? : "");
|
||||
ret = xasprintf ("%s%s%s", map[drive].drive,
|
||||
dos_part_str ? : "",
|
||||
bsd_part_str ? : "");
|
||||
|
||||
if (dos_part_str)
|
||||
free (dos_part_str);
|
||||
|
|
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…
Reference in a new issue