asprintf and snprintf support

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-29 10:04:06 +01:00
parent c181849b95
commit 8b442f3f4c
60 changed files with 396 additions and 345 deletions

View file

@ -272,9 +272,9 @@ grub_gfxterm_init (void)
err = grub_video_set_mode (DEFAULT_VIDEO_MODE, video_hook);
else
{
tmp = grub_malloc (grub_strlen (modevar)
+ sizeof (DEFAULT_VIDEO_MODE) + 1);
grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar);
tmp = grub_asprintf ("%s;" DEFAULT_VIDEO_MODE, modevar);
if (!tmp)
return grub_errno;
err = grub_video_set_mode (tmp, video_hook);
grub_free (tmp);
}

View file

@ -104,7 +104,7 @@ grub_ofconsole_getcharwidth (grub_uint32_t c __attribute__((unused)))
static void
grub_ofconsole_setcolorstate (grub_term_color_state state)
{
char setcol[20];
char *setcol;
int fg;
int bg;
@ -123,8 +123,10 @@ grub_ofconsole_setcolorstate (grub_term_color_state state)
return;
}
grub_sprintf (setcol, "\e[3%dm\e[4%dm", fg, bg);
grub_ofconsole_writeesc (setcol);
setcol = grub_asprintf ("\e[3%dm\e[4%dm", fg, bg);
if (setcol)
grub_ofconsole_writeesc (setcol);
grub_free (setcol);
}
static void
@ -287,15 +289,16 @@ grub_ofconsole_getwh (void)
static void
grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y)
{
char s[11]; /* 5 + 3 + 3. */
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI))
{
char *s;
grub_curr_x = x;
grub_curr_y = y;
grub_sprintf (s, "\e[%d;%dH", y + 1, x + 1);
grub_ofconsole_writeesc (s);
s = grub_asprintf ("\e[%d;%dH", y + 1, x + 1);
if (s)
grub_ofconsole_writeesc (s);
grub_free (s);
}
else
{

View file

@ -167,7 +167,7 @@ save_text(const char *fmt, const char *s, int len)
get_space(s_len + 1);
(void) grub_sprintf(out_buff + out_used, fmt, s);
(void) grub_snprintf(out_buff + out_used, s_len + 1, fmt, s);
out_used += grub_strlen(out_buff + out_used);
}
@ -179,7 +179,7 @@ save_number(const char *fmt, int number, int len)
get_space((unsigned) len + 1);
(void) grub_sprintf(out_buff + out_used, fmt, number);
(void) grub_snprintf(out_buff + out_used, len + 1, fmt, number);
out_used += grub_strlen(out_buff + out_used);
}