summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-07-30 01:31:40 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-07-30 01:31:40 +0000
commit46de181b4e1b74d116a69192817b7c9df694174d (patch)
tree7fc89583752a7a7aaff87b5c7bcfdf417d5469cc
parent0cbd9fae9d5efccad7957422704b007bf85cc3b9 (diff)
downloadeet-46de181b4e1b74d116a69192817b7c9df694174d.tar.gz
+eet_alias_get, related, docs, some spelling corrections
SVN revision: 61915
-rw-r--r--ChangeLog4
-rw-r--r--src/lib/Eet.h20
-rw-r--r--src/lib/eet_lib.c77
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 <mathieu.taillefumier@@free.fr>
@author Albin "Lutin" Tonnerre <albin.tonnerre@@gmail.com>
@author Adam Simpkins <adam@@adamsimpkins.net>
+@author Mike Blumenkrantz <mike@zentific.com>
@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,