mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/744>
This commit is contained in:
parent
d7b0b6b6db
commit
4a2d1d9c78
2 changed files with 12 additions and 56 deletions
|
@ -41,6 +41,7 @@
|
|||
#include "../../gst/gst-i18n-lib.h"
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdio.h> /* for fseeko() */
|
||||
#ifdef HAVE_STDIO_EXT_H
|
||||
#include <stdio_ext.h> /* 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)
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <glib/gstdio.h>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue