tag: use GLib instead of utils.h
Don't use the deprecated functions from utils.h.
This commit is contained in:
parent
35710a81ea
commit
aa772ebc02
18
src/tag.c
18
src/tag.c
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of items managed in the bulk list; if it is
|
* Maximum number of items managed in the bulk list; if it is
|
||||||
|
@ -85,7 +87,7 @@ void tag_lib_init(void)
|
||||||
if (0 == strcasecmp(param->value, "none"))
|
if (0 == strcasecmp(param->value, "none"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
temp = c = s = xstrdup(param->value);
|
temp = c = s = g_strdup(param->value);
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
if (*s == ',' || *s == '\0') {
|
if (*s == ',' || *s == '\0') {
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
|
@ -180,7 +182,7 @@ struct tag *tag_ape_load(const char *file)
|
||||||
tagLen -= sizeof(footer);
|
tagLen -= sizeof(footer);
|
||||||
if (tagLen <= 0)
|
if (tagLen <= 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
buffer = xmalloc(tagLen);
|
buffer = g_malloc(tagLen);
|
||||||
if (fread(buffer, 1, tagLen, fp) != tagLen)
|
if (fread(buffer, 1, tagLen, fp) != tagLen)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -233,7 +235,7 @@ fail:
|
||||||
|
|
||||||
struct tag *tag_new(void)
|
struct tag *tag_new(void)
|
||||||
{
|
{
|
||||||
struct tag *ret = xmalloc(sizeof(*ret));
|
struct tag *ret = g_new(struct tag, 1);
|
||||||
ret->items = NULL;
|
ret->items = NULL;
|
||||||
ret->time = -1;
|
ret->time = -1;
|
||||||
ret->numOfItems = 0;
|
ret->numOfItems = 0;
|
||||||
|
@ -255,7 +257,7 @@ static void deleteItem(struct tag *tag, int idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag->numOfItems > 0) {
|
if (tag->numOfItems > 0) {
|
||||||
tag->items = xrealloc(tag->items, items_size(tag));
|
tag->items = g_realloc(tag->items, items_size(tag));
|
||||||
} else {
|
} else {
|
||||||
free(tag->items);
|
free(tag->items);
|
||||||
tag->items = NULL;
|
tag->items = NULL;
|
||||||
|
@ -307,7 +309,7 @@ struct tag *tag_dup(const struct tag *tag)
|
||||||
ret = tag_new();
|
ret = tag_new();
|
||||||
ret->time = tag->time;
|
ret->time = tag->time;
|
||||||
ret->numOfItems = tag->numOfItems;
|
ret->numOfItems = tag->numOfItems;
|
||||||
ret->items = ret->numOfItems > 0 ? xmalloc(items_size(tag)) : NULL;
|
ret->items = ret->numOfItems > 0 ? g_malloc(items_size(tag)) : NULL;
|
||||||
|
|
||||||
pthread_mutex_lock(&tag_pool_lock);
|
pthread_mutex_lock(&tag_pool_lock);
|
||||||
for (i = 0; i < tag->numOfItems; i++)
|
for (i = 0; i < tag->numOfItems; i++)
|
||||||
|
@ -388,7 +390,7 @@ void tag_end_add(struct tag *tag)
|
||||||
if (tag->numOfItems > 0) {
|
if (tag->numOfItems > 0) {
|
||||||
/* copy the tag items from the bulk list over
|
/* copy the tag items from the bulk list over
|
||||||
to a new list (which fits exactly) */
|
to a new list (which fits exactly) */
|
||||||
tag->items = xmalloc(items_size(tag));
|
tag->items = g_malloc(items_size(tag));
|
||||||
memcpy(tag->items, bulk.items, items_size(tag));
|
memcpy(tag->items, bulk.items, items_size(tag));
|
||||||
} else
|
} else
|
||||||
tag->items = NULL;
|
tag->items = NULL;
|
||||||
|
@ -420,12 +422,12 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
|
||||||
|
|
||||||
if (tag->items != bulk.items)
|
if (tag->items != bulk.items)
|
||||||
/* bulk mode disabled */
|
/* bulk mode disabled */
|
||||||
tag->items = xrealloc(tag->items, items_size(tag));
|
tag->items = g_realloc(tag->items, items_size(tag));
|
||||||
else if (tag->numOfItems >= BULK_MAX) {
|
else if (tag->numOfItems >= BULK_MAX) {
|
||||||
/* bulk list already full - switch back to non-bulk */
|
/* bulk list already full - switch back to non-bulk */
|
||||||
assert(bulk.busy);
|
assert(bulk.busy);
|
||||||
|
|
||||||
tag->items = xmalloc(items_size(tag));
|
tag->items = g_malloc(items_size(tag));
|
||||||
memcpy(tag->items, bulk.items,
|
memcpy(tag->items, bulk.items,
|
||||||
items_size(tag) - sizeof(struct tag_item *));
|
items_size(tag) - sizeof(struct tag_item *));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue