Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
3ab943c4
Commit
3ab943c4
authored
7 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: condense some logic, to elide a variable and a comment
parent
ec20e3a7
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/files.c
+11
-21
src/files.c
with
11 additions
and
21 deletions
+11
-21
src/files.c
View file @
3ab943c4
...
...
@@ -1420,17 +1420,16 @@ void init_operating_dir(void)
snuggly_fit
(
&
operating_dir
);
}
/* Check
to see if we're in
side the operating directory.
Return FALSE
*
if we are, or TRU
E otherwise. If allow_tabcomp is TRUE,
allow
* incomplete names that
would be
matches for the operating directory
,
* so that tab completion will work. */
/* Check
whether the given path is out
side
of
the operating directory.
*
Return TRUE if it is, and FALS
E otherwise. If allow_tabcomp is TRUE,
* incomplete names that
can grow into
matches for the operating directory
*
are considered to be inside,
so that tab completion will work. */
bool
outside_of_confinement
(
const
char
*
currpath
,
bool
allow_tabcomp
)
{
char
*
fullpath
;
bool
retval
=
FALSE
;
const
char
*
whereami1
,
*
whereami2
=
NULL
;
bool
is_inside
,
begins_to_be
;
/* If no operating directory is set,
don't bother doing anything
. */
/* If no operating directory is set,
there is nothing to check
. */
if
(
operating_dir
==
NULL
)
return
FALSE
;
...
...
@@ -1441,26 +1440,17 @@ bool outside_of_confinement(const char *currpath, bool allow_tabcomp)
* is what the user typed somewhere. We don't want to report a
* non-existent directory as being outside the operating directory,
* so we return FALSE. If allow_tabcomp is TRUE, then currpath
* exists, but is not executable. So we say it is
n't in
the
* exists, but is not executable. So we say it is
outside
the
* operating directory. */
if
(
fullpath
==
NULL
)
return
allow_tabcomp
;
whereami1
=
strstr
(
fullpath
,
operating_dir
);
if
(
allow_tabcomp
)
whereami2
=
strstr
(
operating_dir
,
fullpath
);
/* If both searches failed, we're outside the operating directory.
* Otherwise, check the search results. If the full operating
* directory path is not at the beginning of the full current path
* (for normal usage) and vice versa (for tab completion, if we're
* allowing it), we're outside the operating directory. */
if
(
whereami1
!=
fullpath
&&
whereami2
!=
operating_dir
)
retval
=
TRUE
;
is_inside
=
(
strstr
(
fullpath
,
operating_dir
)
==
fullpath
);
begins_to_be
=
(
allow_tabcomp
&&
strstr
(
operating_dir
,
fullpath
)
==
operating_dir
);
free
(
fullpath
);
/* Otherwise, we're still inside it. */
return
retval
;
return
(
!
is_inside
&&
!
begins_to_be
);
}
#endif
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help