* grub-core/fs/fshelp.c: Remove variable length arrays.

Reduces fshelp.mod by 116 bytes (23 compressed).
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-20 15:38:37 +02:00
parent c7037f1d0f
commit 3b502c29a1
2 changed files with 25 additions and 35 deletions

View file

@ -1,3 +1,8 @@
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/fshelp.c: Remove variable length arrays.
Reduces fshelp.mod by 116 bytes (23 compressed).
2013-10-20 Vladimir Serbinenko <phcoder@gmail.com> 2013-10-20 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/completion.c: Remove variable length arrays. * grub-core/normal/completion.c: Remove variable length arrays.

View file

@ -39,7 +39,8 @@ struct grub_fshelp_find_file_ctx
grub_fshelp_node_t rootnode, currroot, currnode, oldnode; grub_fshelp_node_t rootnode, currroot, currnode, oldnode;
enum grub_fshelp_filetype foundtype; enum grub_fshelp_filetype foundtype;
int symlinknest; int symlinknest;
char *name; const char *name;
const char *next;
enum grub_fshelp_filetype type; enum grub_fshelp_filetype type;
}; };
@ -59,9 +60,10 @@ find_file_iter (const char *filename, enum grub_fshelp_filetype filetype,
struct grub_fshelp_find_file_ctx *ctx = data; struct grub_fshelp_find_file_ctx *ctx = data;
if (filetype == GRUB_FSHELP_UNKNOWN || if (filetype == GRUB_FSHELP_UNKNOWN ||
(grub_strcmp (ctx->name, filename) && ((filetype & GRUB_FSHELP_CASE_INSENSITIVE)
(! (filetype & GRUB_FSHELP_CASE_INSENSITIVE) || ? grub_strncasecmp (ctx->name, filename, ctx->next - ctx->name)
grub_strcasecmp (ctx->name, filename)))) : grub_strncmp (ctx->name, filename, ctx->next - ctx->name))
|| filename[ctx->next - ctx->name])
{ {
grub_free (node); grub_free (node);
return 0; return 0;
@ -81,40 +83,31 @@ find_file (const char *currpath, grub_fshelp_node_t currroot,
iterate_dir_func iterate_dir, read_symlink_func read_symlink, iterate_dir_func iterate_dir, read_symlink_func read_symlink,
struct grub_fshelp_find_file_ctx *ctx) struct grub_fshelp_find_file_ctx *ctx)
{ {
char fpath[grub_strlen (currpath) + 1];
char *next;
ctx->currroot = currroot; ctx->currroot = currroot;
ctx->name = fpath; ctx->name = currpath;
ctx->type = GRUB_FSHELP_DIR; ctx->type = GRUB_FSHELP_DIR;
ctx->currnode = currroot; ctx->currnode = currroot;
ctx->oldnode = currroot; ctx->oldnode = currroot;
grub_strncpy (fpath, currpath, grub_strlen (currpath) + 1);
/* Remove all leading slashes. */
while (*ctx->name == '/')
ctx->name++;
if (! *ctx->name)
{
*currfound = ctx->currnode;
return 0;
}
for (;;) for (;;)
{ {
int found; int found;
/* Extract the actual part from the pathname. */ /* Remove all leading slashes. */
next = grub_strchr (ctx->name, '/'); while (*ctx->name == '/')
if (next) ctx->name++;
/* Found the node! */
if (! *ctx->name)
{ {
/* Remove all leading slashes. */ *currfound = ctx->currnode;
while (*next == '/') ctx->foundtype = ctx->type;
*(next++) = '\0'; return 0;
} }
/* Extract the actual part from the pathname. */
for (ctx->next = ctx->name; *ctx->next && *ctx->next != '/'; ctx->next++);
/* At this point it is expected that the current node is a /* At this point it is expected that the current node is a
directory, check if this is true. */ directory, check if this is true. */
if (ctx->type != GRUB_FSHELP_DIR) if (ctx->type != GRUB_FSHELP_DIR)
@ -190,15 +183,7 @@ find_file (const char *currpath, grub_fshelp_node_t currroot,
ctx->oldnode = 0; ctx->oldnode = 0;
} }
/* Found the node! */ ctx->name = ctx->next;
if (! next || *next == '\0')
{
*currfound = ctx->currnode;
ctx->foundtype = ctx->type;
return 0;
}
ctx->name = next;
} }
return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"), return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file `%s' not found"),