net: Break out nested function

Nested functions are not supported in C, but are permitted as an extension
in the GNU C dialect. Commit cb2f15c544 ("normal/main: Search for specific
config files for netboot") added a nested function which caused the build
to break when compiling with clang.

Break that out into a static helper function to make the code portable again.

Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Tested-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Javier Martinez Canillas 2020-05-19 17:53:03 +02:00 committed by Daniel Kiper
parent cc6bd49a52
commit 96be75ecbd

View file

@ -1735,14 +1735,9 @@ grub_net_restore_hw (void)
return GRUB_ERR_NONE;
}
grub_err_t
grub_net_search_config_file (char *config)
{
grub_size_t config_len;
char *suffix;
auto int search_through (grub_size_t num_tries, grub_size_t slice_size);
int search_through (grub_size_t num_tries, grub_size_t slice_size)
static int
grub_config_search_through (char *config, char *suffix,
grub_size_t num_tries, grub_size_t slice_size)
{
while (num_tries-- > 0)
{
@ -1772,6 +1767,12 @@ grub_net_search_config_file (char *config)
return 1;
}
grub_err_t
grub_net_search_config_file (char *config)
{
grub_size_t config_len;
char *suffix;
config_len = grub_strlen (config);
config[config_len] = '-';
suffix = config + config_len + 1;
@ -1801,7 +1802,7 @@ grub_net_search_config_file (char *config)
if (client_uuid)
{
grub_strcpy (suffix, client_uuid);
if (search_through (1, 0) == 0)
if (grub_config_search_through (config, suffix, 1, 0) == 0)
return GRUB_ERR_NONE;
}
@ -1816,7 +1817,7 @@ grub_net_search_config_file (char *config)
if (*ptr == ':')
*ptr = '-';
if (search_through (1, 0) == 0)
if (grub_config_search_through (config, suffix, 1, 0) == 0)
return GRUB_ERR_NONE;
/* By IP address */
@ -1831,7 +1832,7 @@ grub_net_search_config_file (char *config)
((n >> 24) & 0xff), ((n >> 16) & 0xff), \
((n >> 8) & 0xff), ((n >> 0) & 0xff));
if (search_through (8, 1) == 0)
if (grub_config_search_through (config, suffix, 8, 1) == 0)
return GRUB_ERR_NONE;
break;
}
@ -1848,7 +1849,7 @@ grub_net_search_config_file (char *config)
*ptr = '-';
grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf);
if (search_through (1, 0) == 0)
if (grub_config_search_through (config, suffix, 1, 0) == 0)
return GRUB_ERR_NONE;
break;
}