vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Wed Sep 7 14:03:53 2016 +0300| [7888a18c93e15253fa70566ed825c0785f06ab5b] | committer: Rémi Denis-Courmont
vlc_uri_fixup: use vlc_memstream (fixes #17347) > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7888a18c93e15253fa70566ed825c0785f06ab5b --- src/text/url.c | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/text/url.c b/src/text/url.c index b500475..909d1a7 100644 --- a/src/text/url.c +++ b/src/text/url.c @@ -31,9 +31,6 @@ #ifdef _WIN32 # include <io.h> #endif -#ifndef HAVE_OPEN_MEMSTREAM -# define open_memstream(b,l) (*(b) = NULL, *(l) = 0, NULL) -#endif #include <vlc_common.h> #include <vlc_memstream.h> @@ -612,17 +609,17 @@ static char *vlc_uri_remove_dot_segments(char *str) char *vlc_uri_compose(const vlc_url_t *uri) { - struct vlc_memstream stream[1]; + struct vlc_memstream stream; char *enc; - vlc_memstream_open(stream); + vlc_memstream_open(&stream); if (uri->psz_protocol != NULL) - vlc_memstream_printf(stream, "%s:", uri->psz_protocol); + vlc_memstream_printf(&stream, "%s:", uri->psz_protocol); if (uri->psz_host != NULL) { - vlc_memstream_write(stream, "//", 2); + vlc_memstream_write(&stream, "//", 2); if (uri->psz_username != NULL) { @@ -630,7 +627,7 @@ char *vlc_uri_compose(const vlc_url_t *uri) if (enc == NULL) goto error; - vlc_memstream_puts(stream, enc); + vlc_memstream_puts(&stream, enc); free(enc); if (uri->psz_password != NULL) @@ -639,10 +636,10 @@ char *vlc_uri_compose(const vlc_url_t *uri) if (unlikely(enc == NULL)) goto error; - vlc_memstream_printf(stream, ":%s", enc); + vlc_memstream_printf(&stream, ":%s", enc); free(enc); } - vlc_memstream_putc(stream, '@'); + vlc_memstream_putc(&stream, '@'); } const char *fmt; @@ -652,22 +649,22 @@ char *vlc_uri_compose(const vlc_url_t *uri) else fmt = (uri->i_port != 0) ? "%s:%d" : "%s"; /* No IDNA decoding here. Seems unnecessary, dangerous even. */ - vlc_memstream_printf(stream, fmt, uri->psz_host, uri->i_port); + vlc_memstream_printf(&stream, fmt, uri->psz_host, uri->i_port); } if (uri->psz_path != NULL) - vlc_memstream_puts(stream, uri->psz_path); + vlc_memstream_puts(&stream, uri->psz_path); if (uri->psz_option != NULL) - vlc_memstream_printf(stream, "?%s", uri->psz_option); + vlc_memstream_printf(&stream, "?%s", uri->psz_option); /* NOTE: fragment not handled currently */ - if (vlc_memstream_close(stream)) + if (vlc_memstream_close(&stream)) return NULL; - return stream->ptr; + return stream.ptr; error: - if (vlc_memstream_close(stream) == 0) - free(stream->ptr); + if (vlc_memstream_close(&stream) == 0) + free(stream.ptr); return NULL; } @@ -745,11 +742,9 @@ char *vlc_uri_fixup(const char *str) break; } - char *buf; - size_t len; - FILE *stream = open_memstream(&buf, &len); - if (stream == NULL) - return NULL; + struct vlc_memstream stream; + + vlc_memstream_open(&stream); for (size_t i = 0; str[i] != '\0'; i++) { @@ -757,14 +752,14 @@ char *vlc_uri_fixup(const char *str) if (isurisafe(c) || isurisubdelim(c) || (strchr(":/?#[]@", c) != NULL) || (c == '%' && !encode_percent)) - fputc(c, stream); + vlc_memstream_putc(&stream, c); else - fprintf(stream, "%%%02hhX", c); + vlc_memstream_printf(&stream, "%%%02hhX", c); } - if (fclose(stream)) - buf = NULL; - return buf; + if (vlc_memstream_close(&stream)) + return NULL; + return stream.ptr; } #if defined (HAVE_IDN) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
