mirror of https://github.com/MidnightCommander/mc
vfs_dirent: add new member d_len to get rid of d_name length calculation.
* (vfs_dirent_assign): set d_len up. * (mc_readdir): sync with new vfs_dirent: use d_len member. * (filename_completion_function): likewise. * (handle_dirent): likewise. * (find_ignore_dir_search): add 2nd argument to use length of directory name if it's known. * (do_search): sync with modified vfs_dirent and find_ignore_dir_search(). * (NLENGTH): remove. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
f4183ed2f2
commit
ab3e3339bb
3
lib/fs.h
3
lib/fs.h
|
@ -98,9 +98,6 @@
|
||||||
#define MC_MAXPATHLEN MAXPATHLEN
|
#define MC_MAXPATHLEN MAXPATHLEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
|
|
||||||
#define NLENGTH(dirent) (strlen ((dirent)->d_name))
|
|
||||||
|
|
||||||
/* DragonFlyBSD doesn't provide MAXNAMLEN macro */
|
/* DragonFlyBSD doesn't provide MAXNAMLEN macro */
|
||||||
#ifndef MAXNAMLEN
|
#ifndef MAXNAMLEN
|
||||||
#define MAXNAMLEN NAME_MAX
|
#define MAXNAMLEN NAME_MAX
|
||||||
|
|
|
@ -481,7 +481,7 @@ mc_readdir (DIR * dirp)
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
str_vfs_convert_from (vfs_path_element->dir.converter, entry->d_name, vfs_str_buffer);
|
str_vfs_convert_from (vfs_path_element->dir.converter, entry->d_name, vfs_str_buffer);
|
||||||
#else
|
#else
|
||||||
g_string_assign (vfs_str_buffer, entry->d_name);
|
g_string_append_len (vfs_str_buffer, entry->d_name, entry->d_len);
|
||||||
#endif
|
#endif
|
||||||
vfs_dirent_assign (mc_readdir_result, vfs_str_buffer->str, entry->d_ino);
|
vfs_dirent_assign (mc_readdir_result, vfs_str_buffer->str, entry->d_ino);
|
||||||
vfs_dirent_free (entry);
|
vfs_dirent_free (entry);
|
||||||
|
|
|
@ -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);
|
g_string_assign (d->d_name_str, fname);
|
||||||
d->d_name = d->d_name_str->str;
|
d->d_name = d->d_name_str->str;
|
||||||
|
d->d_len = d->d_name_str->len;
|
||||||
d->d_ino = ino;
|
d->d_ino = ino;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,7 @@ struct vfs_dirent
|
||||||
/* public */
|
/* public */
|
||||||
ino_t d_ino;
|
ino_t d_ino;
|
||||||
char *d_name; /* Alias of d_name_str->str */
|
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 *********************************************************/
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
|
@ -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
|
/* Otherwise, if these match up to the length of filename, then
|
||||||
it may be a match. */
|
it may be a match. */
|
||||||
if ((entry->d_name[0] != filename[0]) ||
|
if (entry->d_name[0] != filename[0] || entry->d_len < filename_len
|
||||||
((NLENGTH (entry)) < filename_len) ||
|
|| strncmp (filename, entry->d_name, filename_len) != 0)
|
||||||
strncmp (filename, entry->d_name, filename_len) != 0)
|
|
||||||
continue;
|
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]))
|
if (!IS_PATH_SEP (temp->str[temp->len - 1]))
|
||||||
g_string_append_c (temp, PATH_SEP);
|
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)
|
if (isdir)
|
||||||
g_string_append_c (temp, PATH_SEP);
|
g_string_append_c (temp, PATH_SEP);
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ handle_dirent (struct vfs_dirent *dp, const file_filter_t * filter, struct stat
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
|
if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
|
||||||
return FALSE;
|
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;
|
return FALSE;
|
||||||
|
|
||||||
vpath = vfs_path_from_str (dp->d_name);
|
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;
|
gboolean files_only = (filter->flags & SELECT_FILES_ONLY) != 0;
|
||||||
|
|
||||||
ok = ((S_ISDIR (buf1->st_mode) || *link_to_dir) && files_only)
|
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;
|
return ok;
|
||||||
|
|
|
@ -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.
|
If dir is relative, this means we're going to add dir to the directory stack.
|
||||||
**/
|
**/
|
||||||
static gboolean
|
static gboolean
|
||||||
find_ignore_dir_search (const char *dir)
|
find_ignore_dir_search (const char *dir, size_t len)
|
||||||
{
|
{
|
||||||
if (find_ignore_dirs != NULL)
|
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;
|
const unsigned char dabs = g_path_is_absolute (dir) ? 1 : 0;
|
||||||
|
|
||||||
char **ignore_dir;
|
char **ignore_dir;
|
||||||
|
@ -1337,7 +1337,7 @@ do_search (WDialog * h)
|
||||||
pop_start_dir = FALSE;
|
pop_start_dir = FALSE;
|
||||||
|
|
||||||
/* handle absolute ignore dirs here */
|
/* 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;
|
break;
|
||||||
|
|
||||||
vfs_path_free (tmp_vpath, TRUE);
|
vfs_path_free (tmp_vpath, TRUE);
|
||||||
|
@ -1380,7 +1380,7 @@ do_search (WDialog * h)
|
||||||
if (options.find_recurs && (directory != NULL))
|
if (options.find_recurs && (directory != NULL))
|
||||||
{ /* Can directory be NULL ? */
|
{ /* Can directory be NULL ? */
|
||||||
/* handle relative ignore dirs here */
|
/* 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++;
|
ignore_count++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1401,8 +1401,8 @@ do_search (WDialog * h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
search_ok = mc_search_run (search_file_handle, dp->d_name,
|
search_ok =
|
||||||
0, strlen (dp->d_name), &bytes_found);
|
mc_search_run (search_file_handle, dp->d_name, 0, dp->d_len, &bytes_found);
|
||||||
|
|
||||||
if (search_ok)
|
if (search_ok)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue