Skip to content

Commit

Permalink
[utils] Add mono_path_filename_in_basedir
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdageek authored and marek-safar committed Aug 7, 2018
1 parent efe65c3 commit 5d3dd64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mono/utils/mono-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,27 @@ mono_path_resolve_symlinks (const char *path)
#endif
}

/**
* mono_path_filename_in_basedir:
*
* Return \c TRUE if \p filename is in \p basedir
*
* Both paths must be absolute and using \c G_DIR_SEPARATOR for directory separators.
* If the file is in a subdirectory of \p basedir, returns \c FALSE.
* This function doesn't touch a filesystem, it looks solely at path names.
*/
gboolean
mono_path_filename_in_basedir (const char *filename, const char *basedir)
{
char *p = NULL;
if ((p = strstr (filename, basedir))) {
p += strlen (basedir);
if (*p != G_DIR_SEPARATOR)
return FALSE;
/* if it's in a subdir of the basedir, it doesn't count. */
if (strchr (p, G_DIR_SEPARATOR))
return FALSE;
return TRUE;
}
return FALSE;
}
1 change: 1 addition & 0 deletions mono/utils/mono-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

MONO_API gchar *mono_path_resolve_symlinks (const char *path);
MONO_API gchar *mono_path_canonicalize (const char *path);
gboolean mono_path_filename_in_basedir (const char *filename, const char *basedir);

#endif /* __MONO_PATH_H */

0 comments on commit 5d3dd64

Please sign in to comment.