File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -177,3 +177,27 @@ mono_path_resolve_symlinks (const char *path)
177177#endif
178178}
179179
180+ /**
181+ * mono_path_filename_in_basedir:
182+ *
183+ * Return \c TRUE if \p filename is in \p basedir
184+ *
185+ * Both paths must be absolute and using \c G_DIR_SEPARATOR for directory separators.
186+ * If the file is in a subdirectory of \p basedir, returns \c FALSE.
187+ * This function doesn't touch a filesystem, it looks solely at path names.
188+ */
189+ gboolean
190+ mono_path_filename_in_basedir (const char * filename , const char * basedir )
191+ {
192+ char * p = NULL ;
193+ if ((p = strstr (filename , basedir ))) {
194+ p += strlen (basedir );
195+ if (* p != G_DIR_SEPARATOR )
196+ return FALSE;
197+ /* if it's in a subdir of the basedir, it doesn't count. */
198+ if (strchr (p , G_DIR_SEPARATOR ))
199+ return FALSE;
200+ return TRUE;
201+ }
202+ return FALSE;
203+ }
Original file line number Diff line number Diff line change 1010
1111MONO_API gchar * mono_path_resolve_symlinks (const char * path );
1212MONO_API gchar * mono_path_canonicalize (const char * path );
13+ gboolean mono_path_filename_in_basedir (const char * filename , const char * basedir );
1314
1415#endif /* __MONO_PATH_H */
1516
You can’t perform that action at this time.
0 commit comments