]> git.sesse.net Git - vlc/blobdiff - modules/access/mtp.c
demux: xspf: default psz_base to the XSPF resource location (fixes #6186, #12058)
[vlc] / modules / access / mtp.c
index bbbbf4d1e396f809e8b7c66dadbc5b6ac203fda7..b38e16ee24dc2a0b5616b79fcb861d82475181c3 100644 (file)
@@ -1,26 +1,26 @@
 /*****************************************************************************
  * mtp.c: mtp input (mtp: access plug-in)
  *****************************************************************************
- * Copyright (C) 2001-2006 the VideoLAN team
+ * Copyright (C) 2001-2006 VLC authors and VideoLAN
  * Copyright © 2006-2008 Rémi Denis-Courmont
  *
  * Authors: Fabio Ritrovato <exsephiroth87@gmail.com>
  * Original file.c: Christophe Massiot <massiot@via.ecp.fr>
  *                  Rémi Denis-Courmont <rem # videolan # org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -36,7 +36,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <poll.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -76,7 +75,6 @@ static int  open_file( access_t *, const char * );
 
 struct access_sys_t
 {
-    unsigned int i_nb_reads;
     int fd;
 };
 
@@ -142,7 +140,6 @@ static int Open( vlc_object_t *p_this )
     free( p_rawdevices );
 
     STANDARD_READ_ACCESS_INIT;
-    p_sys->i_nb_reads = 0;
     int fd = p_sys->fd = -1;
 
     /* Open file */
@@ -156,11 +153,6 @@ static int Open( vlc_object_t *p_this )
     }
     p_sys->fd = fd;
 
-    struct stat st;
-    if( fstat( fd, &st ) )
-        msg_Err( p_access, "fstat(%d): %m", fd );
-    p_access->info.i_size = st.st_size;
-
     return VLC_SUCCESS;
 }
 
@@ -174,8 +166,8 @@ static void Close( vlc_object_t * p_this )
 
     close ( p_sys->fd );
     if(        vlc_unlink( p_access->psz_filepath ) != 0 )
-        msg_Err( p_access, "Error deleting file %s, %m",
-                 p_access->psz_filepath );
+        msg_Err( p_access, "Error deleting file %s, %s",
+                 p_access->psz_filepath, vlc_strerror_c(errno) );
     free( p_sys );
 }
 
@@ -199,9 +191,10 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
                 break;
 
             default:
-                msg_Err( p_access, "read failed (%m)" );
-                dialog_Fatal( p_access, _( "File reading failed" ), "%s (%m)",
-                                _( "VLC could not read the file." ) );
+                msg_Err( p_access, "read failed: %s", vlc_strerror_c(errno) );
+                dialog_Fatal( p_access, _( "File reading failed" ),
+                              _( "VLC could not read the file: %s" ),
+                              vlc_strerror(errno) );
                 p_access->info.b_eof = true;
                 return 0;
         }
@@ -211,8 +204,6 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
     else
         p_access->info.b_eof = true;
 
-    p_sys->i_nb_reads++;
-
     return i_ret;
 }
 
@@ -225,7 +216,8 @@ static int Seek( access_t *p_access, uint64_t i_pos )
     p_access->info.i_pos = i_pos;
     p_access->info.b_eof = false;
 
-    lseek( p_access->p_sys->fd, i_pos, SEEK_SET );
+    if (lseek( p_access->p_sys->fd, i_pos, SEEK_SET ) == (off_t)-1)
+        return VLC_EGENERIC;
     return VLC_SUCCESS;
 }
 
@@ -234,12 +226,12 @@ static int Seek( access_t *p_access, uint64_t i_pos )
  *****************************************************************************/
 static int Control( access_t *p_access, int i_query, va_list args )
 {
+    access_sys_t *sys = p_access->p_sys;
     bool   *pb_bool;
     int64_t      *pi_64;
 
     switch( i_query )
     {
-        /* */
         case ACCESS_CAN_SEEK:
         case ACCESS_CAN_FASTSEEK:
             pb_bool = ( bool* )va_arg( args, bool* );
@@ -252,28 +244,30 @@ static int Control( access_t *p_access, int i_query, va_list args )
             *pb_bool = true;
             break;
 
+        case ACCESS_GET_SIZE:
+        {
+            uint64_t *s = va_arg( args, uint64_t * );
+            struct stat st;
+            if( fstat( sys->fd, &st ) )
+            {
+                msg_Err( p_access, "fstat error: %s", vlc_strerror_c(errno) );
+                return VLC_EGENERIC;
+            }
+            *s = st.st_size;
+            break;
+        }
+
         case ACCESS_GET_PTS_DELAY:
             pi_64 = ( int64_t* )va_arg( args, int64_t * );
             *pi_64 = INT64_C(1000)
                    * var_InheritInteger( p_access, "file-caching" );
             break;
 
-        /* */
         case ACCESS_SET_PAUSE_STATE:
             /* Nothing to do */
             break;
 
-        case ACCESS_GET_TITLE_INFO:
-        case ACCESS_SET_TITLE:
-        case ACCESS_SET_SEEKPOINT:
-        case ACCESS_SET_PRIVATE_ID_STATE:
-        case ACCESS_GET_META:
-        case ACCESS_GET_PRIVATE_ID_STATE:
-        case ACCESS_GET_CONTENT_TYPE:
-            return VLC_EGENERIC;
-
         default:
-            msg_Warn( p_access, "unimplemented query %d in control", i_query );
             return VLC_EGENERIC;
 
     }
@@ -288,24 +282,18 @@ static int open_file( access_t *p_access, const char *path )
     int fd = vlc_open( path, O_RDONLY | O_NONBLOCK );
     if( fd == -1 )
     {
-        msg_Err( p_access, "cannot open file %s (%m)", path );
+        msg_Err( p_access, "cannot open file %s: %s", path,
+                 vlc_strerror_c(errno) );
         dialog_Fatal( p_access, _( "File reading failed" ),
-                        _( "VLC could not open the file \"%s\". (%m)" ), path );
+                      _( "VLC could not open the file \"%s\": %s" ), path,
+                      vlc_strerror(errno) );
         return -1;
     }
-
-#if defined( HAVE_FCNTL )
-    fcntl( fd, F_SETFD, fcntl( fd, F_GETFD ) | FD_CLOEXEC );
-
-    /* We'd rather use any available memory for reading ahead
-     * than for caching what we've already seen/heard */
-# if defined( F_RDAHEAD )
+#ifdef F_RDAHEAD
     fcntl( fd, F_RDAHEAD, 1 );
-# endif
-# if defined( F_NOCACHE )
-    fcntl( fd, F_NOCACHE, 1 );
-# endif
 #endif
-
+#ifdef F_NOCACHE
+    fcntl( fd, F_NOCACHE, 0 );
+#endif
     return fd;
 }