[vlc-devel] [PATCH v3 1/14] core: add config_GetTempPath()
Lyndon Brown
jnqnfe at gmail.com
Wed Oct 14 04:51:47 CEST 2020
From: Lyndon Brown <jnqnfe at gmail.com>
Date: Mon, 5 Oct 2020 20:16:48 +0100
Subject: core: add config_GetTempPath()
to provide a common interface to the system/user temporary directory.
we will make use of this with vlc_mkstemp().
this has not been implemented into config_GetSysPath() or
config_GetUserDir() because it may return a system path in some cases
and a user path in others, so it does not perfectly fit either.
diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index c6075c334a..02249048a5 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -320,6 +320,13 @@ typedef enum vlc_user_dir
VLC_API char * config_GetUserDir( vlc_userdir_t ) VLC_USED VLC_MALLOC;
+/**
+ * Gets system/user temp directory.
+ *
+ * @return a heap-allocated string (use free() to release it), or NULL on error
+ */
+VLC_API char *config_GetTempPath(void) VLC_USED VLC_MALLOC;
+
VLC_API void config_AddIntf(const char *);
VLC_API void config_RemoveIntf(const char *);
VLC_API bool config_ExistIntf(const char *) VLC_USED;
diff --git a/src/darwin/dirs.m b/src/darwin/dirs.m
index 3a300a5824..1c27b68370 100644
--- a/src/darwin/dirs.m
+++ b/src/darwin/dirs.m
@@ -230,3 +230,9 @@ char *config_GetUserDir (vlc_userdir_t type)
free(psz_parent);
return psz_dir;
}
+
+char *config_GetTempPath(void)
+{
+ char *dir = getenv("TMPDIR");
+ return strdup((dir != NULL) ? dir : "/tmp");
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index cd47af0a2e..0a64954a4b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -60,6 +60,7 @@ config_ExistIntf
config_FindConfig
config_GetFloat
config_GetSysPath
+config_GetTempPath
config_GetUserDir
config_GetInt
config_GetIntChoices
diff --git a/src/os2/dirs.c b/src/os2/dirs.c
index 350067472c..152e1ec673 100644
--- a/src/os2/dirs.c
+++ b/src/os2/dirs.c
@@ -177,3 +177,11 @@ char *config_GetUserDir (vlc_userdir_t type)
}
return config_GetHomeDir ();
}
+
+char *config_GetTempPath(void)
+{
+ const char *dir = getenv("TEMP");
+ if (dir != NULL)
+ return FromLocaleDup(dir);
+ return NULL;
+}
diff --git a/src/posix/dirs.c b/src/posix/dirs.c
index d6acdb47dc..c4456edc73 100644
--- a/src/posix/dirs.c
+++ b/src/posix/dirs.c
@@ -297,3 +297,9 @@ char *config_GetUserDir (vlc_userdir_t type)
}
return config_GetHomeDir ();
}
+
+char *config_GetTempPath(void)
+{
+ char *dir = getenv("TMPDIR");
+ return strdup((dir != NULL) ? dir : "/tmp");
+}
diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
index e1c7506961..9bf07fdba5 100644
--- a/src/win32/dirs-uap.c
+++ b/src/win32/dirs-uap.c
@@ -304,3 +304,13 @@ char *config_GetUserDir (vlc_userdir_t type)
vlc_assert_unreachable ();
}
}
+
+char *config_GetTempPath(void)
+{
+ wchar_t wdir[MAX_PATH + 1];
+
+ DWORD len = GetTempPathW(MAX_PATH + 1, wdir);
+ if (len != 0 && len <= MAX_PATH)
+ return FromWide(wdir);
+ return NULL;
+}
diff --git a/src/win32/dirs.c b/src/win32/dirs.c
index 7c39e391c2..7e3516bc8a 100644
--- a/src/win32/dirs.c
+++ b/src/win32/dirs.c
@@ -168,3 +168,13 @@ char *config_GetUserDir (vlc_userdir_t type)
}
vlc_assert_unreachable ();
}
+
+char *config_GetTempPath(void)
+{
+ wchar_t wdir[MAX_PATH + 1];
+
+ DWORD len = GetTempPathW(MAX_PATH + 1, wdir);
+ if (len != 0 && len <= MAX_PATH)
+ return FromWide(wdir);
+ return NULL;
+}
More information about the vlc-devel
mailing list