+/* strdup requires BSD source */
+#define _BSD_SOURCE
+
#include "Eet.h"
#include <stdio.h>
#include <unistd.h>
get_time(void)
{
struct timeval timev;
-
+
gettimeofday(&timev, NULL);
return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
}
int items_num;
int i;
double t1, t2;
-
+
+ if (argc < 2)
+ exit(-1);
+
file = argv[1];
ef = eet_open(file, EET_FILE_MODE_READ);
if (ef)
printf("EEK. cannot load %s\n", file);
exit(-1);
}
-
+
t1 = get_time();
ef = eet_open(file, EET_FILE_MODE_READ);
if (ef)
{
for (i = 0; i < items_num; i++)
{
- int w, h, alpha, compress, quality, lossy;
+ int alpha, compress, quality, lossy;
+ unsigned int w, h;
void *data;
-
+
if (eet_data_image_header_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy))
{
data = eet_data_image_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy);
t1 = get_time();
for (i = 0; i < items_num; i++)
{
- int w, h, alpha, compress, quality, lossy;
+ int alpha, compress, quality, lossy;
+ unsigned int w, h;
void *data;
-
+
ef = eet_open(file, EET_FILE_MODE_READ);
if (ef)
{
+/* PATH_MAX requires POSIX source */
+#define _POSIX_SOURCE
+
#include "Eet.h"
#include <stdio.h>
#include <unistd.h>
int size;
FILE *f;
Blah *blah_in;
-
+
edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3),
- evas_list_next,
- evas_list_append,
- evas_list_data,
+ evas_list_next,
+ evas_list_append,
+ evas_list_data,
evas_list_free,
evas_hash_foreach,
evas_hash_add,
evas_hash_free);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
-
+
edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2),
- evas_list_next,
- evas_list_append,
- evas_list_data,
+ evas_list_next,
+ evas_list_append,
+ evas_list_data,
evas_list_free,
evas_hash_foreach,
evas_hash_add,
evas_hash_free);
EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
-
+
edd = eet_data_descriptor_new("blah", sizeof(Blah),
- evas_list_next,
- evas_list_append,
- evas_list_data,
+ evas_list_next,
+ evas_list_append,
+ evas_list_data,
evas_list_free,
evas_hash_foreach,
evas_hash_add,
EET_DATA_DESCRIPTOR_ADD_LIST (edd, Blah, "blah3", blah3, edd3);
blah3.string="PANTS";
-
+
blah2.string="subtype string here!";
-
+
blah.character='7';
blah.sixteen=0x7777;
blah.integer=0xc0def00d;
blah.blah3 = evas_list_append(blah.blah3, &blah3);
blah.blah3 = evas_list_append(blah.blah3, &blah3);
blah.blah3 = evas_list_append(blah.blah3, &blah3);
-
+
data = eet_data_descriptor_encode(edd, &blah, &size);
f = fopen("out", "wb");
if (f)
{
fwrite(data, size, 1, f);
fclose(f);
- }
+ }
printf("-----DECODING\n");
blah_in = eet_data_descriptor_decode(edd, data, size);
printf("-----DECODED!\n");
printf(" %s\n", blah_in->blah2->string);
{
Evas_List *l;
-
+
for (l = blah_in->blah3; l; l = l->next)
{
Blah3 *blah3_in;
-
+
blah3_in = l->data;
printf("%p\n", blah3_in);
printf(" %s\n", blah3_in->string);
eet_data_descriptor_free(edd);
eet_data_descriptor_free(edd2);
eet_data_descriptor_free(edd3);
-
+
exit(0);
}
#endif
{
char ss[PATH_MAX];
int i, ii;
-
+
i = 0;
ii = 0;
while (s[i])
void *data;
int size;
char *last;
-
+
data = eet_read(ef, file, &size);
if (data)
{
FILE *f;
char buf[PATH_MAX];
int len;
-
+
strncpy(buf, file, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
if (buf[0] == '/') return;
if (!strcmp(&(buf[len - 3]), "/..")) return;
}
last = strrchr(buf, '/');
- if (last)
+ if (last)
{
last[1] = 0;
eet_mkdirs(buf);
}
-
+
f = fopen(file, "wb");
if (f)
{
int i, num;
char **list;
Eet_File *ef;
-
- ef = eet_open(pak_file, EET_FILE_MODE_READ);
+
+ ef = eet_open(pak_file, EET_FILE_MODE_READ);
if (!ef)
{
printf("cannot open for reading: %s\n", pak_file);
depak_file(ef, list[i]);
free(list);
}
- eet_close(ef);
+ eet_close(ef);
}
void
int i, num;
char **list;
Eet_File *ef;
-
- ef = eet_open(pak_file, EET_FILE_MODE_READ);
+
+ ef = eet_open(pak_file, EET_FILE_MODE_READ);
if (!ef)
{
printf("cannot open for reading: %s\n", pak_file);
printf("%s\n",list[i]);
free(list);
}
- eet_close(ef);
+ eet_close(ef);
}
void
pak_file(Eet_File *ef, char *file, char **noz, int noz_num)
{
struct stat st;
-
+
if (stat(file, &st) >= 0)
{
void *buf;
-
+
buf = malloc(st.st_size);
if (buf)
{
FILE *f;
-
+
f = fopen(file, "rb");
if (f)
{
int compress = 1;
int i;
-
+
for (i = 0; i < noz_num; i++)
{
if (!fnmatch(noz[i], file, 0))
while ((dp = readdir(dirp)))
{
char buf[PATH_MAX];
-
+
if ((!strcmp(".", dp->d_name)) || (!strcmp("..", dp->d_name)))
{
}
{
Eet_File *ef;
int i;
-
+
ef = eet_open(pak_file, EET_FILE_MODE_WRITE);
if (!ef)
{
int
main(int argc, char **argv)
-{
+{
if (argc == 3)
{
if (!strcmp(argv[1], "-d"))
{
char **noz = NULL;
int noz_num = 0;
-
+
if (!strcmp(argv[1], "-c"))
{
int i;
-
+
for (i = 3; i < argc; i++)
{
if (!strcmp(argv[i], "-nz"))
EET_FILE_MODE_WRITE,
EET_FILE_MODE_READ_WRITE
};
-
+
typedef enum _Eet_File_Mode Eet_File_Mode;
-
+
typedef struct _Eet_File Eet_File;
typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
* @param file The file path to the eet file. eg: "/tmp/file.eet".
* @param mode The mode for opening. Either EET_FILE_MODE_READ or EET_FILE_MODE_WRITE, but not both.
* @return An opened eet file handle.
- *
+ *
* This function will open an exiting eet file for reading, and build
* the directory table in memory and return a handle to the file, if it
* exists and can be read, and no memory errors occur on the way, otherwise
* NULL will be returned.
- *
+ *
* It will also open an eet file for writing. This will, if successful,
* delete the original file and replace it with a new empty file, till
* the eet file handle is closed or flushed. If it cannot be opened for
* writing or a memory error occurs, NULL is returned.
- *
+ *
* Example:
* @code
* #include <Eet.h>
- *
+ *
* int
* main(int argc, char **argv)
* {
* Eet_File *ef;
* char buf[1024], *ret, **list;
* int size, num, i;
- *
+ *
* strcpy(buf, "Here is a string of data to save!");
- *
+ *
* ef = eet_open("/tmp/my_file.eet, EET_FILE_MODE_WRITE);
* if (!ef) return -1;
* if (!eet_write(ef, "/key/to_store/at", buf, 1024, 1))
* fprintf("Error writing data!\n");
* eet_close(ef);
- *
+ *
* ef = eet_open("/tmp/my_file.eet, EET_FILE_MODE_READ);
* if (!ef) return -1;
* list = eet_list(ef, "*", &num);
* free(ret);
* }
* eet_close(ef);
- *
+ *
* return 0;
* }
* @endcode
- */
+ */
EAPI Eet_File *eet_open (const char *file, Eet_File_Mode mode);
/**
* @return The mode ef was opened with.
*/
EAPI Eet_File_Mode eet_mode_get (Eet_File *ef);
-
+
/**
* Close an eet file handle and flush and writes pending.
* @param ef A valid eet file handle.
- *
+ *
* This function will flush any pending writes to disk if the eet file
* was opened for write, and free all data associated with the file handle
* and file, and close the file.
- *
+ *
* If the eet file handle is not valid nothing will be done.
*/
EAPI void eet_close (Eet_File *ef);
-
+
/**
* Read a specified entry from an eet file and return data
* @param ef A valid eet file handle opened for reading.
* @param name Name of the entry. eg: "/base/file_i_want".
* @param size_ret Number of bytes read from entry and returned.
* @return The data stored in that entry in the eet file.
- *
+ *
* This function finds an entry in the eet file that is stored under the
* name specified, and returns that data, decompressed, if successful.
* NULL is returned if the lookup fails or if memory errors are
* encountered. It is the job of the calling program to call free() on
* the returned data. The number of bytes in the returned data chunk are
* placed in size_ret.
- *
+ *
* If the eet file handle is not valid NULL is returned and size_ret is
* filled with 0.
*/
* @param size Length in bytes in the data to be stored.
* @param compress Compression flags (1 == compress, 0 = don't compress).
* @return Success or failure of the write.
- *
+ *
* This function will write the specified chunk of data to the eet file
* and return greater than 0 on success. 0 will be returned on failure.
- *
- * The eet file handle must be a valid file handle for an eet file opened
+ *
+ * The eet file handle must be a valid file handle for an eet file opened
* for writing. If it is not, 0 will be returned and no action will be
* performed.
- *
+ *
* Name, and data must not be NULL, and size must be > 0. If these
* conditions are not met, 0 will be returned.
- *
+ *
* The data will be copied (and optionally compressed) in ram, pending
* a flush to disk (it will stay in ram till the eet file handle is
* closed though).
* @param ef A valid eet file handle opened for writing.
* @param name Name of the entry. eg: "/base/file_i_want".
* @return Success or failure of the delete.
- *
+ *
* This function will delete the specified chunk of data from the eet file
* and return greater than 0 on success. 0 will be returned on failure.
- *
- * The eet file handle must be a valid file handle for an eet file opened
+ *
+ * The eet file handle must be a valid file handle for an eet file opened
* for writing. If it is not, 0 will be returned and no action will be
* performed.
- *
+ *
* Name, must not be NULL, otherwise 0 will be returned.
*/
EAPI int eet_delete(Eet_File *ef, 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.
* @param count_ret Number of entries found to match.
* @return Pointer to an array of strings.
- *
+ *
* This function will list all entries in the eet file matching the
* supplied shell glob and return an allocated list of their names, if
* there are any, and if no memory errors occur.
- *
+ *
* The eet file handle must be valid and glob must not be NULL, or NULL
* will be returned and count_ret will be filled with 0.
- *
+ *
* The calling program must call free() on the array returned, but NOT
* on the string pointers in the array. They are taken as read-only
* internals from the eet file handle. They are only valid as long as
* the file handle is not closed. When it is closed those pointers in the
* array are now not valid and should not be used.
- *
+ *
* On success the array returned will have a list of string pointers
* that are the names of the entries that matched, and count_ret will have
* the number of entries in this array placed in it.
- *
+ *
* Hint: an easy way to list all entries in an eet file is to use a glob
* value of "*".
*/
* Read just the header data for an image and dont decode the pixels.
* @param ef A valid eet file handle opened for reading.
* @param name Name of the entry. eg: "/base/file_i_want".
- * @param w A pointer to the int to hold the width in pixels.
- * @param h A pointer to the int to hold the height in pixels.
+ * @param w A pointer to the unsigned int to hold the width in pixels.
+ * @param h A pointer to the unsigned int to hold the height in pixels.
* @param alpha A pointer to the int to hold the alpha flag.
* @param compress A pointer to the int to hold the compression amount.
* @param quality A pointer to the int to hold the quality amount.
* @param lossy A pointer to the int to hold the lossiness flag.
* @return 1 on successfull decode, 0 otherwise
- *
+ *
* This function reads an image from an eet file stored under the named
* key in the eet file and return a pointer to the decompressed pixel data.
- *
+ *
* The other parameters of the image (width, height etc.) are placed into
* the values pointed to (they must be supplied). The pixel data is a linear
- * array of pixels starting from the top-left of the image scanning row by
+ * array of pixels starting from the top-left of the image scanning row by
* row from left to right. Each pile is a 32bit value, with the high byte
* being the alpha channel, the next being red, then green, and the low byte
* being blue. The width and height are measured in pixels and will be
* stored with. The quality value is filled with the quality encoding of
* the image file (0 - 100). The lossy flags is either 0 or 1 as to if
* the image was encoded lossily or not.
- *
+ *
* On success the function returns 1 indicating the header was read and
* decoded properly, or 0 on failure.
*/
- EAPI int eet_data_image_header_read(Eet_File *ef, char *name, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
-
+ EAPI int eet_data_image_header_read(Eet_File *ef, char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+
/**
* Read image data from the named key in the eet file.
* @param ef A valid eet file handle opened for reading.
* @param name Name of the entry. eg: "/base/file_i_want".
- * @param w A pointer to the int to hold the width in pixels.
- * @param h A pointer to the int to hold the height in pixels.
+ * @param w A pointer to the unsigned int to hold the width in pixels.
+ * @param h A pointer to the unsigned int to hold the height in pixels.
* @param alpha A pointer to the int to hold the alpha flag.
* @param compress A pointer to the int to hold the compression amount.
* @param quality A pointer to the int to hold the quality amount.
* @param lossy A pointer to the int to hold the lossiness flag.
* @return The image pixel data decoded
- *
+ *
* This function reads an image from an eet file stored under the named
* key in the eet file and return a pointer to the decompressed pixel data.
- *
+ *
* The other parameters of the image (width, height etc.) are placed into
* the values pointed to (they must be supplied). The pixel data is a linear
- * array of pixels starting from the top-left of the image scanning row by
+ * array of pixels starting from the top-left of the image scanning row by
* row from left to right. Each pile is a 32bit value, with the high byte
* being the alpha channel, the next being red, then green, and the low byte
* being blue. The width and height are measured in pixels and will be
* stored with. The quality value is filled with the quality encoding of
* the image file (0 - 100). The lossy flags is either 0 or 1 as to if
* the image was encoded lossily or not.
- *
+ *
* On success the function returns a pointer to the image data decoded. The
* calling application is responsible for calling free() on the image data
* when it is done with it. On failure NULL is returned and the parameter
* values may not contain any sensible data.
*/
- EAPI void *eet_data_image_read(Eet_File *ef, char *name, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
-
+ EAPI void *eet_data_image_read(Eet_File *ef, char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+
/**
* Write image data to the named key in an eet file.
* @param ef A valid eet file handle opened for writing.
* @param quality The quality encoding amount.
* @param lossy The lossiness flag.
* @return Success if the data was encoded and written or not.
- *
+ *
* This function takes image pixel data and encodes it in an eet file
* stored under the supplied name key, and returns how many bytes were
* actually written to encode the image data.
- *
+ *
* The data expected is the same format as returned by eet_data_image_read.
* If this is not the case weird things may happen. Width and height must
* be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
* lossy compression and should be a value from 0 to 100. The lossy flag
* can be 0 or 1. 0 means encode losslessly and 1 means to encode with
* image quality loss (but then have a much smaller encoding).
- *
+ *
* On success this function returns the number of bytes that were required
* to encode the image data, or on failure it returns 0.
- */
- EAPI int eet_data_image_write(Eet_File *ef, char *name, void *data, int w, int h, int alpha, int compress, int quality, int lossy);
-
+ */
+ EAPI int eet_data_image_write(Eet_File *ef, char *name, void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
+
/**
* Decode Image data header only to get information.
* @param data The encoded pixel data.
* @param size The size, in bytes, of the encoded pixel data.
- * @param w A pointer to the int to hold the width in pixels.
- * @param h A pointer to the int to hold the height in pixels.
+ * @param w A pointer to the unsigned int to hold the width in pixels.
+ * @param h A pointer to the unsigned int to hold the height in pixels.
* @param alpha A pointer to the int to hold the alpha flag.
* @param compress A pointer to the int to hold the compression amount.
* @param quality A pointer to the int to hold the quality amount.
* @param lossy A pointer to the int to hold the lossiness flag.
* @return 1 on success, 0 on failure.
- *
+ *
* This function takes encoded pixel data and decodes it into raw RGBA
* pixels on success.
- *
+ *
* The other parameters of the image (width, height etc.) are placed into
* the values pointed to (they must be supplied). The pixel data is a linear
- * array of pixels starting from the top-left of the image scanning row by
+ * array of pixels starting from the top-left of the image scanning row by
* row from left to right. Each pixel is a 32bit value, with the high byte
* being the alpha channel, the next being red, then green, and the low byte
* being blue. The width and height are measured in pixels and will be
* stored with. The quality value is filled with the quality encoding of
* the image file (0 - 100). The lossy flags is either 0 or 1 as to if
* the image was encoded lossily or not.
- *
+ *
* On success the function returns 1 indicating the header was read and
* decoded properly, or 0 on failure.
*/
- EAPI int eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI int eet_data_image_header_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
/**
* Decode Image data into pixel data.
* @param data The encoded pixel data.
* @param size The size, in bytes, of the encoded pixel data.
- * @param w A pointer to the int to hold the width in pixels.
- * @param h A pointer to the int to hold the height in pixels.
+ * @param w A pointer to the unsigned int to hold the width in pixels.
+ * @param h A pointer to the unsigned int to hold the height in pixels.
* @param alpha A pointer to the int to hold the alpha flag.
* @param compress A pointer to the int to hold the compression amount.
* @param quality A pointer to the int to hold the quality amount.
* @param lossy A pointer to the int to hold the lossiness flag.
* @return The image pixel data decoded
- *
+ *
* This function takes encoded pixel data and decodes it into raw RGBA
* pixels on success.
- *
+ *
* The other parameters of the image (width, height etc.) are placed into
* the values pointed to (they must be supplied). The pixel data is a linear
- * array of pixels starting from the top-left of the image scanning row by
+ * array of pixels starting from the top-left of the image scanning row by
* row from left to right. Each pixel is a 32bit value, with the high byte
* being the alpha channel, the next being red, then green, and the low byte
* being blue. The width and height are measured in pixels and will be
* stored with. The quality value is filled with the quality encoding of
* the image file (0 - 100). The lossy flags is either 0 or 1 as to if
* the image was encoded lossily or not.
- *
+ *
* On success the function returns a pointer to the image data decoded. The
* calling application is responsible for calling free() on the image data
* when it is done with it. On failure NULL is returned and the parameter
* values may not contain any sensible data.
*/
- EAPI void *eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI void *eet_data_image_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
/**
* Encode image data for storage or transmission.
* @param quality The quality encoding amount.
* @param lossy The lossiness flag.
* @return The encoded image data.
- *
+ *
* This function stakes image pixel data and encodes it with compression and
* possible loss of quality (as a trade off for size) for storage or
* transmission to another system.
- *
+ *
* The data expected is the same format as returned by eet_data_image_read.
* If this is not the case weird things may happen. Width and height must
* be between 1 and 8000 pixels. The alpha flags can be 0 or 1 (0 meaning
* lossy compression and should be a value from 0 to 100. The lossy flag
* can be 0 or 1. 0 means encode losslessly and 1 means to encode with
* image quality loss (but then have a much smaller encoding).
- *
+ *
* On success this function returns a pointer to the encoded data that you
* can free with free() when no longer needed.
- */
- EAPI void *eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy);
+ */
+ EAPI void *eet_data_image_encode(void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
/***************************************************************************/
-
+
/**
* Create a new empty data structure descriptor.
* @param name The string name of this data structure.
* @param func_hash_add The function to add a member to a hash table.
* @param func_hash_free The function to free an entire hash table.
* @return A new empty data descriptor.
- *
+ *
* This function creates a new data descriptore and returns a handle to the
* new data descriptor. On creation it will be empty, containing no contents
* describing anything other than the shell of the data structure.
- *
+ *
* You add structure members to the data descriptor using the macros
* EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
* EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
* adding to the description.
- *
+ *
* Once you have described all the members of a struct you want loaded, or
* saved eet can load and save those members for you, encode them into
* endian-independant serialised data chunks for transmission across a
* a network or more.
- *
+ *
* Example:
- *
+ *
* @code
* #include <Eet.h>
* #include <Evas.h>
- *
+ *
* typedef struct _blah2
* {
* char *string;
* }
* Blah2;
- *
+ *
* typedef struct _blah3
* {
* char *string;
* }
* Blah3;
- *
+ *
* typedef struct _blah
* {
* char character;
* Evas_List *blah3;
* }
* Blah;
- *
+ *
* int
* main(int argc, char **argv)
* {
* int size;
* FILE *f;
* Blah *blah_in;
- *
+ *
* edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3),
* evas_list_next,
* evas_list_append,
* evas_hash_add,
* evas_hash_free);
* EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
- *
+ *
* edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2),
* evas_list_next,
* evas_list_append,
* evas_hash_add,
* evas_hash_free);
* EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
- *
+ *
* edd = eet_data_descriptor_new("blah", sizeof(Blah),
* evas_list_next,
* evas_list_append,
* EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING);
* EET_DATA_DESCRIPTOR_ADD_SUB(edd, Blah, "blah2", blah2, edd2);
* EET_DATA_DESCRIPTOR_ADD_LIST(edd, Blah, "blah3", blah3, edd3);
- *
+ *
* blah3.string="PANTS";
- *
+ *
* blah2.string="subtype string here!";
- *
+ *
* blah.character='7';
* blah.sixteen=0x7777;
* blah.integer=0xc0def00d;
* blah.blah3 = evas_list_append(blah.blah3, &blah3);
* blah.blah3 = evas_list_append(blah.blah3, &blah3);
* blah.blah3 = evas_list_append(blah.blah3, &blah3);
- *
+ *
* data = eet_data_descriptor_encode(edd, &blah, &size);
* f = fopen("out", "w");
* if (f)
* }
* printf("-----DECODING\n");
* blah_in = eet_data_descriptor_decode(edd, data, size);
- *
+ *
* printf("-----DECODED!\n");
* printf("%c\n", blah_in->character);
* printf("%x\n", (int)blah_in->sixteen);
* printf(" %s\n", blah_in->blah2->string);
* {
* Evas_List *l;
- *
+ *
* for (l = blah_in->blah3; l; l = l->next)
* {
* Blah3 *blah3_in;
- *
+ *
* blah3_in = l->data;
* printf("%p\n", blah3_in);
* printf(" %s\n", blah3_in->string);
* eet_data_descriptor_free(edd);
* eet_data_descriptor_free(edd2);
* eet_data_descriptor_free(edd3);
- *
+ *
* return 0;
* }
- *
+ *
* @endcode
- *
+ *
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_new(char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void *(*func_list_free) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d), void (*func_hash_free) (void *h));
-
+
/**
* This function frees a data descriptor when it is not needed anymore.
* @param edd The data descriptor to free.
* This function takes a data descriptor handle as a parameter and frees all
* data allocated for the data descriptor and the handle itself. After this
* call the descriptor is no longer valid.
- *
+ *
*/
EAPI void eet_data_descriptor_free(Eet_Data_Descriptor *edd);
-
+
/**
* This function is an internal used by macros.
*
* EET_DATA_DESCRIPTOR_ADD_SUB() and EET_DATA_DESCRIPTOR_ADD_LIST(). It is
* complex to use by hand and should be left to be used by the macros, and
* thus is not documented.
- *
+ *
*/
EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type, int group_type, int offset, int count, char *counter_name, Eet_Data_Descriptor *subtype);
-
+
/**
* Read a data structure from an eet file and decodes it.
* @param ef The eet file handle to read from.
* @param edd The data descriptor handle to use when decoding.
* @param name The key the data is stored under in the eet file.
* @return A pointer to the decoded data structure.
- *
+ *
* This function decodes a data structure stored in an eet file, returning
* a pointer to it if it decoded successfully, or NULL on failure. This
* can save a programmer dozens of hours of work in writing configuration
* storage and safely zero-fills unfilled members if they were not found
* in the data. It checks sizes and headers whenever it reads data, allowing
* the programmer to not worry about corrupt data.
- *
+ *
* Once a data structure has been described by the programmer with the
* fields they wish to save or load, storing or retrieving a data structure
* from an eet file, or from a chunk of memory is as simple as a single
* function call.
- *
+ *
*/
EAPI void *eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name);
-
+
/**
* Write a data structure from memory and store in an eet file.
* @param ef The eet file handle to write to.
* @param data A pointer to the data structure to ssave and encode.
* @param compress Compression flags for storage.
* @return 1 on successful write, 0 on failure.
- *
+ *
* This function is the reverse of eet_data_read(), saving a data structure
* to an eet file.
- *
+ *
*/
EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, char *name, void *data, int compress);
-
+
/**
* Decode a data structure from an arbitary location in memory.
* @param edd The data descriptor to use when decoding.
* @param data_in The pointer to the data to decode into a struct.
* @param size_in The size of the data pointed to in bytes.
* @return NULL on failure, or a valid decoded struct pointer on success.
- *
+ *
* This function will decode a data structure that has been encoded using
* eet_data_descriptor_encode(), and return a data structure with all its
* elements filled out, if successful, or NULL on failure.
- *
+ *
* The data to be decoded is stored at the memory pointed to by @p data_in,
* and is described by the descriptor pointed to by @p edd. The data size is
* passed in as the value to @p size_in, ande must be greater than 0 to
* succeed.
- *
+ *
* This function is useful for decoding data structures delivered to the
* application by means other than an eet file, such as an IPC or socket
* connection, raw files, shared memory etc.
- *
+ *
* Please see eet_data_read() for more information.
- *
- */
+ *
+ */
EAPI void *eet_data_descriptor_decode(Eet_Data_Descriptor *edd, void *data_in, int size_in);
-
+
/**
* Encode a dsata struct to memory and return that encoded data.
* @param edd The data descriptor to use when encoding.
* @return NULL on failure, or a valid encoded data chunk on success.
*
* This function takes a data structutre in memory and encodes it into a
- * serialised chunk of data that can be decoded again by
+ * serialised chunk of data that can be decoded again by
* eet_data_descriptor_decode(). This is useful for being able to transmit
* data structures across sockets, pipes, IPC or shared file mechanisms,
* without having to worry about memory space, machine type, endianess etc.
- *
+ *
* The parameter @p edd must point to a valid data descriptor, and
* @p data_in must point to the right data structure to encode. If not, the
* encoding may fail.
- *
+ *
* On success a non NULL valid pointer is returned and what @p size_ret
* points to is set to the size of this decoded data, in bytes. When the
* encoded data is no longer needed, call free() on it. On failure NULL is
* returned and what @p size_ret points to is set to 0.
- *
+ *
* Please see eet_data_write() for more information.
- *
+ *
*/
EAPI void *eet_data_descriptor_encode(Eet_Data_Descriptor *edd, void *data_in, int *size_ret);
* @param name The string name to use to encode/decode this member.
* @param member The struct member itself to be encoded.
* @param type The type of the member to encode.
- *
+ *
* This macro is a convenience macro provided to add a member to the data
* descriptor @p edd. The type of the structure is provided as the
* @p struct_type parameter (for example: struct my_struct). The @p name
* must be one of: EET_T_CHAR, EET_T_SHORT, EET_T_INT, EET_T_LONG_LONG,
* EET_T_FLOAT, EET_T_DOUBLE, EET_T_UCHAR, EET_T_USHORT, EET_T_UINT,
* EET_T_ULONG_LONG or EET_T_STRING.
- *
+ *
*/
#define EET_DATA_DESCRIPTOR_ADD_BASIC(edd, struct_type, name, member, type) \
{ \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
0, NULL, NULL); \
}
-
+
/**
* Add a sub-element type to a data descriptor
* @param edd The data descriptor to add the type to.
* @param name The string name to use to encode/decode this member.
* @param member The struct member itself to be encoded.
* @param subtype The type of sub-type struct to add.
- *
+ *
* This macro lets you easily add a sub-type (a struct that's pointed to
- * by this one). All the parameters are the same as for
+ * by this one). All the parameters are the same as for
* EET_DATA_DESCRIPTOR_ADD_BASIC(), with the @p subtype being the exception.
* This must be the data descriptor of the struct that is pointed to by
* this element.
- *
+ *
*/
#define EET_DATA_DESCRIPTOR_ADD_SUB(edd, struct_type, name, member, subtype) \
{ \
(char *)(&(___ett.member)) - (char *)(&(___ett)), \
0, NULL, subtype); \
}
-
+
/**
* Add a linked list type to a data descriptor
* @param edd The data descriptor to add the type to.
* @param name The string name to use to encode/decode this member.
* @param member The struct member itself to be encoded.
* @param subtype The type of linked list member to add.
- *
- * This macro lets you easily add a linked list of other data types. All the
- * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
+ *
+ * This macro lets you easily add a linked list of other data types. All the
+ * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_BASIC(), with the
* @p subtype being the exception. This must be the data descriptor of the
* element that is in each member of the linked list to be stored.
- *
+ *
*/
#define EET_DATA_DESCRIPTOR_ADD_LIST(edd, struct_type, name, member, subtype) \
{ \
/*
* rotuines for doing data -> struct and struct -> data conversion
- *
+ *
* types:
- *
+ *
* basic types:
* a sequence of...
- *
+ *
* char
* short
* int
* unsigned int
* unsgined long long
* string
- *
+ *
* groupings:
* multiple entries ordered as...
- *
+ *
* fixed size array [ of basic types ]
* variable size array [ of basic types ]
* linked list [ of basic types ]
* hash table [ of basic types ]
- *
+ *
* need to provide builder/accessor funcs for:
- *
+ *
* list_next
* list_append
- *
+ *
* hash_foreach
* hash_add
- *
+ *
*/
/*---*/
/*---*/
-const Eet_Data_Basic_Type_Decoder eet_coder[] =
+const Eet_Data_Basic_Type_Decoder eet_coder[] =
{
{sizeof(char), eet_data_get_char, eet_data_put_char },
{sizeof(short), eet_data_get_short, eet_data_put_short },
eet_data_get_char(void *src, void *src_end, void *dst)
{
char *s, *d;
-
+
if (((char *)src + sizeof(char)) > (char *)src_end) return -1;
s = (char *)src;
d = (char *)dst;
eet_data_put_char(void *src, int *size_ret)
{
char *s, *d;
-
+
d = (char *)malloc(sizeof(char));
if (!d) return NULL;
s = (char *)src;
eet_data_get_short(void *src, void *src_end, void *dst)
{
short *d;
-
+
if (((char *)src + sizeof(short)) > (char *)src_end) return -1;
memcpy(dst, src, sizeof(short));
d = (short *)dst;
eet_data_put_short(void *src, int *size_ret)
{
short *s, *d;
-
+
d = (short *)malloc(sizeof(short));
if (!d) return NULL;
s = (short *)src;
eet_data_get_int(void *src, void *src_end, void *dst)
{
int *d;
-
+
if (((char *)src + sizeof(int)) > (char *)src_end) return -1;
memcpy(dst, src, sizeof(int));
d = (int *)dst;
eet_data_put_int(void *src, int *size_ret)
{
int *s, *d;
-
+
d = (int *)malloc(sizeof(int));
if (!d) return NULL;
s = (int *)src;
eet_data_get_long_long(void *src, void *src_end, void *dst)
{
unsigned long long *d;
-
+
if (((char *)src + sizeof(unsigned long long)) > (char *)src_end) return -1;
memcpy(dst, src, sizeof(unsigned long long));
d = (unsigned long long *)dst;
eet_data_put_long_long(void *src, int *size_ret)
{
unsigned long long *s, *d;
-
+
d = (unsigned long long *)malloc(sizeof(unsigned long long));
if (!d) return NULL;
s = (unsigned long long *)src;
{
char *s, **d, *p;
int len;
-
+
s = (char *)src;
d = (char **)dst;
p = s;
char *s, *d;
int len;
const char *empty_s = "";
-
+
s = (char *)(*((char **)src));
if (!s) s = (char *)empty_s;
len = strlen(s);
float *d;
char *s, *str, *p, *prev_locale;
int len;
-
+
s = (char *)src;
d = (float *)dst;
p = s;
if (!str) return -1;
memcpy(str, s, len);
str[len] = 0;
-
+
prev_locale = setlocale(LC_NUMERIC, "C");
*d = (float)atof(str);
if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
-
+
free(str);
return len + 1;
}
float *s;
char *d, buf[64], *prev_locale;
int len;
-
+
s = (float *)src;
prev_locale = setlocale(LC_NUMERIC, "C");
snprintf(buf, sizeof(buf), "%a", (double)(*s));
double *d;
char *s, *str, *p, *prev_locale;
int len;
-
+
s = (char *)src;
d = (double *)dst;
p = s;
if (!str) return -1;
memcpy(str, s, len);
str[len] = 0;
-
+
prev_locale = setlocale(LC_NUMERIC, "C");
*d = (double)atof(str);
if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
-
+
free(str);
return len + 1;
}
double *s;
char *d, buf[128], *prev_locale;
int len;
-
+
s = (double *)src;
prev_locale = setlocale(LC_NUMERIC, "C");
snprintf(buf, sizeof(buf), "%a", (double)(*s));
eet_data_get_type(int type, void *src, void *src_end, void *dest)
{
int ret;
-
+
ret = eet_coder[type - 1].get(src, src_end, dest);
return ret;
}
eet_data_put_type(int type, void *src, int *size_ret)
{
void *ret;
-
+
ret = eet_coder[type - 1].put(src, size_ret);
return ret;
}
/* chunk format...
- *
+ *
* char[4] = "CHnK";
* int = chunk size (including magic string);
* char[] = chuck magic/name string (0 byte terminated);
* ... sub-chunks (a chunk can contain chuncks recusrively) ...
* or
* ... payload data ...
- *
+ *
*/
static Eet_Data_Chunk *
Eet_Data_Chunk *chnk;
char *s;
int ret1, ret2;
-
+
if (!src) return NULL;
if (size <= 8) return NULL;
-
+
chnk = calloc(1, sizeof(Eet_Data_Chunk));
if (!chnk) return NULL;
-
+
s = src;
if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
{
if (ret1 <= 0)
{
free(chnk);
- return NULL;
+ return NULL;
}
if ((chnk->size < 0) || ((chnk->size + 8) > size))
{
free(chnk);
- return NULL;
+ return NULL;
}
ret2 = eet_data_get_type(EET_T_STRING, (void *)(s + 8), (void *)(s + size), &(chnk->name));
if (ret2 <= 0)
{
free(chnk);
- return NULL;
+ return NULL;
}
chnk->data = (char *)src + 4 + ret1 + ret2;
chnk->size -= ret2;
eet_data_chunk_new(void *data, int size, char *name)
{
Eet_Data_Chunk *chnk;
-
+
if (!name) return NULL;
chnk = calloc(1, sizeof(Eet_Data_Chunk));
if (!chnk) return NULL;
-
+
chnk->name = strdup(name);
chnk->size = size;
chnk->data = data;
-
+
return chnk;
}
eet_data_stream_new(void)
{
Eet_Data_Stream *ds;
-
+
ds = calloc(1, sizeof(Eet_Data_Stream));
if (!ds) return NULL;
return ds;
eet_data_stream_write(Eet_Data_Stream *ds, void *data, int size)
{
char *p;
-
+
if ((ds->pos + size) > ds->size)
{
ds->data = realloc(ds->data, ds->size + size + 256);
eet_data_descriptor_free(Eet_Data_Descriptor *edd)
{
int i;
-
+
if (edd->name) free(edd->name);
for (i = 0; i < edd->elements.num; i++)
{
}
void
-eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type,
- int group_type,
- int offset,
- int count, char *counter_name,
+eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, char *name, int type,
+ int group_type,
+ int offset,
+ int count, char *counter_name,
Eet_Data_Descriptor *subtype)
{
Eet_Data_Element *ede;
-
+
edd->elements.num++;
edd->elements.set = realloc(edd->elements.set, edd->elements.num * sizeof(Eet_Data_Element));
if (!edd->elements.set) return;
void *data_dec;
void *data;
int size;
-
+
data = eet_read(ef, name, &size);
if (!data) return NULL;
data_dec = eet_data_descriptor_decode(edd, data, size);
void *data_enc;
int size;
int val;
-
+
data_enc = eet_data_descriptor_encode(edd, data, &size);
if (!data_enc) return 0;
val = eet_write(ef, name, data_enc, size, compress);
_eet_freelist_list_add(void **data)
{
int i;
-
+
for (i = 0; i < freelist_list_num; i++)
{
if (freelist_list[i] == data) return;
_eet_freelist_list_free(Eet_Data_Descriptor *edd)
{
int i;
-
+
if (freelist_list_ref > 0) return;
for (i = 0; i < freelist_list_num; i++)
edd->func.list_free(*(freelist_list[i]));
char *p;
int size;
Eet_Data_Chunk *chnk;
-
+
if (words_bigendian == -1)
{
unsigned long int v;
if (v == 0x12345678) words_bigendian = 1;
else words_bigendian = 0;
}
-
+
data = calloc(1, edd->size);
if (!data) return NULL;
_eet_freelist_ref();
{
Eet_Data_Chunk *echnk;
int i;
-
+
/* get next data chunk */
echnk = eet_data_chunk_get(p, size);
if (!echnk)
for (i = 0; i < edd->elements.num; i++)
{
Eet_Data_Element *ede;
-
+
ede = &(edd->elements.set[i]);
if (!strcmp(echnk->name, ede->name))
{
{
int ret;
void *data_ret;
-
- if ((ede->type >= EET_T_CHAR) &&
+
+ if ((ede->type >= EET_T_CHAR) &&
(ede->type <= EET_T_STRING))
{
ret = eet_data_get_type(ede->type,
else if (ede->subtype)
{
void **ptr;
-
+
data_ret = eet_data_descriptor_decode(ede->subtype,
echnk->data,
echnk->size);
void *list = NULL;
void **ptr;
void *data_ret;
-
+
ptr = (void **)(((char *)data) + ede->offset);
list = *ptr;
data_ret = NULL;
int i;
void *cdata;
int csize;
-
+
if (words_bigendian == -1)
{
unsigned long int v;
if (v == 0x12345678) words_bigendian = 1;
else words_bigendian = 0;
}
-
+
ds = eet_data_stream_new();
for (i = 0; i < edd->elements.num; i++)
{
Eet_Data_Chunk *echnk;
void *data;
int size;
-
+
ede = &(edd->elements.set[i]);
data = NULL;
if (ede->group_type == EET_G_UNKNOWN)
{
- if ((ede->type >= EET_T_CHAR) &&
+ if ((ede->type >= EET_T_CHAR) &&
(ede->type <= EET_T_STRING))
- data = eet_data_put_type(ede->type,
- ((char *)data_in) + ede->offset,
+ data = eet_data_put_type(ede->type,
+ ((char *)data_in) + ede->offset,
&size);
else if (ede->subtype)
{
if (*((char **)(((char *)data_in) + ede->offset)))
- data = eet_data_descriptor_encode(ede->subtype,
+ data = eet_data_descriptor_encode(ede->subtype,
*((char **)(((char *)data_in) + ede->offset)),
&size);
}
- if (data)
+ if (data)
{
echnk = eet_data_chunk_new(data, size, ede->name);
eet_data_chunk_put(echnk, ds);
case EET_G_LIST:
{
void *l;
-
+
l = *((void **)(((char *)data_in) + ede->offset));
for (; l; l = edd->func.list_next(l))
{
&size);
if (data)
{
- echnk = eet_data_chunk_new(data, size, ede->name);
+ echnk = eet_data_chunk_new(data, size, ede->name);
eet_data_chunk_put(echnk, ds);
eet_data_chunk_free(echnk);
free(data);
ds->data = NULL;
ds->size = 0;
eet_data_stream_free(ds);
-
+
ds = eet_data_stream_new();
eet_data_chunk_put(chnk, ds);
cdata = ds->data;
ds->size = 0;
eet_data_stream_free(ds);
*size_ret = csize;
-
+
free(chnk->data);
eet_data_chunk_free(chnk);
-
+
return cdata;
}
static void _JPEGErrorHandler(j_common_ptr cinfo);
static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
-static int eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h);
-static void *eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h);
-static void *eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h);
-static void *eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha);
-static void *eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression);
-static void *eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality);
-static void *eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality);
+static int eet_data_image_jpeg_header_decode(void *data, int size, unsigned int *w, unsigned int *h);
+static void *eet_data_image_jpeg_rgb_decode(void *data, int size, unsigned int *w, unsigned int *h);
+static void *eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, unsigned int *w, unsigned int *h);
+static void *eet_data_image_lossless_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha);
+static void *eet_data_image_lossless_compressed_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int compression);
+static void *eet_data_image_jpeg_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality);
+static void *eet_data_image_jpeg_alpha_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality);
/*---*/
_JPEGFatalErrorHandler(j_common_ptr cinfo)
{
emptr errmgr;
-
+
errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/
longjmp(errmgr->setjmp_buffer, 1);
return;
}
-
+
static void
_JPEGErrorHandler(j_common_ptr cinfo)
{
emptr errmgr;
-
+
errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
return;
}
-
+
static void
_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
{
emptr errmgr;
-
+
errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/
/* longjmp(errmgr->setjmp_buffer, 1);*/
}
static int
-eet_data_image_jpeg_header_decode(void *data, int size, int *w, int *h)
+eet_data_image_jpeg_header_decode(void *data, int size, unsigned int *w, unsigned int *h)
{
struct jpeg_decompress_struct cinfo;
struct _JPEG_error_mgr jerr;
FILE *f;
-
+
f = _eet_memfile_read_open(data, (size_t)size);
if (!f) return 0;
cinfo.err = jpeg_std_error(&(jerr.pub));
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_start_decompress(&cinfo);
-
+
/* head decoding */
*w = cinfo.output_width;
*h = cinfo.output_height;
}
static void *
-eet_data_image_jpeg_rgb_decode(void *data, int size, int *w, int *h)
+eet_data_image_jpeg_rgb_decode(void *data, int size, unsigned int *w, unsigned int *h)
{
unsigned int *d;
struct jpeg_decompress_struct cinfo;
struct _JPEG_error_mgr jerr;
unsigned char *ptr, *line[16], *tdata = NULL;
unsigned int *ptr2;
- int x, y, l, i, scans, count, prevy;
+ unsigned int x, y, l, scans;
+ int i, count, prevy;
FILE *f;
-
+
f = _eet_memfile_read_open(data, (size_t)size);
if (!f) return NULL;
cinfo.err = jpeg_std_error(&(jerr.pub));
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_start_decompress(&cinfo);
-
+
/* head decoding */
*w = cinfo.output_width;
*h = cinfo.output_height;
}
static void *
-eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, int *w, int *h)
+eet_data_image_jpeg_alpha_decode(void *data, int size, unsigned int *d, unsigned int *w, unsigned int *h)
{
struct jpeg_decompress_struct cinfo;
struct _JPEG_error_mgr jerr;
unsigned char *ptr, *line[16], *tdata = NULL;
unsigned int *ptr2;
- int x, y, l, i, scans, count, prevy;
+ unsigned int x, y, l, scans;
+ int i, count, prevy;
FILE *f;
-
+
f = _eet_memfile_read_open(data, (size_t)size);
if (!f) return NULL;
if (0)
{
char buf[1];
-
+
while (fread(buf, 1, 1, f));
_eet_memfile_read_close(f);
return d;
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_start_decompress(&cinfo);
-
+
/* head decoding */
if ((*w) != cinfo.output_width)
{
jpeg_destroy_decompress(&cinfo);
_eet_memfile_read_close(f);
- return NULL;
+ return NULL;
}
if ((*h) != cinfo.output_height)
{
jpeg_destroy_decompress(&cinfo);
_eet_memfile_read_close(f);
- return NULL;
+ return NULL;
}
*w = cinfo.output_width;
*h = cinfo.output_height;
}
static void *
-eet_data_image_lossless_convert(int *size, void *data, int w, int h, int alpha)
+eet_data_image_lossless_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha)
{
if (words_bigendian == -1)
{
{
unsigned char *d;
int *header;
-
+
d = malloc((w * h * 4) + (8 * 4));
if (!d) return NULL;
header[3] = alpha;
memcpy(d + 32, data, w * h * 4);
-
+
if (words_bigendian)
{
- int i;
-
+ unsigned int i;
+
for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]);
}
*size = ((w * h * 4) + (8 * 4));
}
static void *
-eet_data_image_lossless_compressed_convert(int *size, void *data, int w, int h, int alpha, int compression)
+eet_data_image_lossless_compressed_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int compression)
{
if (words_bigendian == -1)
{
int *header;
int ret;
uLongf buflen;
-
+
d = malloc((w * h * 4) + (8 * 4));
if (!d) return NULL;
buflen = (((w * h * 101) / 100) + 3) * 4;
header[3] = alpha;
header[4] = compression;
memcpy(d + 32, data, w * h * 4);
-
+
if (words_bigendian)
{
- int i;
-
+ unsigned int i;
+
for (i = 0; i < ((w * h) + 8); i++) SWAP32(header[i]);
}
ret = compress2((Bytef *)comp, &buflen,
}
static void *
-eet_data_image_jpeg_convert(int *size, void *data, int w, int h, int alpha, int quality)
+eet_data_image_jpeg_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality)
{
int *ptr;
void *d = NULL;
FILE *f;
unsigned char *buf;
+ (void) alpha; /* unused */
+
f =_eet_memfile_write_open(&d, &sz);
if (!f) return NULL;
-
+
buf = malloc(3 * w);
- if (!buf)
+ if (!buf)
{
_eet_memfile_write_close(f);
if (d) free(d);
return NULL;
}
-
+
cinfo.err = jpeg_std_error(&(jerr.pub));
jerr.pub.error_exit = _JPEGFatalErrorHandler;
jerr.pub.emit_message = _JPEGErrorHandler2;
ptr = data;
while (cinfo.next_scanline < cinfo.image_height)
{
- int i, j;
-
+ unsigned int i, j;
+
/* convert scaline from ARGB to RGB packed */
for (j = 0, i = 0; i < w; i++)
{
ptr++;
}
jbuf = (JSAMPROW *) (&buf);
- jpeg_write_scanlines(&cinfo, jbuf, 1);
+ jpeg_write_scanlines(&cinfo, jbuf, 1);
}
-
+
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
-
+
_eet_memfile_write_close(f);
*size = sz;
- if (buf) free(buf);
+ if (buf) free(buf);
return d;
}
static void *
-eet_data_image_jpeg_alpha_convert(int *size, void *data, int w, int h, int alpha, int quality)
+eet_data_image_jpeg_alpha_convert(int *size, void *data, unsigned int w, unsigned int h, int alpha, int quality)
{
unsigned char *d1, *d2;
unsigned char *d;
int *header;
int sz1, sz2;
+ (void) alpha; /* unused */
+
if (words_bigendian == -1)
{
unsigned long int v;
if (v == 0x12345678) words_bigendian = 1;
else words_bigendian = 0;
}
-
+
{
int *ptr;
void *d = NULL;
struct jpeg_compress_struct cinfo;
FILE *f;
unsigned char *buf;
-
+
f = _eet_memfile_write_open(&d, &sz);
if (!f) return NULL;
-
+
buf = malloc(3 * w);
- if (!buf)
+ if (!buf)
{
_eet_memfile_write_close(f);
if (d) free(d);
return NULL;
}
-
+
cinfo.err = jpeg_std_error(&(jerr.pub));
jerr.pub.error_exit = _JPEGFatalErrorHandler;
jerr.pub.emit_message = _JPEGErrorHandler2;
cinfo.comp_info[2].v_samp_factor = 1;
}
jpeg_start_compress(&cinfo, TRUE);
-
+
ptr = data;
while (cinfo.next_scanline < cinfo.image_height)
{
- int i, j;
-
+ unsigned int i, j;
+
/* convert scaline from ARGB to RGB packed */
for (j = 0, i = 0; i < w; i++)
{
ptr++;
}
jbuf = (JSAMPROW *) (&buf);
- jpeg_write_scanlines(&cinfo, jbuf, 1);
+ jpeg_write_scanlines(&cinfo, jbuf, 1);
}
-
+
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
-
- if (buf) free(buf);
+
+ if (buf) free(buf);
_eet_memfile_write_close(f);
d1 = d;
sz1 = sz;
struct jpeg_compress_struct cinfo;
FILE *f;
unsigned char *buf;
-
+
f = _eet_memfile_write_open(&d, &sz);
- if (!f)
+ if (!f)
{
free(d1);
return NULL;
}
-
+
buf = malloc(3 * w);
- if (!buf)
+ if (!buf)
{
_eet_memfile_write_close(f);
if (d) free(d);
free(d1);
return NULL;
}
-
+
cinfo.err = jpeg_std_error(&(jerr.pub));
jerr.pub.error_exit = _JPEGFatalErrorHandler;
jerr.pub.emit_message = _JPEGErrorHandler2;
cinfo.comp_info[2].v_samp_factor = 1;
}
jpeg_start_compress(&cinfo, TRUE);
-
+
ptr = data;
while (cinfo.next_scanline < cinfo.image_height)
{
- int i, j;
-
+ unsigned int i, j;
+
/* convert scaline from ARGB to RGB packed */
for (j = 0, i = 0; i < w; i++)
{
ptr++;
}
jbuf = (JSAMPROW *) (&buf);
- jpeg_write_scanlines(&cinfo, jbuf, 1);
+ jpeg_write_scanlines(&cinfo, jbuf, 1);
}
-
+
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
-
- if (buf) free(buf);
+
+ if (buf) free(buf);
_eet_memfile_write_close(f);
d2 = d;
sz2 = sz;
if (words_bigendian)
{
int i;
-
+
for (i = 0; i < 3; i++) SWAP32(header[i]);
}
memcpy(d + 12, d1, sz1);
memcpy(d + 12 + sz1, d2, sz2);
-
+
free(d1);
free(d2);
*size = 12 + sz1 + sz2;
- return d;
+ return d;
}
int
eet_data_image_write(Eet_File *ef, char *name,
- void *data, int w, int h, int alpha,
+ void *data, unsigned int w, unsigned int h, int alpha,
int compress, int quality, int lossy)
{
void *d = NULL;
if (d)
{
int v;
-
+
v = eet_write(ef, name, d, size, 0);
free(d);
return v;
void *
eet_data_image_read(Eet_File *ef, char *name,
- int *w, int *h, int *alpha,
+ unsigned int *w, unsigned int *h, int *alpha,
int *compress, int *quality, int *lossy)
{
void *data;
int size;
unsigned int *d = NULL;
-
+
data = eet_read(ef, name, &size);
if (!data) return NULL;
d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
int
eet_data_image_header_read(Eet_File *ef, char *name,
- int *w, int *h, int *alpha,
+ unsigned int *w, unsigned int *h, int *alpha,
int *compress, int *quality, int *lossy)
{
void *data;
int size;
int d;
-
+
data = eet_read(ef, name, &size);
if (!data) return 0;
d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy);
}
void *
-eet_data_image_encode(void *data, int *size_ret, int w, int h, int alpha, int compress, int quality, int lossy)
+eet_data_image_encode(void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy)
{
void *d = NULL;
int size = 0;
-
+
if (lossy == 0)
{
if (compress <= 0)
}
int
-eet_data_image_header_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy)
+eet_data_image_header_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
{
int header[8];
-
+
if (words_bigendian == -1)
{
unsigned long int v;
if (v == 0x12345678) words_bigendian = 1;
else words_bigendian = 0;
}
-
+
if (size < 32) return 0;
memcpy(header, data, 32);
if (words_bigendian)
{
int i;
-
- for (i = 0; i < 8; i++) SWAP32(header[i]);
+
+ for (i = 0; i < 8; i++) SWAP32(header[i]);
}
- if (header[0] == 0xac1dfeed)
+ if ((unsigned)header[0] == 0xac1dfeed)
{
int iw, ih, al, cp;
-
+
iw = header[1];
ih = header[2];
al = header[3];
if (quality) *quality = 100;
return 1;
}
- else if (header[0] == 0xbeeff00d)
+ else if ((unsigned)header[0] == 0xbeeff00d)
{
- int iw = 0, ih = 0;
- int sz1, sz2;
+ unsigned int iw = 0, ih = 0;
unsigned char *dt;
+ int sz1, sz2;
int ok;
-
+
sz1 = header[1];
sz2 = header[2];
dt = data;
}
else
{
- int iw = 0, ih = 0;
+ unsigned int iw = 0, ih = 0;
int ok;
-
+
ok = eet_data_image_jpeg_header_decode(data, size, &iw, &ih);
if (ok)
{
}
void *
-eet_data_image_decode(void *data, int size, int *w, int *h, int *alpha, int *compress, int *quality, int *lossy)
+eet_data_image_decode(void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy)
{
unsigned int *d = NULL;
int header[8];
-
+
if (words_bigendian == -1)
{
unsigned long int v;
if (v == 0x12345678) words_bigendian = 1;
else words_bigendian = 0;
}
-
+
if (size < 32) return NULL;
memcpy(header, data, 32);
if (words_bigendian)
{
int i;
-
- for (i = 0; i < 8; i++) SWAP32(header[i]);
+
+ for (i = 0; i < 8; i++) SWAP32(header[i]);
}
- if (header[0] == 0xac1dfeed)
+ if ((unsigned)header[0] == 0xac1dfeed)
{
int iw, ih, al, cp;
unsigned int *body;
-
+
iw = header[1];
ih = header[2];
al = header[3];
if ((cp == 0) && (size < ((iw * ih * 4) + 32))) return NULL;
body = ((unsigned int *)data) + 8;
d = malloc(iw * ih * 4);
- if (!d) return NULL;
+ if (!d) return NULL;
if (!cp)
{
memcpy(d, body, iw * ih * 4);
if (words_bigendian)
{
int x;
-
+
for (x = 0; x < (iw * ih); x++) SWAP32(d[x]);
}
}
else
{
uLongf dlen;
-
+
dlen = iw * ih * 4;
uncompress((Bytef *)d, &dlen, (Bytef *)body,
(uLongf)(size - 32));
if (words_bigendian)
{
int x;
-
+
for (x = 0; x < (iw * ih); x++) SWAP32(d[x]);
}
}
if (compress) *compress = cp;
if (lossy) *lossy = 0;
if (quality) *quality = 100;
- }
+ }
}
- else if (header[0] == 0xbeeff00d)
+ else if ((unsigned)header[0] == 0xbeeff00d)
{
- int iw = 0, ih = 0;
- int sz1, sz2;
+ unsigned int iw = 0, ih = 0;
unsigned char *dt;
-
+ int sz1, sz2;
+
sz1 = header[1];
sz2 = header[2];
dt = data;
}
else
{
- int iw = 0, ih = 0;
-
+ unsigned int iw = 0, ih = 0;
+
d = eet_data_image_jpeg_rgb_decode(data, size, &iw, &ih);
if (d)
{
#define EET_MAGIC_FILE_HEADER 0x1ee7ff01
#define EET_MAGIC_FILE_NODE 0x1ee7ff02
#define EET_MAGIC_FILE_DIRECTORY 0x1ee7ff03
-#define EET_MAGIC_FILE_DIRECTORY_HASH 0x1ee7ff04
+#define EET_MAGIC_FILE_DIRECTORY_HASH 0x1ee7ff04
typedef struct _Eet_File_Header Eet_File_Header;
typedef struct _Eet_File_Node Eet_File_Node;
{
int magic;
int references;
-
+
char *path;
char *real_path;
-
+
FILE *fp;
Eet_File_Mode mode;
-
+
int writes_pending : 1;
-
+
Eet_File_Header *header;
};
int magic; /* magic number ie 0x1ee7ff00 */
int num_directory_entries; /* number of directory entries to follow */
int bytes_directory_entries; /* bytes of directory entries to follow */
-struct
+struct
{
int offset; /* bytes offset into file for data chunk */
int flags; /* flags - for now 0 = uncompressed, 1 = compressed */
char name[name_size]; /* name string (variable length) */
} directory[num_directory_entries];
/* and now startes the data stream... */
-#endif
+#endif
/* prototypes of internal calls */
static Eet_File *eet_cache_find(char *real_path, Eet_File **cache, int cache_num);
eet_cache_find(char *real_path, Eet_File **cache, int cache_num)
{
int i;
-
+
/* walk list */
for (i = 0; i < cache_num; i++)
{
{
Eet_File **new_cache;
int new_cache_num;
-
+
new_cache_num = *cache_num;
new_cache = *cache;
new_cache_num++;
if (!new_cache) return;
new_cache[new_cache_num - 1] = ef;
*cache = new_cache;
- *cache_num = new_cache_num;
+ *cache_num = new_cache_num;
}
/* delete from cache */
return;
}
new_cache_num--;
- for (j = i; j < new_cache_num; j++) new_cache[j] = new_cache[j + 1];
+ for (j = i; j < new_cache_num; j++) new_cache[j] = new_cache[j + 1];
if (new_cache_num > 0)
{
new_cache = realloc(new_cache, new_cache_num * sizeof(Eet_File *));
free(new_cache);
new_cache = NULL;
}
- *cache_num = new_cache_num;
+ *cache_num = new_cache_num;
*cache = new_cache;
}
if (*s1 != *s2) return 0;
s1++;
s2++;
- }
+ }
while ((*s1) || (*s2));
/* got this far. match */
return 1;
0x7f,
0xff
};
-
+
/* no string - index 0 */
if (!key) return 0;
-
+
/* calc hash num */
- for (ptr = key; *ptr; ptr++) hash_num ^= (int)(*ptr);
-
+ for (ptr = (unsigned char *)key; *ptr; ptr++)
+ hash_num ^= (int)(*ptr);
+
/* mask it */
hash_num &= masks[hash_size];
/* return it */
int i, j, count, size, num, offset;
int head[3];
unsigned long int i1, i2;
-
- /* check to see its' an eet file pointer */
+
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE))
return;
if (!ef->header) return;
for (j = 0; j < ef->header->directory->hash[i].size; j++)
{
if (ef->header->directory->hash[i].node[j].compression >= 0)
- {
+ {
size += 20 + strlen(ef->header->directory->hash[i].node[j].name);
count++;
}
i2 = htonl(i1);
*((int *)(buf + 16)) = (int)i2;
memcpy(buf + 20, ef->header->directory->hash[i].node[j].name, name_size);
- if (fwrite(buf, buf_size, 1, ef->fp) != 1)
+ if (fwrite(buf, buf_size, 1, ef->fp) != 1)
{
free(buf);
return;
{
if (ef->header->directory->hash[i].node[j].compression >= 0)
{
- if (fwrite(ef->header->directory->hash[i].node[j].data,
+ if (fwrite(ef->header->directory->hash[i].node[j].data,
ef->header->directory->hash[i].node[j].size,
1, ef->fp) != 1)
return;
// printf("open %s\n", file);
#ifdef HAVE_REALPATH
/* in case this is a symlink... find out where it REALLY points */
- if (!realpath(file, buf))
+ if (!realpath(file, buf))
{
if (mode == EET_FILE_MODE_READ) return NULL;
}
ef->references++;
return ef;
}
-
+
/* allocate struct for eet file and have it zero'd out */
ef = calloc(sizeof(Eet_File), 1);
if (!ef) return NULL;
-
+
/* fill some of the members */
ef->path = strdup(file);
ef->real_path = strdup(buf);
eet_close(ef);
return NULL;
}
-
+
/* if we can't open - bail out */
if (!ef->fp)
{
eet_close(ef);
return NULL;
}
-
+
/* if we opened for read or read-write */
if ((mode == EET_FILE_MODE_READ) || (mode == EET_FILE_MODE_READ_WRITE))
{
unsigned long int i1, i2;
int num_entries, byte_entries, i;
size_t count;
-
+
/* build header table if read mode */
/* geat header */
count = fread(buf, 12, 1, ef->fp);
if (count != 1)
{
eet_close(ef);
- return NULL;
+ return NULL;
}
/* get magic no */
memcpy(&i1, buf + 0, sizeof(int));
if (i2 != EET_MAGIC_FILE)
{
eet_close(ef);
- return NULL;
+ return NULL;
}
/* get entries count and byte count */
memcpy(&i1, buf + 4, sizeof(int));
if ((num_entries <= 0) || (byte_entries <= 0))
{
eet_close(ef);
- return NULL;
+ return NULL;
}
/* we can't have more entires than minimum bytes for those! invalid! */
if ((num_entries * 20) > byte_entries)
{
eet_close(ef);
- return NULL;
+ return NULL;
}
/* allocate dynamic buffer for entire directory block */
dyn_buf = malloc(byte_entries);
if (!dyn_buf)
{
eet_close(ef);
- return NULL;
+ return NULL;
}
/* allocate header */
ef->header = calloc(sizeof(Eet_File_Header), 1);
Eet_File_Node *node;
int node_size;
void *data = NULL;
-
+
/* out directory block is inconsistent - we have oveerun our */
- /* dynamic block buffer before we finished scanning dir entries */
+ /* dynamic block buffer before we finished scanning dir entries */
if (p >= (dyn_buf + byte_entries))
{
free(dyn_buf);
{
free(dyn_buf);
eet_close(ef);
- return NULL;
+ return NULL;
}
/* invalid name_size */
if (name_size <= 0)
{
free(dyn_buf);
eet_close(ef);
- return NULL;
+ return NULL;
}
/* reading name would mean falling off end of dyn_buf - invalid */
if ((p + 16 + name_size) > (dyn_buf + byte_entries))
{
free(dyn_buf);
eet_close(ef);
- return NULL;
+ return NULL;
}
/* allocate name string */
name = malloc(name_size + 1);
{
free(dyn_buf);
eet_close(ef);
- return NULL;
+ return NULL;
}
/* copy name in and terminate it */
- strncpy(name, p + 20, name_size);
+ strncpy(name, (char *)p + 20, name_size);
name[name_size] = 0;
/* get hask bucket it should go in */
hash = eet_hash_gen(name, ef->header->directory->size);
/* resize hask bucket */
- node = realloc(ef->header->directory->hash[hash].node,
- (ef->header->directory->hash[hash].size + 1) *
+ node = realloc(ef->header->directory->hash[hash].node,
+ (ef->header->directory->hash[hash].size + 1) *
sizeof(Eet_File_Node));
if (!node)
{
break;
}
}
-
+
ef->header->directory->hash[hash].node[node_size].data = data;
}
Eet_File_Mode
eet_mode_get(Eet_File *ef)
{
- /* check to see its' an eet file pointer */
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE))
return EET_FILE_MODE_INVALID;
else
void
eet_close(Eet_File *ef)
{
- /* check to see its' an eet file pointer */
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE))
return;
/* deref */
if (ef->real_path) free(ef->real_path);
/* free up data */
- if (ef->header)
+ if (ef->header)
{
if (ef->header->directory)
{
if (ef->header->directory->hash)
{
int i, num;
-
+
num = (1 << (ef->header->directory->size - 1));
for (i = 0; i < num; i++)
{
{
int j;
int num2;
-
+
num2 = ef->header->directory->hash[i].size;
for (j = 0; j < num2; j++)
{
}
free(ef->header);
}
-
+
/* zero out ram for struct - caution tactic against stale memory use */
memset(ef, 0, sizeof(Eet_File));
/* free it */
{
/* if we alreayd have the data in ram... copy that */
if (ef->header->directory->hash[hash].node[i].data)
- memcpy(data,
- ef->header->directory->hash[hash].node[i].data,
+ memcpy(data,
+ ef->header->directory->hash[hash].node[i].data,
ef->header->directory->hash[hash].node[i].size);
/* or get data from disk */
else
else
{
void *tmp_data;
-
+
/* get size of data in file */
tmp_size = ef->header->directory->hash[hash].node[i].size;
tmp_data = malloc(tmp_size);
if (data)
{
uLongf dlen;
-
+
/* if we already have the data in ram... copy that */
if (ef->header->directory->hash[hash].node[i].data)
- memcpy(tmp_data,
- ef->header->directory->hash[hash].node[i].data,
+ memcpy(tmp_data,
+ ef->header->directory->hash[hash].node[i].data,
tmp_size);
/* or get data from disk */
else
}
/* decompress it */
dlen = size;
- if (uncompress((Bytef *)data, &dlen,
+ if (uncompress((Bytef *)data, &dlen,
tmp_data, (uLongf)tmp_size))
{
free(tmp_data);
char *name2;
void *data2;
int exists_already = 0;
-
- /* check to see its' an eet file pointer */
+
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE)
- || (!name) || (!data) || (size <= 0) ||
+ || (!name) || (!data) || (size <= 0) ||
((ef->mode != EET_FILE_MODE_WRITE) &&
(ef->mode != EET_FILE_MODE_READ_WRITE)))
-
+
return 0;
if (!ef->header)
{
uLongf buflen;
int ok;
-
+
/* compress the data with max compression */
buflen = (uLongf)data_size;
- if ((ok = compress2((Bytef *)data2, &buflen, (Bytef *)data,
+ if ((ok = compress2((Bytef *)data2, &buflen, (Bytef *)data,
(uLong)size, 9)) != Z_OK)
{
free(name2);
}
/* record compressed chunk size */
data_size = (int)buflen;
- if (data_size >= size)
+ if (data_size >= size)
{
compress = 0;
data_size = size;
else
{
void *data3;
-
+
data3 = realloc(data2, data_size);
if (data3) data2 = data3;
}
if (!exists_already)
{
/* increase hash bucket size */
- node = realloc(ef->header->directory->hash[hash].node,
+ node = realloc(ef->header->directory->hash[hash].node,
(node_size + 1) * sizeof(Eet_File_Node));
- if (!node)
+ if (!node)
{
free(name2);
free(data2);
{
int hash, node_size, i;
int exists_already = 0;
-
- /* check to see its' an eet file pointer */
+
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE) || (!name))
return 0;
if (ef->mode != EET_FILE_MODE_READ_WRITE) return 0;
if (!ef->header) return 0;
-
+
/* figure hash bucket */
hash = eet_hash_gen(name, ef->header->directory->size);
node_size = ef->header->directory->hash[hash].size;
-
+
/* Does this node already exist? */
for (i = 0; i < node_size; i++)
{
int list_count_alloc = 0;
int i, j, num;
- /* check to see its' an eet file pointer */
+ /* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE) || (!glob) ||
(!ef->header) || (!ef->header->directory) ||
((ef->mode != EET_FILE_MODE_READ) &&
if (!fnmatch(glob, ef->header->directory->hash[i].node[j].name, 0))
{
char **new_list;
-
+
/* add it to our list */
list_count++;
/* only realloc in 32 entry chunks */
{
free(list_ret);
if (count_ret) *count_ret = 0;
- return NULL;
+ return NULL;
}
list_ret = new_list;
}
}
}
/* return count and list */
- if (count_ret) *count_ret = list_count;
+ if (count_ret) *count_ret = list_count;
return list_ret;
}
return (FILE *)fmemopen(data, size, "rb");
#else
FILE *f;
-
+
f = tmpfile();
if (!f)
{
fclose(f);
#else
fclose(f);
-#endif
+#endif
}
{
#ifdef HAVE_OPEN_MEMSTREAM
return open_memstream((char **)data, size);
-#else
+#else
FILE *f;
-
+
_eet_memfile_info_num++;
if (_eet_memfile_info_num > _eet_memfile_info_alloc_num)
{
Eet_Memfile_Write_Info *tmp;
-
+
_eet_memfile_info_alloc_num += 16;
- tmp = realloc(_eet_memfile_info,
- _eet_memfile_info_alloc_num *
+ tmp = realloc(_eet_memfile_info,
+ _eet_memfile_info_alloc_num *
sizeof(Eet_Memfile_Write_Info));
if (!tmp)
{
_eet_memfile_info = tmp;
}
f = tmpfile();
- if (!f)
+ if (!f)
{
_eet_memfile_info_num--;
return NULL;
_eet_memfile_write_close(FILE *f)
{
#ifdef HAVE_OPEN_MEMSTREAM
- fclose(f);
+ fclose(f);
#else
int i;
-
+
for (i = 0; i < _eet_memfile_info_num; i++)
{
if (_eet_memfile_info[i].f == f)