diff --git a/src/autocomplete.c b/src/autocomplete.c index b21bdf9..9354baf 100644 --- a/src/autocomplete.c +++ b/src/autocomplete.c @@ -273,7 +273,8 @@ int dir_match(ToxWindow *self, Tox *m, wchar_t *line) int dircount = 0; while ((entry = readdir(dp)) && dircount < MAX_DIRS) { - if (strncmp(entry->d_name, b_name, b_name_len) == 0) { + if (strncmp(entry->d_name, b_name, b_name_len) == 0 + && strcmp(".", entry->d_name) && strcmp("..", entry->d_name)) { snprintf(dirnames[dircount], sizeof(dirnames[dircount]), "%s", entry->d_name); ++dircount; } @@ -282,8 +283,10 @@ int dir_match(ToxWindow *self, Tox *m, wchar_t *line) if (dircount == 0) return -1; - if (dircount > 1) + if (dircount > 1) { + qsort(dirnames, dircount, NAME_MAX, qsort_strcasecmp_hlpr); print_matches(self, m, dirnames, dircount, NAME_MAX); + } return complete_line(self, dirnames, dircount, NAME_MAX); } diff --git a/src/misc_tools.c b/src/misc_tools.c index 9d31c61..36bd140 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -143,9 +143,9 @@ int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n) } /* case-insensitive string compare function for use with qsort */ -int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2) +int qsort_strcasecmp_hlpr(const void *str1, const void *str2) { - return strcasecmp((const char *) nick1, (const char *) nick2); + return strcasecmp((const char *) str1, (const char *) str2); } /* Returns 1 if nick is valid, 0 if not. A valid toxic nick: diff --git a/src/misc_tools.h b/src/misc_tools.h index 37894de..bea928b 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -70,7 +70,7 @@ int timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); void alert_window(ToxWindow *self, int type, bool is_beep); /* case-insensitive string compare function for use with qsort */ -int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2); +int qsort_strcasecmp_hlpr(const void *str1, const void *str2); /* Returns 1 if nick is valid, 0 if not. A valid toxic nick: - cannot be empty