]> git.sesse.net Git - vlc/blobdiff - modules/access_output/file.c
modules: use the new add_shortcut capability (add multiple shortcuts at a time).
[vlc] / modules / access_output / file.c
index 6a3cd86d7a7d95873ef64794799fee37da4a8937..91ae8636690cc11a0e1c7c6b687d38f513cc1317 100644 (file)
@@ -31,7 +31,6 @@
 #endif
 
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <time.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -40,8 +39,8 @@
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
-#include <vlc_charset.h>
-#include "vlc_strings.h"
+#include <vlc_fs.h>
+#include <vlc_strings.h>
 
 #if defined( WIN32 ) && !defined( UNDER_CE )
 #   include <io.h>
@@ -64,6 +63,8 @@ static void Close( vlc_object_t * );
 #define APPEND_TEXT N_("Append to file")
 #define APPEND_LONGTEXT N_( "Append to file if it exists instead " \
                             "of replacing it.")
+#define SYNC_TEXT N_("Synchronous writing")
+#define SYNC_LONGTEXT N_( "Open the file with synchronous writing.")
 
 vlc_module_begin ()
     set_description( N_("File stream output") )
@@ -71,10 +72,11 @@ vlc_module_begin ()
     set_capability( "sout access", 50 )
     set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_ACO )
-    add_shortcut( "file" )
-    add_shortcut( "stream" )
-    add_bool( SOUT_CFG_PREFIX "append", 0, NULL, APPEND_TEXT,APPEND_LONGTEXT,
+    add_shortcut( "file", "stream" )
+    add_bool( SOUT_CFG_PREFIX "append", false, NULL, APPEND_TEXT,APPEND_LONGTEXT,
               true )
+    add_bool( SOUT_CFG_PREFIX "sync", false, NULL, SYNC_TEXT,SYNC_LONGTEXT,
+              false )
     set_callbacks( Open, Close )
 vlc_module_end ()
 
@@ -83,7 +85,7 @@ vlc_module_end ()
  * Exported prototypes
  *****************************************************************************/
 static const char *const ppsz_sout_options[] = {
-    "append", NULL
+    "append", "sync", NULL
 };
 
 static ssize_t Write( sout_access_out_t *, block_t * );
@@ -103,6 +105,7 @@ static int Open( vlc_object_t *p_this )
 {
     sout_access_out_t   *p_access = (sout_access_out_t*)p_this;
     int                 fd;
+    bool                sync;
 
     config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
 
@@ -113,6 +116,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     bool append = var_GetBool( p_access, SOUT_CFG_PREFIX "append" );
+    sync = var_GetBool( p_access, SOUT_CFG_PREFIX "sync" );
 
     if( !strcmp( p_access->psz_path, "-" ) )
     {
@@ -120,10 +124,11 @@ static int Open( vlc_object_t *p_this )
 #ifdef WIN32
         setmode (fileno (stdout), O_BINARY);
 #endif
-        fd = dup (fileno (stdout));
+        fd = vlc_dup (fileno (stdout));
         msg_Dbg( p_access, "using stdout" );
 #else
 #warning stdout is not supported on Windows Mobile, but may be used on Windows CE
+        fd = -1;
 #endif
     }
     else
@@ -131,7 +136,10 @@ static int Open( vlc_object_t *p_this )
         char *psz_tmp = str_format( p_access, p_access->psz_path );
         path_sanitize( psz_tmp );
 
-        fd = utf8_open( psz_tmp, O_RDWR | O_CREAT | O_LARGEFILE |
+        fd = vlc_open( psz_tmp, O_RDWR | O_CREAT | O_LARGEFILE |
+#ifdef O_SYNC
+                        (sync ? O_SYNC : 0) |
+#endif
                         (append ? 0 : O_TRUNC), 0666 );
         free( psz_tmp );
     }