From 4a2d1d9c78580f247a35c217f9dc3fe077cd5a38 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 29 Jan 2021 23:07:34 +0900 Subject: [PATCH] filesrc/filesink: Use g_open/g_fopen and g_close instead of ours There should be no more cross-CRT issue on Windows since we bumped MinGW toolchain Part-of: --- plugins/elements/gstfilesink.c | 29 +++++-------------------- plugins/elements/gstfilesrc.c | 39 ++++++---------------------------- 2 files changed, 12 insertions(+), 56 deletions(-) diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index 1caa2373a5..ce0fba328a 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -41,6 +41,7 @@ #include "../../gst/gst-i18n-lib.h" #include +#include #include /* for fseeko() */ #ifdef HAVE_STDIO_EXT_H #include /* for __fbufsize, for debugging */ @@ -131,35 +132,15 @@ gst_fopen (const gchar * filename, const gchar * mode, gboolean o_sync) { FILE *retval; #ifdef G_OS_WIN32 - wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); - wchar_t *wmode; - int save_errno; - - if (wfilename == NULL) { - errno = EINVAL; - return NULL; - } - - wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL); - - if (wmode == NULL) { - g_free (wfilename); - errno = EINVAL; - return NULL; - } - - retval = _wfopen (wfilename, wmode); - save_errno = errno; - - g_free (wfilename); - g_free (wmode); - - errno = save_errno; + retval = g_fopen (filename, mode); return retval; #else int fd; int flags = O_CREAT | O_WRONLY; + /* NOTE: below code is for handing spurious EACCES return on write + * See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/143 + */ if (strcmp (mode, "wb") == 0) flags |= O_TRUNC; else if (strcmp (mode, "ab") == 0) diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index bcd58d8c6a..62ffb202f4 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -38,6 +38,7 @@ #endif #include +#include #include "gstfilesrc.h" #include "gstcoreelementselements.h" @@ -98,36 +99,6 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", #define O_BINARY (0) #endif -/* Copy of glib's g_open due to win32 libc/cross-DLL brokenness: we can't - * use the 'file descriptor' opened in glib (and returned from this function) - * in this library, as they may have unrelated C runtimes. */ -static int -gst_open (const gchar * filename, int flags, int mode) -{ -#ifdef G_OS_WIN32 - wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); - int retval; - int save_errno; - - if (wfilename == NULL) { - errno = EINVAL; - return -1; - } - - retval = _wopen (wfilename, flags, mode); - save_errno = errno; - - g_free (wfilename); - - errno = save_errno; - return retval; -#elif defined (__BIONIC__) - return open (filename, flags | O_LARGEFILE, mode); -#else - return open (filename, flags, mode); -#endif -} - GST_DEBUG_CATEGORY_STATIC (gst_file_src_debug); #define GST_CAT_DEFAULT gst_file_src_debug @@ -483,6 +454,10 @@ static gboolean gst_file_src_start (GstBaseSrc * basesrc) { GstFileSrc *src = GST_FILE_SRC (basesrc); + int flags = O_RDONLY | O_BINARY; +#if defined (__BIONIC__) + flags |= O_LARGEFILE; +#endif if (src->filename == NULL || src->filename[0] == '\0') goto no_filename; @@ -490,7 +465,7 @@ gst_file_src_start (GstBaseSrc * basesrc) GST_INFO_OBJECT (src, "opening file %s", src->filename); /* open the file */ - src->fd = gst_open (src->filename, O_RDONLY | O_BINARY, 0); + src->fd = g_open (src->filename, flags, 0); if (src->fd < 0) goto open_failed; @@ -626,7 +601,7 @@ gst_file_src_stop (GstBaseSrc * basesrc) GstFileSrc *src = GST_FILE_SRC (basesrc); /* close the file */ - close (src->fd); + g_close (src->fd, NULL); /* zero out a lot of our state */ src->fd = 0;