* 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-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
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
#include <stdlib.h>
#include <stdio.h>
+#include <stdarg.h>
#include <setjmp.h>
#include <unistd.h>
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
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')
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')
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')
if (q)
*q = ',';
- asprintf (&grub_dev, "md%s", p);
+ grub_dev = xasprintf ("md%s", p);
free (p);
}
else
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);
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);
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);
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);
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
+#include <errno.h>
#include <grub/kernel.h>
#include <grub/misc.h>
{
}
+#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
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;
#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)