diff --git a/main/gui_selectfile.c b/main/gui_selectfile.c index b1ddcf9..0eda4a6 100644 --- a/main/gui_selectfile.c +++ b/main/gui_selectfile.c @@ -1,4 +1,4 @@ -/* $Id: gui_selectfile.c,v 1.3 2014/02/12 21:23:06 steffen Exp $ */ +/* $Id: gui_selectfile.c,v 1.4 2014/02/12 23:05:35 steffen Exp $ */ /*************************************************************************** * gui_selectdir.c * @@ -143,33 +143,33 @@ void gui_sfile_update () { continue; } d_printf ("dir:%s", fname); - if (S_ISDIR(stbuf.st_mode)) { - /* need more memory? */ - if (cnt >= wsf_listmax) { - /* save old pointer and counter */ - char **tmp = wsf_list; - int i = wsf_listmax-1; - - /* allocate new list */ - wsf_listmax += 512; - wsf_list = ml_malloc (wsf_listmax * sizeof(void*)); - memset (wsf_list, 0x0, wsf_listmax * sizeof(void*)); - - /* copy list */ - if (tmp) { - for (; i >= 0; i--) wsf_list[i] = tmp[i]; - ml_free (tmp); - } - - /* setup new list */ - GUI_LIST_T (wsf_flist)->data = wsf_list; + if (cnt >= wsf_listmax) { + /* save old pointer and counter */ + char **tmp = wsf_list; + int i = wsf_listmax-1; + + /* allocate new list */ + wsf_listmax += 512; + wsf_list = ml_malloc (wsf_listmax * sizeof(void*)); + memset (wsf_list, 0x0, wsf_listmax * sizeof(void*)); + + /* copy list */ + if (tmp) { + for (; i >= 0; i--) wsf_list[i] = tmp[i]; + ml_free (tmp); } - - wsf_list[cnt] = ml_malloc (LEN_FILENAME); - strncpy (wsf_list[cnt], direntry->d_name, LEN_FILENAME); - d_printf ("added entry:%-3d '%s'", cnt, direntry->d_name); - cnt++; + /* setup new list */ + GUI_LIST_T (wsf_flist)->data = wsf_list; } + + wsf_list[cnt] = ml_malloc (LEN_FILENAME); + + if (S_ISDIR(stbuf.st_mode)) snprintf (wsf_list[cnt], LEN_FILENAME, "[%s]", direntry->d_name); + else snprintf (wsf_list[cnt], LEN_FILENAME, "%s", direntry->d_name); + + d_printf ("added entry:%-3d '%s'", cnt, direntry->d_name); + cnt++; + } closedir (dir);