plugins/elements/gstfilesrc.c: Use 64 bit variants of stat functions on win32, to...
authorAlessandro Decina <alessandro@nnva.org>
Tue, 19 Aug 2008 17:23:18 +0000 (17:23 +0000)
committerMichael Smith <msmith@xiph.org>
Tue, 19 Aug 2008 17:23:18 +0000 (17:23 +0000)
Original commit message from CVS:
Patch by: Alessandro Decina <alessandro@nnva.org>
* plugins/elements/gstfilesrc.c:
Use 64 bit variants of stat functions on win32, to enable support
of large files there.
Fixes #547277.

ChangeLog
plugins/elements/gstfilesrc.c

index 18a2e39..0287fe4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-08-19  Michael Smith <msmith@songbirdnest.com>
+
+       Patch by: Alessandro Decina <alessandro@nnva.org>
+       * plugins/elements/gstfilesrc.c:
+         Use 64 bit variants of stat functions on win32, to enable support
+         of large files there.
+         Fixes #547277.
+
 2008-08-19  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * libs/gst/base/gstbasesink.c: (gst_base_sink_render_object),
index a01e610..cf3d5aa 100644 (file)
 
 #include <stdio.h>
 #include <sys/types.h>
+#ifdef G_OS_WIN32
+#include <io.h>                 /* lseek, open, close, read */
+/* On win32, stat* default to 32 bit; we need the 64-bit
+ * variants, so explicitly define it that way. */
+#define stat __stat64
+#define fstat _fstat64
+#undef lseek
+#define lseek _lseeki64
+#undef off_t
+#define off_t guint64
+/* Prevent stat.h from defining the stat* functions as
+ * _stat*, since we're explicitly overriding that */
+#undef _INC_STAT_INL
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 
 # include <sys/mman.h>
 #endif
 
-#ifdef HAVE_WIN32
-#  include <io.h>               /* lseek, open, close, read */
-#endif
-
 #include <errno.h>
 #include <string.h>
 
@@ -74,6 +84,34 @@ 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. */
+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;
+#else
+  return open (filename, flags, mode);
+#endif
+}
+
 
 /**********************************************************************
  * GStreamer Default File Source
@@ -909,7 +947,7 @@ gst_file_src_start (GstBaseSrc * basesrc)
   GST_INFO_OBJECT (src, "opening file %s", src->filename);
 
   /* open the file */
-  src->fd = open (src->filename, O_RDONLY | O_BINARY);
+  src->fd = gst_open (src->filename, O_RDONLY | O_BINARY, 0);
 
   if (src->fd < 0)
     goto open_failed;
@@ -1086,6 +1124,7 @@ gst_file_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
     return TRUE;
   } else {
     location = gst_uri_get_location (uri);
+    GST_LOG_OBJECT (src, "Location '%s' found from uri '%s'", location, uri);
   }
 
   if (!location)