[vlc-devel] [PATCH v3 5/14] es_out_timeshift: refactor GetTmpFile()

Lyndon Brown jnqnfe at gmail.com
Wed Oct 14 04:53:30 CEST 2020


From: Lyndon Brown <jnqnfe at gmail.com>
Date: Mon, 5 Oct 2020 23:54:06 +0100
Subject: es_out_timeshift: refactor GetTmpFile()

to avoid duplicated logic, and to remove pointless fallback on default
path should asprintf call fail.

param names have been changed to ones that make better sense.

one further small functional change is that vlc_mkdir() is now used even
in the default directory case, when it was not before. (reviewer requested
recursive style for handling null directory param).

diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index 02735e807b..82aa2da137 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -322,7 +322,7 @@ static int  CmdExecuteControl( es_out_t *, ts_cmd_control_t * );
 static int  CmdExecutePrivControl( es_out_t *, ts_cmd_privcontrol_t * );
 
 /* File helpers */
-static int GetTmpFile( char **ppsz_file, const char *psz_path );
+static int GetTmpFile( char **path, const char *directory );
 
 static const struct es_out_callbacks es_out_timeshift_cbs;
 
@@ -1807,29 +1807,17 @@ static int CmdExecutePrivControl( es_out_t *p_tsout, ts_cmd_privcontrol_t *p_cmd
     }
 }
 
-static int GetTmpFile( char **filename, const char *dirname )
+static int GetTmpFile( char **path, const char *directory )
 {
-    if( dirname != NULL
-     && asprintf( filename, "%s"DIR_SEP PACKAGE_NAME"-timeshift.XXXXXX",
-                  dirname ) >= 0 )
-    {
-        vlc_mkdir( dirname, 0700 );
-
-        int fd = vlc_mkstemp( *filename );
-        if( fd != -1 )
-            return fd;
+    if (directory == NULL)
+        return GetTmpFile(path, DIR_SEP"tmp");
+    vlc_mkdir(directory, 0700);
 
-        free( *filename );
+    int fd = -1;
+    if (asprintf(path, "%s" DIR_SEP PACKAGE_NAME "-timeshift.XXXXXX", directory) >= 0) {
+        fd = vlc_mkstemp(*path);
+        if (fd == -1)
+            free(*path);
     }
-
-    *filename = strdup( DIR_SEP"tmp"DIR_SEP PACKAGE_NAME"-timeshift.XXXXXX" );
-    if( unlikely(*filename == NULL) )
-        return -1;
-
-    int fd = vlc_mkstemp( *filename );
-    if( fd != -1 )
-        return fd;
-
-    free( *filename );
-    return -1;
+    return fd;
 }



More information about the vlc-devel mailing list