[vlc-commits] directory: Don't append a separator when it's not needed
Hugo Beauzée-Luyssen
git at videolan.org
Wed Feb 26 15:36:52 CET 2020
vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Feb 19 09:58:28 2020 +0100| [255800a23d1aa1bce8ecdf9984a04443d245f208] | committer: Hugo Beauzée-Luyssen
directory: Don't append a separator when it's not needed
(cherry picked from commit 97a471e6e387cd84a481e51ca5053e3986d9923e)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=255800a23d1aa1bce8ecdf9984a04443d245f208
---
modules/access/directory.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/modules/access/directory.c b/modules/access/directory.c
index 59915de767..b7500c1f6b 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -45,6 +45,7 @@
struct access_sys_t
{
char *base_uri;
+ bool need_separator;
DIR *dir;
};
@@ -68,6 +69,12 @@ int DirInit (stream_t *access, DIR *dir)
if (unlikely(sys->base_uri == NULL))
goto error;
+ char last_char = sys->base_uri[strlen(sys->base_uri) - 1];
+ sys->need_separator =
+#ifdef _WIN32
+ last_char != '\\' &&
+#endif
+ last_char != '/';
sys->dir = dir;
access->p_sys = sys;
@@ -173,7 +180,9 @@ int DirRead (stream_t *access, input_item_node_t *node)
}
char *uri;
- if (unlikely(asprintf(&uri, "%s/%s", sys->base_uri, encoded) == -1))
+ if (unlikely(asprintf(&uri, "%s%s%s", sys->base_uri,
+ sys->need_separator ? "/" : "",
+ encoded) == -1))
uri = NULL;
free(encoded);
if (unlikely(uri == NULL))
More information about the vlc-commits
mailing list