From 48f21004a37df39dd63f6dbc0c8d65d2b60c6552 Mon Sep 17 00:00:00 2001 From: discomfitor Date: Sat, 30 Jul 2011 01:31:40 +0000 Subject: [PATCH] +eet_alias_get, related, docs, some spelling corrections git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eet@61915 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 4 +++ src/lib/Eet.h | 20 +++++++++++++-- src/lib/eet_lib.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb57e97..b108bff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -522,3 +522,7 @@ * On Windows, open() in text mode followed by fdopen() in binary mode does not create a stream in binary mode. So add O_BINARY to open(). + +2011-07-29 Mike Blumenkrantz + + * Add eet_alias_get to return the destination name of an alias diff --git a/src/lib/Eet.h b/src/lib/Eet.h index 7a722bf..b09d3a4 100644 --- a/src/lib/Eet.h +++ b/src/lib/Eet.h @@ -20,6 +20,7 @@ These routines are used for Eet Library interaction @author Mathieu Taillefumier @author Albin "Lutin" Tonnerre @author Adam Simpkins +@author Mike Blumenkrantz @date 2000-2011 @section toc Table of Contents @@ -750,11 +751,11 @@ eet_delete(Eet_File *ef, * no check are done. * @param ef A valid eet file handle opened for writing. * @param name Name of the entry. eg: "/base/file_i_want". - * @param destination Destionation of the alias. eg: "/base/the_real_stuff_i_want". + * @param destination Destination of the alias. eg: "/base/the_real_stuff_i_want". * @param compress Compression flags (1 == compress, 0 = don't compress). * @return EINA_TRUE on success, EINA_FALSE on failure. * - * Name and Destination must not be NULL, otherwhise EINA_FALSE will be returned. + * Name and Destination must not be NULL, otherwise EINA_FALSE will be returned. * * @since 1.3.3 * @ingroup Eet_File_Group @@ -766,6 +767,21 @@ eet_alias(Eet_File *ef, int compress); /** + * Retrieve the destination name of an alias + * @param ef A valid eet file handle opened for writing + * @param name Name of the entry. eg: "/base/file_i_want" + * @return Destination of the alias. eg: "/base/the_real_stuff_i_want", NULL on failure + * + * Name must not be NULL, otherwise NULL will be returned. + * + * @since 1.5 + * @ingroup Eet_File_Group + */ +EAPI const char * +eet_alias_get(Eet_File *ef, + const char *name); + +/** * List all entries in eet file matching shell glob. * @param ef A valid eet file handle. * @param glob A shell glob to match against. diff --git a/src/lib/eet_lib.c b/src/lib/eet_lib.c index 6ee10c4..f8f64ee 100644 --- a/src/lib/eet_lib.c +++ b/src/lib/eet_lib.c @@ -1983,6 +1983,83 @@ on_error: return NULL; } /* eet_read_direct */ +EAPI const char * +eet_alias_get(Eet_File *ef, + const char *name) +{ + Eet_File_Node *efn; + const char *data = NULL; + int size = 0; + + /* check to see its' an eet file pointer */ + if (eet_check_pointer(ef)) + return NULL; + + if (!name) + return NULL; + + if ((ef->mode != EET_FILE_MODE_READ) && + (ef->mode != EET_FILE_MODE_READ_WRITE)) + return NULL; + + /* no header, return NULL */ + if (eet_check_header(ef)) + return NULL; + + LOCK_FILE(ef); + + /* hunt hash bucket */ + efn = find_node_by_name(ef, name); + if (!efn) + goto on_error; + + /* trick to detect data in memory instead of mmaped from disk */ + if (efn->offset > ef->data_size && !efn->data) + goto on_error; + + /* get size (uncompressed, if compressed at all) */ + size = efn->data_size; + + if (!efn->alias) return NULL; + data = efn->data ? efn->data : ef->data + efn->offset; + + /* handle alias case */ + if (efn->compression) + { + char *tmp; + int compr_size = efn->size; + uLongf dlen; + + tmp = alloca(sizeof (compr_size)); + dlen = size; + + if (uncompress((Bytef *)tmp, &dlen, (Bytef *)data, + (uLongf)compr_size)) + goto on_error; + + if (tmp[compr_size - 1] != '\0') + goto on_error; + + UNLOCK_FILE(ef); + + return eina_stringshare_add(tmp); + } + + if (!data) + goto on_error; + + if (data[size - 1] != '\0') + goto on_error; + + UNLOCK_FILE(ef); + + return eina_stringshare_add(data); + +on_error: + UNLOCK_FILE(ef); + return NULL; +} + EAPI Eina_Bool eet_alias(Eet_File *ef, const char *name, -- 2.7.4