forked from enlightenment/efl
efl: make xattr stuff work.
* fix eina_xattr_value_ls() and eina_xattr_value_fd_ls() to not loop infinitely. * NULL terminate the retrieved xattr values, at least they'll be easier to handle in our programs and less error prone. SVN revision: 81940
This commit is contained in:
parent
80fd3a77c0
commit
9161f83a3e
|
@ -29,6 +29,11 @@
|
||||||
# include <sys/xattr.h>
|
# include <sys/xattr.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "eina_config.h"
|
#include "eina_config.h"
|
||||||
#include "eina_private.h"
|
#include "eina_private.h"
|
||||||
|
|
||||||
|
@ -37,6 +42,7 @@
|
||||||
#include "eina_convert.h"
|
#include "eina_convert.h"
|
||||||
#include "eina_stringshare.h"
|
#include "eina_stringshare.h"
|
||||||
|
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Local *
|
* Local *
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
@ -73,11 +79,12 @@ _eina_xattr_value_ls_fd_iterator_next(Eina_Xattr_Iterator *it, void **data)
|
||||||
|
|
||||||
*data = it->attr;
|
*data = it->attr;
|
||||||
it->attr->name = it->xattr + it->offset;
|
it->attr->name = it->xattr + it->offset;
|
||||||
|
it->offset += strlen(it->attr->name) + 1;
|
||||||
|
|
||||||
it->attr->length = fgetxattr(it->fd, it->attr->name, NULL, 0);
|
it->attr->length = fgetxattr(it->fd, it->attr->name, NULL, 0);
|
||||||
if (it->attr->length)
|
if (it->attr->length)
|
||||||
{
|
{
|
||||||
tmp = realloc((void*) it->attr->value, it->attr->length);
|
tmp = realloc((void*) it->attr->value, it->attr->length + 1);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
{
|
{
|
||||||
free((void*) it->attr->value);
|
free((void*) it->attr->value);
|
||||||
|
@ -86,9 +93,11 @@ _eina_xattr_value_ls_fd_iterator_next(Eina_Xattr_Iterator *it, void **data)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
it->attr->value = tmp;
|
||||||
it->attr->length = fgetxattr(it->fd, it->attr->name,
|
it->attr->length = fgetxattr(it->fd, it->attr->name,
|
||||||
(void *) it->attr->value,
|
(void *) it->attr->value,
|
||||||
it->attr->length);
|
it->attr->length);
|
||||||
|
tmp[it->attr->length] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +114,7 @@ _eina_xattr_value_ls_iterator_next(Eina_Xattr_Iterator *it, void **data)
|
||||||
|
|
||||||
*data = it->attr;
|
*data = it->attr;
|
||||||
it->attr->name = it->xattr + it->offset;
|
it->attr->name = it->xattr + it->offset;
|
||||||
|
it->offset += strlen(it->attr->name) + 1;
|
||||||
|
|
||||||
it->attr->length = getxattr(it->file, it->attr->name, NULL, 0);
|
it->attr->length = getxattr(it->file, it->attr->name, NULL, 0);
|
||||||
if (it->attr->length)
|
if (it->attr->length)
|
||||||
|
@ -118,9 +128,11 @@ _eina_xattr_value_ls_iterator_next(Eina_Xattr_Iterator *it, void **data)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
it->attr->value = tmp;
|
||||||
it->attr->length = getxattr(it->file, it->attr->name,
|
it->attr->length = getxattr(it->file, it->attr->name,
|
||||||
(void*) it->attr->value,
|
(void*) it->attr->value,
|
||||||
it->attr->length);
|
it->attr->length);
|
||||||
|
tmp[it->attr->length] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,6 +313,13 @@ eina_xattr_value_ls(const char *file)
|
||||||
it = calloc(1, sizeof (Eina_Xattr_Iterator) + length - 1);
|
it = calloc(1, sizeof (Eina_Xattr_Iterator) + length - 1);
|
||||||
if (!it) return NULL;
|
if (!it) return NULL;
|
||||||
|
|
||||||
|
it->attr = calloc(1, sizeof (Eina_Xattr));
|
||||||
|
if (!it->attr)
|
||||||
|
{
|
||||||
|
free(it);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
|
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
|
||||||
|
|
||||||
it->length = listxattr(file, it->xattr, length);
|
it->length = listxattr(file, it->xattr, length);
|
||||||
|
@ -328,7 +347,7 @@ EAPI void *
|
||||||
eina_xattr_get(const char *file, const char *attribute, ssize_t *size)
|
eina_xattr_get(const char *file, const char *attribute, ssize_t *size)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_XATTR
|
#ifdef HAVE_XATTR
|
||||||
void *ret = NULL;
|
char *ret = NULL;
|
||||||
ssize_t tmp;
|
ssize_t tmp;
|
||||||
|
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
||||||
|
@ -340,12 +359,13 @@ eina_xattr_get(const char *file, const char *attribute, ssize_t *size)
|
||||||
if (!(*size > 0 && *size < 2 * 1024 * 1024))
|
if (!(*size > 0 && *size < 2 * 1024 * 1024))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
ret = malloc(*size);
|
ret = malloc(*size + 1);
|
||||||
if (!ret) return NULL;
|
if (!ret) goto on_error;
|
||||||
|
|
||||||
tmp = getxattr(file, attribute, ret, *size);
|
tmp = getxattr(file, attribute, ret, *size);
|
||||||
if (tmp != *size)
|
if (tmp != *size)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
ret[tmp] = '\0';
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue