diff --git a/lib/fs.h b/lib/fs.h index 40d29f4a3..bb4c705dc 100644 --- a/lib/fs.h +++ b/lib/fs.h @@ -98,9 +98,6 @@ #define MC_MAXPATHLEN MAXPATHLEN #endif -/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */ -#define NLENGTH(dirent) (strlen ((dirent)->d_name)) - /* DragonFlyBSD doesn't provide MAXNAMLEN macro */ #ifndef MAXNAMLEN #define MAXNAMLEN NAME_MAX diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index 8469bdae6..971de94bb 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -481,7 +481,7 @@ mc_readdir (DIR * dirp) #ifdef HAVE_CHARSET str_vfs_convert_from (vfs_path_element->dir.converter, entry->d_name, vfs_str_buffer); #else - g_string_assign (vfs_str_buffer, entry->d_name); + g_string_append_len (vfs_str_buffer, entry->d_name, entry->d_len); #endif vfs_dirent_assign (mc_readdir_result, vfs_str_buffer->str, entry->d_ino); vfs_dirent_free (entry); diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 18d15ed35..c6ffd9448 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -565,6 +565,7 @@ vfs_dirent_assign (struct vfs_dirent *d, const char *fname, ino_t ino) { g_string_assign (d->d_name_str, fname); d->d_name = d->d_name_str->str; + d->d_len = d->d_name_str->len; d->d_ino = ino; } diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index 260e8f337..0a55c98bb 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -214,6 +214,7 @@ struct vfs_dirent /* public */ ino_t d_ino; char *d_name; /* Alias of d_name_str->str */ + size_t d_len; /* Alias of d_name_str->len */ }; /*** global variables defined in .c file *********************************************************/ diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index eeeba50d7..34847de23 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -212,9 +212,8 @@ filename_completion_function (const char *text, int state, input_complete_t flag { /* Otherwise, if these match up to the length of filename, then it may be a match. */ - if ((entry->d_name[0] != filename[0]) || - ((NLENGTH (entry)) < filename_len) || - strncmp (filename, entry->d_name, filename_len) != 0) + if (entry->d_name[0] != filename[0] || entry->d_len < filename_len + || strncmp (filename, entry->d_name, filename_len) != 0) continue; } @@ -291,7 +290,7 @@ filename_completion_function (const char *text, int state, input_complete_t flag if (!IS_PATH_SEP (temp->str[temp->len - 1])) g_string_append_c (temp, PATH_SEP); } - g_string_append (temp, entry->d_name); + g_string_append_len (temp, entry->d_name, entry->d_len); if (isdir) g_string_append_c (temp, PATH_SEP); diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index b405131b1..d3be210d5 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -159,7 +159,7 @@ handle_dirent (struct vfs_dirent *dp, const file_filter_t * filter, struct stat return FALSE; if (!panels_options.show_dot_files && (dp->d_name[0] == '.')) return FALSE; - if (!panels_options.show_backups && dp->d_name[strlen (dp->d_name) - 1] == '~') + if (!panels_options.show_backups && dp->d_name[dp->d_len - 1] == '~') return FALSE; vpath = vfs_path_from_str (dp->d_name); @@ -186,7 +186,7 @@ handle_dirent (struct vfs_dirent *dp, const file_filter_t * filter, struct stat gboolean files_only = (filter->flags & SELECT_FILES_ONLY) != 0; ok = ((S_ISDIR (buf1->st_mode) || *link_to_dir) && files_only) - || mc_search_run (filter->handler, dp->d_name, 0, strlen (dp->d_name), NULL); + || mc_search_run (filter->handler, dp->d_name, 0, dp->d_len, NULL); } return ok; diff --git a/src/filemanager/find.c b/src/filemanager/find.c index dbe23fcf0..2f6527a34 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1188,11 +1188,11 @@ search_content (WDialog * h, const char *directory, const char *filename) If dir is relative, this means we're going to add dir to the directory stack. **/ static gboolean -find_ignore_dir_search (const char *dir) +find_ignore_dir_search (const char *dir, size_t len) { if (find_ignore_dirs != NULL) { - const size_t dlen = strlen (dir); + const size_t dlen = len == (size_t) (-1) ? strlen (dir) : len; const unsigned char dabs = g_path_is_absolute (dir) ? 1 : 0; char **ignore_dir; @@ -1337,7 +1337,7 @@ do_search (WDialog * h) pop_start_dir = FALSE; /* handle absolute ignore dirs here */ - if (!find_ignore_dir_search (vfs_path_as_str (tmp_vpath))) + if (!find_ignore_dir_search (vfs_path_as_str (tmp_vpath), -1)) break; vfs_path_free (tmp_vpath, TRUE); @@ -1380,7 +1380,7 @@ do_search (WDialog * h) if (options.find_recurs && (directory != NULL)) { /* Can directory be NULL ? */ /* handle relative ignore dirs here */ - if (options.ignore_dirs_enable && find_ignore_dir_search (dp->d_name)) + if (options.ignore_dirs_enable && find_ignore_dir_search (dp->d_name, dp->d_len)) ignore_count++; else { @@ -1401,8 +1401,8 @@ do_search (WDialog * h) } } - search_ok = mc_search_run (search_file_handle, dp->d_name, - 0, strlen (dp->d_name), &bytes_found); + search_ok = + mc_search_run (search_file_handle, dp->d_name, 0, dp->d_len, &bytes_found); if (search_ok) {