]> git.sesse.net Git - vlc/blobdiff - modules/access/vcd/cdrom.c
avio: remove interrupt callback for output
[vlc] / modules / access / vcd / cdrom.c
index dfab30375269bda4ef8bc88f7fbc82a588610cfa..a4a8bd438dd7335b1a506e826da180e3141cc763 100644 (file)
 #   define INCL_DOSDEVIOCTL
 #endif
 
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
 #include <sys/types.h>
+#include <unistd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#ifdef HAVE_ARPA_INET_H
-#   include <arpa/inet.h>
-#endif
+#include <limits.h>
 
 #include <vlc_common.h>
 #include <vlc_access.h>
 #include <vlc_charset.h>
 #include <vlc_fs.h>
-#include <limits.h>
+#include <vlc_meta.h>
 
 #if defined( SYS_BSDI )
 #   include <dvd.h>
 #elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H )
 #   include <sys/cdio.h>
 #   include <sys/cdrio.h>
-#elif defined( WIN32 )
+#elif defined( _WIN32 )
 #   include <windows.h>
 #   include <winioctl.h>
 #elif defined (__linux__)
 #   include <sys/ioctl.h>
 #   include <linux/cdrom.h>
 #elif defined( __OS2__ )
+#   include <os2safe.h>
 #   include <os2.h>
+
+/*****************************************************************************
+ * vlc_DosDevIOCtl: high memory safe wrapper for DosDevIOCtl
+ *****************************************************************************
+ * Unfortunately, DosDevIOCtl() is not high memory safe API, and is not
+ * covered by os2safe.h. So define a wrapper function for it here.
+ *****************************************************************************/
+
+static APIRET vlc_DosDevIOCtl( HFILE hdevice, ULONG category, ULONG function,
+                               PVOID pParams, ULONG cbParamLenMax,
+                               PULONG pcbParamLen, PVOID pData,
+                               ULONG cbDataLenMax, PULONG pcbDataLen )
+{
+    PVOID pParamsLow = NULL;
+    PVOID pDataLow = NULL;
+    ULONG cbParamLenLow;
+    ULONG cbDataLenLow;
+
+    APIRET rc;
+
+    rc = DosAllocMem( &pParamsLow, cbParamLenMax, fALLOC );
+    if( rc )
+        goto exit_free;
+
+    rc = DosAllocMem( &pDataLow, cbDataLenMax, fALLOC );
+    if( rc )
+        goto exit_free;
+
+    memcpy( pParamsLow, pParams, cbParamLenMax );
+    memcpy( pDataLow, pData, cbDataLenMax );
+
+    cbParamLenLow = *pcbParamLen;
+    cbDataLenLow  = *pcbDataLen;
+
+    rc = DosDevIOCtl( hdevice, category, function, pParamsLow,
+                      cbParamLenMax, &cbParamLenLow, pDataLow, cbDataLenMax,
+                      &cbDataLenLow );
+
+    if( !rc )
+    {
+        memcpy( pParams, pParamsLow, cbParamLenMax );
+        memcpy( pData, pDataLow, cbDataLenMax );
+
+        *pcbParamLen = cbParamLenLow;
+        *pcbDataLen  = cbDataLenLow;
+    }
+
+exit_free:
+    DosFreeMem( pParamsLow);
+    DosFreeMem( pDataLow);
+
+    return rc;
+}
+
+#   define DosDevIOCtl vlc_DosDevIOCtl
 #else
 #   error FIXME
 #endif
 
 #include "cdrom_internals.h"
 #include "cdrom.h"
-#include <vlc_meta.h>
 
 /*****************************************************************************
  * ioctl_Open: Opens a VCD device or file and returns an opaque handle
@@ -97,7 +148,7 @@ vcddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev )
     int i_ret;
     int b_is_file;
     vcddev_t *p_vcddev;
-#if !defined( WIN32 ) && !defined( __OS2__ )
+#if !defined( _WIN32 ) && !defined( __OS2__ )
     struct stat fileinfo;
 #endif
 
@@ -116,7 +167,7 @@ vcddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev )
     /*
      *  Check if we are dealing with a device or a file (vcd image)
      */
-#if defined( WIN32 ) || defined( __OS2__ )
+#if defined( _WIN32 ) || defined( __OS2__ )
     if( (strlen( psz_dev ) == 2 && psz_dev[1] == ':') )
     {
         b_is_file = 0;
@@ -144,7 +195,7 @@ vcddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev )
          *  open the vcd device
          */
 
-#ifdef WIN32
+#ifdef _WIN32
         i_ret = win32_vcd_open( p_this, psz_dev, p_vcddev );
 #elif defined( __OS2__ )
         i_ret = os2_vcd_open( p_this, psz_dev, p_vcddev );
@@ -189,7 +240,7 @@ void ioctl_Close( vlc_object_t * p_this, vcddev_t *p_vcddev )
      *  vcd device mode
      */
 
-#ifdef WIN32
+#ifdef _WIN32
     if( p_vcddev->h_device_handle )
         CloseHandle( p_vcddev->h_device_handle );
 #elif defined( __OS2__ )
@@ -296,7 +347,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev,
 
         darwin_freeTOC( pTOC );
 
-#elif defined( WIN32 )
+#elif defined( _WIN32 )
         DWORD dwBytesReturned;
         CDROM_TOC cdrom_toc;
 
@@ -547,7 +598,7 @@ int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
             goto error;
         }
 
-#elif defined( WIN32 )
+#elif defined( _WIN32 )
         DWORD dwBytesReturned;
         RAW_READ_INFO cdrom_raw;
 
@@ -728,30 +779,33 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev,
     {
         /* psz_dev must be the cue file. Let's assume there's a .bin
          * file with the same filename */
-        psz_vcdfile = malloc( p_pos - psz_dev + 5 /* ".bin" */ );
-        strncpy( psz_vcdfile, psz_dev, p_pos - psz_dev );
-        strcpy( psz_vcdfile + (p_pos - psz_dev), ".bin");
+        if( asprintf( &psz_vcdfile, "%.*s.bin", (int)(p_pos - psz_dev),
+                      psz_dev ) < 0 )
+            psz_vcdfile = NULL;
         psz_cuefile = strdup( psz_dev );
     }
     else
+    if( p_pos )
     {
         /* psz_dev must be the actual vcd file. Let's assume there's a .cue
          * file with the same filename */
-        if( p_pos )
-        {
-            psz_cuefile = malloc( p_pos - psz_dev + 5 /* ".cue" */ );
-            strncpy( psz_cuefile, psz_dev, p_pos - psz_dev );
-            strcpy( psz_cuefile + (p_pos - psz_dev), ".cue");
-        }
-        else
-        {
-            if( asprintf( &psz_cuefile, "%s.cue", psz_dev ) == -1 )
-                psz_cuefile = NULL;
-        }
-        /* If we need to look up the .cue file, then we don't have to look for the vcd */
+        if( asprintf( &psz_cuefile, "%.*s.cue", (int)(p_pos - psz_dev),
+                      psz_dev ) < 0 )
+            psz_cuefile = NULL;
+        psz_vcdfile = strdup( psz_dev );
+    }
+    else
+    {
+        if( asprintf( &psz_cuefile, "%s.cue", psz_dev ) == -1 )
+            psz_cuefile = NULL;
+         /* If we need to look up the .cue file, then we don't have to look
+          * for the vcd */
         psz_vcdfile = strdup( psz_dev );
     }
 
+    if( psz_cuefile == NULL || psz_vcdfile == NULL )
+        goto error;
+
     /* Open the cue file and try to parse it */
     msg_Dbg( p_this,"trying .cue file: %s", psz_cuefile );
     cuefile = vlc_fopen( psz_cuefile, "rt" );
@@ -764,7 +818,7 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev,
     msg_Dbg( p_this,"guessing vcd image file: %s", psz_vcdfile );
     p_vcddev->i_vcdimage_handle = vlc_open( psz_vcdfile,
                                     O_RDONLY | O_NONBLOCK | O_BINARY );
+
     while( fgets( line, 1024, cuefile ) && !b_found )
     {
         /* We have a cue file, but no valid vcd file yet */
@@ -998,7 +1052,7 @@ static int darwin_getNumberOfTracks( CDTOC *pTOC, int i_descriptors )
 }
 #endif /* __APPLE__ */
 
-#if defined( WIN32 )
+#if defined( _WIN32 )
 /*****************************************************************************
  * win32_vcd_open: open vcd drive
  *****************************************************************************
@@ -1016,7 +1070,7 @@ static int win32_vcd_open( vlc_object_t * p_this, const char *psz_dev,
 
     sprintf( psz_win32_drive, "\\\\.\\%c:", psz_dev[0] );
 
-    p_vcddev->h_device_handle = CreateFile( psz_win32_drive, GENERIC_READ,
+    p_vcddev->h_device_handle = CreateFileA( psz_win32_drive, GENERIC_READ,
                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
                                             NULL, OPEN_EXISTING,
                                             FILE_FLAG_NO_BUFFERING |
@@ -1024,7 +1078,7 @@ static int win32_vcd_open( vlc_object_t * p_this, const char *psz_dev,
     return (p_vcddev->h_device_handle == NULL) ? -1 : 0;
 }
 
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 #ifdef __OS2__
 /*****************************************************************************
@@ -1217,7 +1271,7 @@ static int CdTextRead( vlc_object_t *p_object, const vcddev_t *p_vcddev,
     VLC_UNUSED( pi_buffer );
     return -1;
 }
-#elif defined( WIN32 )
+#elif defined( _WIN32 )
 static int CdTextRead( vlc_object_t *p_object, const vcddev_t *p_vcddev,
                        uint8_t **pp_buffer, int *pi_buffer )
 {