[vlc-devel] [PATCH 2/5] item: add input_stat2type

Thomas Guillem thomas at gllm.fr
Thu Nov 5 12:09:09 CET 2015


---
 include/vlc_input_item.h   |  3 +++
 modules/access/directory.c | 16 +++++-----------
 src/input/item.c           | 31 +++++++++++++++++++++++++++++++
 src/libvlccore.sym         |  1 +
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index f86c405..fc7f3f0 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -113,6 +113,9 @@ enum input_item_type_e
     ITEM_TYPE_NUMBER
 };
 
+struct stat;
+VLC_API enum input_item_type_e input_stat2type( struct stat *st, bool * );
+
 typedef int (*input_item_compar_cb)( input_item_t *, input_item_t * );
 
 struct input_item_node_t
diff --git a/modules/access/directory.c b/modules/access/directory.c
index 9b16b16..2e27ce9 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -127,17 +127,11 @@ input_item_t* DirRead (access_t *p_access)
         if (fstatat (dirfd (p_sys->p_dir), entry, &st, 0))
             continue;
 
-        switch (st.st_mode & S_IFMT)
-        {
-            case S_IFBLK: type = ITEM_TYPE_DISC;      break;
-            case S_IFCHR: type = ITEM_TYPE_CARD;      break;
-            case S_IFIFO: type = ITEM_TYPE_STREAM;    break;
-            case S_IFREG: type = ITEM_TYPE_FILE;      break;
-            case S_IFDIR: type = ITEM_TYPE_DIRECTORY; break;
-            /* S_IFLNK cannot occur while following symbolic links */
-            /* S_IFSOCK cannot be opened with open()/openat() */
-            default:      continue; /* ignore */
-        }
+        bool net;
+        type = input_stat2type (&st, &net);
+        if (type == ITEM_TYPE_UNKNOWN || net)
+            /* net streams cannot be opened with open()/openat() */
+            continue;
 #else
         type = ITEM_TYPE_FILE;
 #endif
diff --git a/src/input/item.c b/src/input/item.c
index 3248a84..9b93c6b 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -26,6 +26,9 @@
 #endif
 #include <assert.h>
 #include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include <vlc_common.h>
 #include <vlc_url.h>
@@ -1250,3 +1253,31 @@ void input_item_UpdateTracksInfo(input_item_t *item, const es_format_t *fmt)
     TAB_APPEND(item->i_es, item->es, fmt_copy);
     vlc_mutex_unlock( &item->lock );
 }
+
+/**
+ * Get an input item type from a valid struct stat
+ *
+ * \param st a valid struct stat
+ * \param net out argument: true if the file is remote
+ * \return an input item.type (ITEM_TYPE_UNKNOWN if stat is unknown)
+ */
+enum input_item_type_e input_stat2type( struct stat *st, bool *net )
+{
+    if( net )
+       *net = false;
+
+    switch( st->st_mode & S_IFMT )
+    {
+        case S_IFBLK: return ITEM_TYPE_DISC;
+        case S_IFCHR: return ITEM_TYPE_CARD;
+        case S_IFIFO: return ITEM_TYPE_STREAM;
+        case S_IFREG: return ITEM_TYPE_FILE;
+        case S_IFDIR: return ITEM_TYPE_DIRECTORY;
+#ifdef S_IFSOCK
+        case S_IFSOCK:
+            if( net ) *net = true;
+            return ITEM_TYPE_STREAM;
+#endif
+        default: return ITEM_TYPE_UNKNOWN;
+    }
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 204b5d5..c121a94 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -229,6 +229,7 @@ input_resource_GetAout
 input_resource_HoldAout
 input_resource_PutAout
 input_resource_ResetAout
+input_stat2type
 input_Start
 input_Stop
 input_vaControl
-- 
2.1.4



More information about the vlc-devel mailing list