[vlc-commits] access_out_file: reorder to avoid forward declarations

Rémi Denis-Courmont git at videolan.org
Tue May 26 22:28:11 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue May 26 22:59:12 2015 +0300| [e7a4311db421cdc6f61114f24cc875cddf9de480] | committer: Rémi Denis-Courmont

access_out_file: reorder to avoid forward declarations

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e7a4311db421cdc6f61114f24cc875cddf9de480
---

 modules/access_output/file.c |  242 +++++++++++++++++++-----------------------
 1 file changed, 110 insertions(+), 132 deletions(-)

diff --git a/modules/access_output/file.c b/modules/access_output/file.c
index 846a0b3..080ef89 100644
--- a/modules/access_output/file.c
+++ b/modules/access_output/file.c
@@ -46,61 +46,98 @@
 #include <vlc_strings.h>
 #include <vlc_dialog.h>
 
-#if defined( _WIN32 ) || defined( __OS2__ )
-#   include <io.h>
-#endif
-
-#ifndef _WIN32
-#   include <unistd.h>
-#endif
-
 #ifndef O_LARGEFILE
 #   define O_LARGEFILE 0
 #endif
 
+#define SOUT_CFG_PREFIX "sout-file-"
+
 /*****************************************************************************
- * Module descriptor
+ * Read: standard read on a file descriptor.
  *****************************************************************************/
-static int  Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
+static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
+{
+    ssize_t val;
 
-#define SOUT_CFG_PREFIX "sout-file-"
-#define OVERWRITE_TEXT N_("Overwrite existing file")
-#define OVERWRITE_LONGTEXT N_( \
-    "If the file already exists, it will be overwritten.")
-#define APPEND_TEXT N_("Append to file")
-#define APPEND_LONGTEXT N_( "Append to file if it exists instead " \
-                            "of replacing it.")
-#define FORMAT_TEXT N_("Format time and date")
-#define FORMAT_LONGTEXT N_("Perform ISO C time and date formatting " \
-    "on the file path")
-#define SYNC_TEXT N_("Synchronous writing")
-#define SYNC_LONGTEXT N_( "Open the file with synchronous writing.")
+    do
+        val = read( (intptr_t)p_access->p_sys, p_buffer->p_buffer,
+                    p_buffer->i_buffer );
+    while (val == -1 && errno == EINTR);
+    return val;
+}
 
-vlc_module_begin ()
-    set_description( N_("File stream output") )
-    set_shortname( N_("File" ))
-    set_capability( "sout access", 50 )
-    set_category( CAT_SOUT )
-    set_subcategory( SUBCAT_SOUT_ACO )
-    add_shortcut( "file", "stream", "fd" )
-    add_bool( SOUT_CFG_PREFIX "overwrite", true, OVERWRITE_TEXT,
-              OVERWRITE_LONGTEXT, true )
-    add_bool( SOUT_CFG_PREFIX "append", false, APPEND_TEXT,APPEND_LONGTEXT,
-              true )
-    add_bool( SOUT_CFG_PREFIX "format", false, FORMAT_TEXT, FORMAT_LONGTEXT,
-              true )
-#ifdef O_SYNC
-    add_bool( SOUT_CFG_PREFIX "sync", false, SYNC_TEXT,SYNC_LONGTEXT,
-              false )
-#endif
-    set_callbacks( Open, Close )
-vlc_module_end ()
+/*****************************************************************************
+ * Write: standard write on a file descriptor.
+ *****************************************************************************/
+static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
+{
+    size_t i_write = 0;
+
+    while( p_buffer )
+    {
+        ssize_t val = write ((intptr_t)p_access->p_sys,
+                             p_buffer->p_buffer, p_buffer->i_buffer);
+        if (val <= 0)
+        {
+            if (errno == EINTR)
+                continue;
+            block_ChainRelease (p_buffer);
+            msg_Err( p_access, "cannot write: %s", vlc_strerror_c(errno) );
+            return -1;
+        }
 
+        if ((size_t)val >= p_buffer->i_buffer)
+        {
+            block_t *p_next = p_buffer->p_next;
+            block_Release (p_buffer);
+            p_buffer = p_next;
+        }
+        else
+        {
+            p_buffer->p_buffer += val;
+            p_buffer->i_buffer -= val;
+        }
+        i_write += val;
+    }
+    return i_write;
+}
 
 /*****************************************************************************
- * Exported prototypes
+ * Seek: seek to a specific location in a file
  *****************************************************************************/
+static int Seek( sout_access_out_t *p_access, off_t i_pos )
+{
+    return lseek( (intptr_t)p_access->p_sys, i_pos, SEEK_SET );
+}
+
+static int Control( sout_access_out_t *p_access, int i_query, va_list args )
+{
+    switch( i_query )
+    {
+        case ACCESS_OUT_CONTROLS_PACE:
+        {
+            bool *pb = va_arg( args, bool * );
+            *pb = strcmp( p_access->psz_access, "stream" );
+            break;
+        }
+
+        case ACCESS_OUT_CAN_SEEK:
+        {
+            bool *pb = va_arg( args, bool * );
+            struct stat st;
+            if( fstat( (intptr_t)p_access->p_sys, &st ) == -1 )
+                *pb = false;
+            else
+                *pb = S_ISREG( st.st_mode ) || S_ISBLK( st.st_mode );
+            break;
+        }
+
+        default:
+            return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
+
 static const char *const ppsz_sout_options[] = {
     "append",
     "format",
@@ -111,11 +148,6 @@ static const char *const ppsz_sout_options[] = {
     NULL
 };
 
-static ssize_t Write( sout_access_out_t *, block_t * );
-static int Seek ( sout_access_out_t *, off_t  );
-static ssize_t Read ( sout_access_out_t *, block_t * );
-static int Control( sout_access_out_t *, int, va_list );
-
 /*****************************************************************************
  * Open: open the file
  *****************************************************************************/
@@ -238,88 +270,34 @@ static void Close( vlc_object_t * p_this )
     msg_Dbg( p_access, "file access output closed" );
 }
 
-static int Control( sout_access_out_t *p_access, int i_query, va_list args )
-{
-    switch( i_query )
-    {
-        case ACCESS_OUT_CONTROLS_PACE:
-        {
-            bool *pb = va_arg( args, bool * );
-            *pb = strcmp( p_access->psz_access, "stream" );
-            break;
-        }
-
-        case ACCESS_OUT_CAN_SEEK:
-        {
-            bool *pb = va_arg( args, bool * );
-            struct stat st;
-            if( fstat( (intptr_t)p_access->p_sys, &st ) == -1 )
-                *pb = false;
-            else
-                *pb = S_ISREG( st.st_mode ) || S_ISBLK( st.st_mode );
-            break;
-        }
-
-        default:
-            return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Read: standard read on a file descriptor.
- *****************************************************************************/
-static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
-{
-    ssize_t val;
-
-    do
-        val = read( (intptr_t)p_access->p_sys, p_buffer->p_buffer,
-                    p_buffer->i_buffer );
-    while (val == -1 && errno == EINTR);
-    return val;
-}
-
-/*****************************************************************************
- * Write: standard write on a file descriptor.
- *****************************************************************************/
-static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
-{
-    size_t i_write = 0;
-
-    while( p_buffer )
-    {
-        ssize_t val = write ((intptr_t)p_access->p_sys,
-                             p_buffer->p_buffer, p_buffer->i_buffer);
-        if (val <= 0)
-        {
-            if (errno == EINTR)
-                continue;
-            block_ChainRelease (p_buffer);
-            msg_Err( p_access, "cannot write: %s", vlc_strerror_c(errno) );
-            return -1;
-        }
-
-        if ((size_t)val >= p_buffer->i_buffer)
-        {
-            block_t *p_next = p_buffer->p_next;
-            block_Release (p_buffer);
-            p_buffer = p_next;
-        }
-        else
-        {
-            p_buffer->p_buffer += val;
-            p_buffer->i_buffer -= val;
-        }
-        i_write += val;
-    }
-    return i_write;
-}
+#define OVERWRITE_TEXT N_("Overwrite existing file")
+#define OVERWRITE_LONGTEXT N_( \
+    "If the file already exists, it will be overwritten.")
+#define APPEND_TEXT N_("Append to file")
+#define APPEND_LONGTEXT N_( "Append to file if it exists instead " \
+                            "of replacing it.")
+#define FORMAT_TEXT N_("Format time and date")
+#define FORMAT_LONGTEXT N_("Perform ISO C time and date formatting " \
+    "on the file path")
+#define SYNC_TEXT N_("Synchronous writing")
+#define SYNC_LONGTEXT N_( "Open the file with synchronous writing.")
 
-/*****************************************************************************
- * Seek: seek to a specific location in a file
- *****************************************************************************/
-static int Seek( sout_access_out_t *p_access, off_t i_pos )
-{
-    return lseek( (intptr_t)p_access->p_sys, i_pos, SEEK_SET );
-}
+vlc_module_begin ()
+    set_description( N_("File stream output") )
+    set_shortname( N_("File" ))
+    set_capability( "sout access", 50 )
+    set_category( CAT_SOUT )
+    set_subcategory( SUBCAT_SOUT_ACO )
+    add_shortcut( "file", "stream", "fd" )
+    add_bool( SOUT_CFG_PREFIX "overwrite", true, OVERWRITE_TEXT,
+              OVERWRITE_LONGTEXT, true )
+    add_bool( SOUT_CFG_PREFIX "append", false, APPEND_TEXT,APPEND_LONGTEXT,
+              true )
+    add_bool( SOUT_CFG_PREFIX "format", false, FORMAT_TEXT, FORMAT_LONGTEXT,
+              true )
+#ifdef O_SYNC
+    add_bool( SOUT_CFG_PREFIX "sync", false, SYNC_TEXT,SYNC_LONGTEXT,
+              false )
+#endif
+    set_callbacks( Open, Close )
+vlc_module_end ()



More information about the vlc-commits mailing list