path: move code to IsSupportedCharset()
This commit is contained in:
21
src/path.c
21
src/path.c
@@ -21,6 +21,7 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
|
#include "gcc.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@@ -60,18 +61,26 @@ utf8_to_fs_charset(const char *path_utf8)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
static bool
|
||||||
|
IsSupportedCharset(const char *charset)
|
||||||
|
{
|
||||||
|
/* convert a space to check if the charset is valid */
|
||||||
|
char *test = g_convert(" ", 1, charset, "UTF-8", NULL, NULL, NULL);
|
||||||
|
if (test == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
g_free(test);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
path_set_fs_charset(const char *charset)
|
path_set_fs_charset(const char *charset)
|
||||||
{
|
{
|
||||||
char *test;
|
|
||||||
|
|
||||||
assert(charset != NULL);
|
assert(charset != NULL);
|
||||||
|
|
||||||
/* convert a space to ensure that the charset is valid */
|
if (!IsSupportedCharset(charset))
|
||||||
test = g_convert(" ", 1, charset, "UTF-8", NULL, NULL, NULL);
|
|
||||||
if (test == NULL)
|
|
||||||
MPD_ERROR("invalid filesystem charset: %s", charset);
|
MPD_ERROR("invalid filesystem charset: %s", charset);
|
||||||
g_free(test);
|
|
||||||
|
|
||||||
g_free(fs_charset);
|
g_free(fs_charset);
|
||||||
fs_charset = g_strdup(charset);
|
fs_charset = g_strdup(charset);
|
||||||
|
Reference in New Issue
Block a user