[vlc-devel] [PATCH v2 1/13] core: add config_GetTempPath()
Steve Lhomme
robux4 at ycbcr.xyz
Tue Oct 6 08:55:37 CEST 2020
On 2020-10-06 7:56, Lyndon Brown wrote:
> 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 mkstemp().
>
> 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..74e2183b7a 100644
> --- a/src/darwin/dirs.m
> +++ b/src/darwin/dirs.m
> @@ -230,3 +230,8 @@ char *config_GetUserDir (vlc_userdir_t type)
> free(psz_parent);
> return psz_dir;
> }
> +
> +char *config_GetTempPath(void)
> +{
> + return strdup("/tmp");
> +}
> diff --git a/src/libvlccore.sym b/src/libvlccore.sym
> index bd00a9b74a..028891b3c9 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..995be9b3ce 100644
> --- a/src/posix/dirs.c
> +++ b/src/posix/dirs.c
> @@ -297,3 +297,8 @@ char *config_GetUserDir (vlc_userdir_t type)
> }
> return config_GetHomeDir ();
> }
> +
> +char *config_GetTempPath(void)
> +{
> + return strdup("/tmp");
I'm no expert in POSIX but hardcoding a value like that doesn't seem
right (same for the other platforms).
> +}
> diff --git a/src/win32/dirs-uap.c b/src/win32/dirs-uap.c
> index e1c7506961..a27bd6eeb9 100644
> --- a/src/win32/dirs-uap.c
> +++ b/src/win32/dirs-uap.c
> @@ -304,3 +304,9 @@ char *config_GetUserDir (vlc_userdir_t type)
> vlc_assert_unreachable ();
> }
> }
> +
> +char *config_GetTempPath(void)
> +{
> + //FIXME
> + return NULL;
> +}
GetTempPathW is available even in UWP. You can put the implementation in
a file built in both cases.
> 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;
> +}
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
More information about the vlc-devel
mailing list