asprintf and snprintf support
This commit is contained in:
parent
c181849b95
commit
8b442f3f4c
60 changed files with 396 additions and 345 deletions
|
@ -86,7 +86,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
int print_files_long (const char *filename,
|
||||
const struct grub_dirhook_info *info)
|
||||
{
|
||||
char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1];
|
||||
char *pathname;
|
||||
|
||||
if ((! all) && (filename[0] == '.'))
|
||||
return 0;
|
||||
|
@ -96,9 +96,12 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
grub_file_t file;
|
||||
|
||||
if (dirname[grub_strlen (dirname) - 1] == '/')
|
||||
grub_sprintf (pathname, "%s%s", dirname, filename);
|
||||
pathname = grub_asprintf ("%s%s", dirname, filename);
|
||||
else
|
||||
grub_sprintf (pathname, "%s/%s", dirname, filename);
|
||||
pathname = grub_asprintf ("%s/%s", dirname, filename);
|
||||
|
||||
if (!pathname)
|
||||
return 1;
|
||||
|
||||
/* XXX: For ext2fs symlinks are detected as files while they
|
||||
should be reported as directories. */
|
||||
|
@ -130,8 +133,9 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
grub_uint32_t whole, fraction;
|
||||
|
||||
whole = grub_divmod64 (fsize, 100, &fraction);
|
||||
grub_sprintf (buf, "%u.%02u%c", whole, fraction,
|
||||
grub_human_sizes[units]);
|
||||
grub_snprintf (buf, sizeof (buf),
|
||||
"%u.%02u%c", whole, fraction,
|
||||
grub_human_sizes[units]);
|
||||
grub_printf ("%-12s", buf);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -61,7 +61,7 @@ grub_cmd_read (grub_extcmd_t cmd, int argc, char **argv)
|
|||
|
||||
if (cmd->state[0].set)
|
||||
{
|
||||
grub_sprintf (buf, "%x", value);
|
||||
grub_snprintf (buf, sizeof (buf), "%x", value);
|
||||
grub_env_set (cmd->state[0].arg, buf);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -182,12 +182,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
|||
{
|
||||
char *filename;
|
||||
|
||||
filename = grub_malloc (grub_strlen (prefix) + sizeof ("/parttool.lst"));
|
||||
filename = grub_asprintf ("%s/parttool.lst", prefix);
|
||||
if (filename)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
grub_sprintf (filename, "%s/parttool.lst", prefix);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,6 @@ void
|
|||
FUNC_NAME (const char *key, const char *var, int no_floppy)
|
||||
{
|
||||
int count = 0;
|
||||
char *buf = NULL;
|
||||
grub_fs_autoload_hook_t saved_autoload;
|
||||
|
||||
auto int iterate_device (const char *name);
|
||||
|
@ -48,24 +47,20 @@ FUNC_NAME (const char *key, const char *var, int no_floppy)
|
|||
|
||||
#ifdef DO_SEARCH_FILE
|
||||
{
|
||||
grub_size_t len;
|
||||
char *p;
|
||||
char *buf;
|
||||
grub_file_t file;
|
||||
|
||||
len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
|
||||
p = grub_realloc (buf, len);
|
||||
if (! p)
|
||||
buf = grub_asprintf ("(%s)%s", name, key);
|
||||
if (! buf)
|
||||
return 1;
|
||||
|
||||
buf = p;
|
||||
grub_sprintf (buf, "(%s)%s", name, key);
|
||||
|
||||
file = grub_file_open (buf);
|
||||
if (file)
|
||||
{
|
||||
found = 1;
|
||||
grub_file_close (file);
|
||||
}
|
||||
grub_free (buf);
|
||||
}
|
||||
#else
|
||||
{
|
||||
|
@ -135,8 +130,6 @@ FUNC_NAME (const char *key, const char *var, int no_floppy)
|
|||
else
|
||||
grub_device_iterate (iterate_device);
|
||||
|
||||
grub_free (buf);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE && count == 0)
|
||||
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
|
||||
}
|
||||
|
|
|
@ -349,18 +349,18 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)),
|
|||
grub_memcpy (hashme.prefix, hash_prefix, sizeof (hashme.prefix));
|
||||
|
||||
md5 ((char *) &hashme, sizeof (hashme), (char *) xnu_uuid);
|
||||
grub_sprintf (uuid_string,
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
(unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1],
|
||||
(unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],
|
||||
(unsigned int) xnu_uuid[4], (unsigned int) xnu_uuid[5],
|
||||
(unsigned int) ((xnu_uuid[6] & 0xf) | 0x30),
|
||||
(unsigned int) xnu_uuid[7],
|
||||
(unsigned int) ((xnu_uuid[8] & 0x3f) | 0x80),
|
||||
(unsigned int) xnu_uuid[9],
|
||||
(unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
|
||||
(unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
|
||||
(unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
|
||||
grub_snprintf (uuid_string, sizeof (uuid_string),
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
(unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1],
|
||||
(unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3],
|
||||
(unsigned int) xnu_uuid[4], (unsigned int) xnu_uuid[5],
|
||||
(unsigned int) ((xnu_uuid[6] & 0xf) | 0x30),
|
||||
(unsigned int) xnu_uuid[7],
|
||||
(unsigned int) ((xnu_uuid[8] & 0x3f) | 0x80),
|
||||
(unsigned int) xnu_uuid[9],
|
||||
(unsigned int) xnu_uuid[10], (unsigned int) xnu_uuid[11],
|
||||
(unsigned int) xnu_uuid[12], (unsigned int) xnu_uuid[13],
|
||||
(unsigned int) xnu_uuid[14], (unsigned int) xnu_uuid[15]);
|
||||
for (ptr = uuid_string; *ptr; ptr++)
|
||||
*ptr = grub_toupper (*ptr);
|
||||
if (argc == 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue