core/file: Switch file_readl() to return a gchar *
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
471c773bd5
commit
7529ccd4cc
|
@ -128,17 +128,14 @@ int file_readf(struct file *file, const char *fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string file_readl(struct file *file)
|
||||
gchar *file_readl(struct file *file)
|
||||
{
|
||||
std::string res;
|
||||
gchar *g_res;
|
||||
gchar *res;
|
||||
|
||||
if (file_readf(file, "%m[^\n]\n", &g_res) == 0)
|
||||
g_res = g_strdup("");
|
||||
if (file_readf(file, "%m[^\n]\n", &res) == 0)
|
||||
return g_strdup("");
|
||||
|
||||
g_strstrip(g_res);
|
||||
res = g_res;
|
||||
g_free(g_res);
|
||||
g_strstrip(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,9 +55,11 @@ void IndexEntry :: write(file &file)
|
|||
void IndexEntry :: read(file &file)
|
||||
{
|
||||
unsigned int num, val;
|
||||
gchar *key = file_readl(&file);
|
||||
|
||||
_key = file_readl(&file);
|
||||
file_readf(&file, "%u", &num);
|
||||
_key = key;
|
||||
g_free(key);
|
||||
|
||||
for (unsigned int i = 0; i < num; i++) {
|
||||
file_readf(&file, "%u", &val);
|
||||
|
|
|
@ -28,11 +28,13 @@ const std::string GenericTag :: primary_key() const
|
|||
|
||||
void GenericTag :: read(file &file)
|
||||
{
|
||||
gchar *g_lc;
|
||||
gchar *name = file_readl(&file);
|
||||
gchar *g_lc = string_lowercase(name);
|
||||
|
||||
_name = file_readl(&file);
|
||||
g_lc = string_lowercase(_name.c_str());
|
||||
_name = name;
|
||||
_lower = g_lc;
|
||||
|
||||
g_free(name);
|
||||
g_free(g_lc);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,14 @@ const std::string Library :: primary_key() const
|
|||
void Library :: read(file &file)
|
||||
{
|
||||
int enabled;
|
||||
gchar *path;
|
||||
|
||||
file_readf(&file, "%d\n", &enabled);
|
||||
_enabled = enabled;
|
||||
_path = file_readl(&file);
|
||||
|
||||
path = file_readl(&file);
|
||||
_path = path;
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
void Library :: write(file &file)
|
||||
|
|
|
@ -119,13 +119,16 @@ int Track :: compare_date(const Track *rhs)
|
|||
void Track :: read(file &file)
|
||||
{
|
||||
unsigned int library_id, artist_id, album_id, genre_id;
|
||||
gchar *path;
|
||||
|
||||
file_readf(&file, "%u %u %u %u %u %u %u %u %u %u", &library_id,
|
||||
&artist_id, &album_id, &genre_id, &_track, &_date.year,
|
||||
&_date.month, &_date.day, &_count, &_length);
|
||||
|
||||
GenericTag :: read(file);
|
||||
_path = file_readl(&file);
|
||||
path = file_readl(&file);
|
||||
_path = path;
|
||||
g_free(path);
|
||||
|
||||
_library = tags :: get_library(library_id);
|
||||
_artist = tags :: get_artist(artist_id);
|
||||
|
|
|
@ -89,8 +89,11 @@ bool file_open(struct file *, OpenMode);
|
|||
/* Close an open file, setting file->f_file to NULL. */
|
||||
void file_close(struct file *);
|
||||
|
||||
/* Read an entire line from the file and return it to the caller. */
|
||||
std::string file_readl(struct file *);
|
||||
/*
|
||||
* Read an entire line from the file and return it to the caller.
|
||||
* This function allocates a new string that MUST be freed with g_free().
|
||||
*/
|
||||
gchar *file_readl(struct file *);
|
||||
|
||||
/*
|
||||
* Read from a file with an fscanf(3) style format string.
|
||||
|
|
|
@ -116,8 +116,10 @@ static void test_io()
|
|||
free(res);
|
||||
|
||||
test_equal(file_readf(&fin, "%u", &i), 1);
|
||||
res = file_readl(&fin);
|
||||
test_equal(i, 3);
|
||||
test_equal(file_readl(&fin), "");
|
||||
test_equal(res, "");
|
||||
free(res);
|
||||
|
||||
test_equal(file_readf(&fin, "%u %m[^\n]", &i, &res), 2);
|
||||
test_equal(i, 4);
|
||||
|
|
Loading…
Reference in New Issue