diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2011-02-23 16:18:09 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2011-02-26 16:40:31 +0200 |
commit | 962eec0440ad65a71c09a9e206e110c62d9de3c8 (patch) | |
tree | 7e1f2b9406fa34859dfe67de8d4ea6b80bc09408 /osdep | |
parent | e8af22db818f839f5ac25a309e8838ea53e831b2 (diff) | |
download | mpv-962eec0440ad65a71c09a9e206e110c62d9de3c8.tar.bz2 mpv-962eec0440ad65a71c09a9e206e110c62d9de3c8.tar.xz |
bstr.[ch], path.[ch]: add string and path handling functions
Add some new string and path handling functions to be used in
following commits.
Use new path handling functions to simplify find_files().
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/findfiles.c | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/osdep/findfiles.c b/osdep/findfiles.c index 879f6d5c98..e35174dfd4 100644 --- a/osdep/findfiles.c +++ b/osdep/findfiles.c @@ -22,38 +22,18 @@ #include <assert.h> #include "talloc.h" - -#if defined(__MINGW32__) || defined(__CYGWIN__) -static const char dir_separators[] = "/\\:"; -#else -static const char dir_separators[] = "/"; -#endif +#include "path.h" +#include "bstr.h" char **find_files(const char *original_file, const char *suffix, int *num_results_ptr) { void *tmpmem = talloc_new(NULL); - char *fname = talloc_strdup(tmpmem, original_file); - char *basename = NULL; - char *next = fname; - while (1) { - next = strpbrk(next, dir_separators); - if (!next) - break; - basename = next++; - } - char *directory; - if (basename) { - directory = fname; - *basename++ = 0; - } else { - directory = "."; - basename = fname; - } - - + char *basename = mp_basename(original_file); + struct bstr directory = mp_dirname(original_file); char **results = talloc_size(NULL, 0); - DIR *dp = opendir(directory); + char *dir_zero = bstrdup0(tmpmem, directory); + DIR *dp = opendir(dir_zero); struct dirent *ep; char ***names_by_matchlen = talloc_array(tmpmem, char **, strlen(basename) + 1); @@ -68,7 +48,7 @@ char **find_files(const char *original_file, const char *suffix, if (!strcmp(ep->d_name, basename)) continue; - char *name = talloc_asprintf(results, "%s/%s", directory, ep->d_name); + char *name = mp_path_join(results, directory, BSTR(ep->d_name)); char *s1 = ep->d_name; char *s2 = basename; int matchlen = 0; |