[MPlayer-cygwin] DVD startup mingw vs cygwin

Gianluigi Tiesi mplayer at netfarm.it
Sat Jan 29 10:46:15 CET 2005


Sorry I'm dumb, .. mingw off_t is dumb... 4 byte instead of 8,
as Sasha said long long is enough, anyway after changes types.h of
mingw, try this patch for seeking.

-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/stream_file.c sherpya/libmpdemux/stream_file.c
--- main/libmpdemux/stream_file.c	2005-01-29 07:16:51.802006400 +0100
+++ sherpya/libmpdemux/stream_file.c	2005-01-29 07:18:15.762736000 +0100
@@ -1,4 +1,6 @@
-
+#ifdef __MINGW32__
+#include <windows.h>
+#endif
 #include "config.h"
 
 #include <sys/types.h>
@@ -32,18 +34,41 @@
 };  
 
 static int fill_buffer(stream_t *s, char* buffer, int max_len){
+#ifdef __MINGW32__
+  int r;
+  if(ReadFile((HANDLE) s->fd, buffer, max_len, (LPDWORD) &r, NULL))
+    return r;
+   else
+    return -1;
+#else
   int r = read(s->fd,buffer,max_len);
+#endif
   return (r <= 0) ? -1 : r;
 }
 
 static int write_buffer(stream_t *s, char* buffer, int len) {
+#ifdef __MINGW32__
+  int r;
+  if(WriteFile((HANDLE) s->fd, buffer, len, (LPDWORD) &r, NULL))
+    return r;
+   else
+    return -1;
+#else    
   int r = write(s->fd,buffer,len);
   return (r <= 0) ? -1 : r;
+#endif
 }
 
 static int seek(stream_t *s,off_t newpos) {
   s->pos = newpos;
+#ifdef __MINGW32__
+  LARGE_INTEGER li_seek;
+  li_seek.QuadPart = (LONGLONG) newpos;
+  li_seek.LowPart = SetFilePointer((HANDLE) s->fd, li_seek.LowPart, &li_seek.HighPart, FILE_BEGIN);
+  if((li_seek.LowPart == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) {
+#else
   if(lseek(s->fd,s->pos,SEEK_SET)<0) {
+#endif
     s->eof=1;
     return 0;
   }
@@ -65,6 +90,13 @@
   return 1;
 }
 
+#ifdef __MINGW32__
+static void file_close(stream_t* s) {
+    CloseHandle((HANDLE) s->fd);
+    s->fd = 0;
+}
+#endif
+
 static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
   int f;
   mode_t m = 0;
@@ -107,18 +139,28 @@
 #endif
     }
   } else {
+#ifdef __MINGW32__
+    f = (int) CreateFile(p->filename, (mode == STREAM_READ) ? GENERIC_READ : GENERIC_WRITE,
+               FILE_SHARE_READ | FILE_SHARE_WRITE,
+               NULL, OPEN_EXISTING,
+               FILE_FLAG_SEQUENTIAL_SCAN, NULL);
+    if(f == (int) INVALID_HANDLE_VALUE) {
+#else
     f=open(p->filename,m);
     if(f<0) {
+#endif
       mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,p->filename);
       m_struct_free(&stream_opts,opts);
       return STREAM_ERROR;
     }
   }
-
-  len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
 #ifdef __MINGW32__
-  if(f==0 || len == -1) {
+  LARGE_INTEGER l;
+  l.LowPart = GetFileSize((HANDLE) f, (LPDWORD)&l.HighPart);
+  len = l.QuadPart;
+  if ((l.LowPart == INVALID_FILE_SIZE) && (GetLastError() != NO_ERROR)) {
 #else
+  len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
   if(len == -1) {
 #endif
     stream->seek = seek_forward;
@@ -139,7 +181,9 @@
   stream->fd = f;
   stream->fill_buffer = fill_buffer;
   stream->write_buffer = write_buffer;
-
+#ifdef __MINGW32__
+  stream->close = file_close;
+#endif
   m_struct_free(&stream_opts,opts);
   return STREAM_OK;
 }


More information about the MPlayer-cygwin mailing list