/***************************************************************************/
- enum _Eet_File_Mode
+ typedef enum _Eet_File_Mode
{
EET_FILE_MODE_INVALID = -1,
EET_FILE_MODE_READ,
EET_FILE_MODE_WRITE,
EET_FILE_MODE_READ_WRITE
- };
+ } Eet_File_Mode;
- typedef enum _Eet_File_Mode Eet_File_Mode;
+ typedef enum _Eet_Error
+ {
+ EET_ERROR_NONE,
+ EET_ERROR_BAD_OBJECT,
+ EET_ERROR_EMPTY,
+ EET_ERROR_NOT_WRITABLE,
+ EET_ERROR_WRITE_ERROR,
+ EET_ERROR_WRITE_ERROR_FILE_TOO_BIG,
+ EET_ERROR_WRITE_ERROR_IO_ERROR,
+ EET_ERROR_WRITE_ERROR_OUT_OF_SPACE,
+ EET_ERROR_WRITE_ERROR_FILE_CLOSED
+ } Eet_Error;
typedef struct _Eet_File Eet_File;
typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
* }
* @endcode
*/
- EAPI Eet_File *eet_open (const char *file, Eet_File_Mode mode);
+ EAPI Eet_File *eet_open(const char *file, Eet_File_Mode mode);
/**
* Get the mode an Eet_File was opened with.
* @param ef A valid eet file handle.
* @return The mode ef was opened with.
*/
- EAPI Eet_File_Mode eet_mode_get (Eet_File *ef);
+ EAPI Eet_File_Mode eet_mode_get(Eet_File *ef);
/**
* Close an eet file handle and flush and writes pending.
*
* If the eet file handle is not valid nothing will be done.
*/
- EAPI void eet_close (Eet_File *ef);
+ EAPI Eet_Error eet_close(Eet_File *ef);
/**
* Read a specified entry from an eet file and return data
* If the eet file handle is not valid NULL is returned and size_ret is
* filled with 0.
*/
- EAPI void *eet_read (Eet_File *ef, const char *name, int *size_ret);
+ EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret);
/**
* Write a specified entry to an eet file handle
* a flush to disk (it will stay in ram till the eet file handle is
* closed though).
*/
- EAPI int eet_write (Eet_File *ef, const char *name, const void *data, int size, int compress);
+ EAPI int eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress);
/**
* Delete a specified entry from an Eet file being written or re-written
*
* Name, must not be NULL, otherwise 0 will be returned.
*/
- EAPI int eet_delete(Eet_File *ef, const char *name);
+ EAPI int eet_delete(Eet_File *ef, const char *name);
/**
* List all entries in eet file matching shell glob.
* Hint: an easy way to list all entries in an eet file is to use a glob
* value of "*".
*/
- EAPI char **eet_list (Eet_File *ef, const char *glob, int *count_ret);
+ EAPI char **eet_list(Eet_File *ef, const char *glob, int *count_ret);
/**
* Return the number of entries in the specified eet file.
* @return Number of entries in ef or -1 if the number of entries
* cannot be read due to open mode restrictions.
*/
- EAPI int eet_num_entries(Eet_File *ef);
+ EAPI int eet_num_entries(Eet_File *ef);
/***************************************************************************/
* 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, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI int eet_data_image_header_read(Eet_File *ef, const 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.
* 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, const char *name, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI void *eet_data_image_read(Eet_File *ef, const 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.
* 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, const char *name, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
+ EAPI int eet_data_image_write(Eet_File *ef, const char *name, const void *data, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
/**
* Decode Image data header only to get information.
* 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(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI int eet_data_image_header_decode(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
/**
* Decode Image data into pixel 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(const void *data, int size, unsigned int *w, unsigned int *h, int *alpha, int *compress, int *quality, int *lossy);
+ EAPI void *eet_data_image_decode(const 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.
* 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(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
+ EAPI void *eet_data_image_encode(const void *data, int *size_ret, unsigned int w, unsigned int h, int alpha, int compress, int quality, int lossy);
/***************************************************************************/
* call the descriptor is no longer valid.
*
*/
- EAPI void eet_data_descriptor_free(Eet_Data_Descriptor *edd);
+ EAPI void eet_data_descriptor_free(Eet_Data_Descriptor *edd);
/**
* This function is an internal used by macros.
* thus is not documented.
*
*/
- EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, const char *name, int type, int group_type, int offset, int count, const char *counter_name, Eet_Data_Descriptor *subtype);
+ EAPI void eet_data_descriptor_element_add(Eet_Data_Descriptor *edd, const char *name, int type, int group_type, int offset, int count, const char *counter_name, Eet_Data_Descriptor *subtype);
/**
* Read a data structure from an eet file and decodes it.
* to an eet file.
*
*/
- EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress);
+ EAPI int eet_data_write(Eet_File *ef, Eet_Data_Descriptor *edd, const char *name, const void *data, int compress);
/**
* Decode a data structure from an arbitary location in memory.
static void eet_cache_del(Eet_File *ef, Eet_File ***cache, int *cache_num, int *cache_alloc);
static int eet_string_match(const char *s1, const char *s2);
static int eet_hash_gen(const char *key, int hash_size);
-static void eet_flush(Eet_File *ef);
+static Eet_Error eet_flush(Eet_File *ef);
static Eet_File_Node *find_node_by_name (Eet_File *ef, const char *name);
static int read_data_from_disk(Eet_File *ef, Eet_File_Node *efn, void *buf, int len);
}
/* flush out writes to an eet file */
-static void
+static Eet_Error
eet_flush(Eet_File *ef)
{
int i, count, size, num, offset;
/* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE))
- return;
- if (!ef->header) return;
- if (!ef->header->directory) return;
- if ((ef->mode != EET_FILE_MODE_WRITE) && (ef->mode != EET_FILE_MODE_READ_WRITE)) return;
- if (!ef->writes_pending) return;
+ return EET_ERROR_BAD_OBJECT;
+ if (!ef->header) return EET_ERROR_EMPTY;
+ if (!ef->header->directory) return EET_ERROR_EMPTY;
+ if ((ef->mode != EET_FILE_MODE_WRITE) && (ef->mode != EET_FILE_MODE_READ_WRITE)) return EET_ERROR_NOT_WRITABLE;
+ if (!ef->writes_pending) return EET_ERROR_NONE;
/* calculate total size in bytes of directory block */
size = 0;
i2 = htonl(i1);
*((int *)(buf + 16)) = (int)i2;
memcpy(buf + 20, efn->name, name_size);
- if (fwrite(buf, buf_size, 1, ef->fp) != 1) return;
+ if (fwrite(buf, buf_size, 1, ef->fp) != 1)
+ {
+ write_error:
+ switch (ferror(ef->fp))
+ {
+ case EFBIG:
+ return EET_ERROR_WRITE_ERROR_FILE_TOO_BIG;
+ case EIO:
+ return EET_ERROR_WRITE_ERROR_IO_ERROR;
+ case ENOSPC:
+ return EET_ERROR_WRITE_ERROR_OUT_OF_SPACE;
+ case EPIPE:
+ return EET_ERROR_WRITE_ERROR_FILE_CLOSED;
+ default:
+ return EET_ERROR_WRITE_ERROR;
+ }
+ return EET_ERROR_WRITE_ERROR;
+ }
offset += buf_size;
}
}
if (efn->compression >= 0)
{
if (fwrite(efn->data, efn->size, 1, ef->fp) != 1)
- return;
+ goto write_error;
}
}
}
/* no more writes pending */
ef->writes_pending = 0;
+ return EET_ERROR_NONE;
}
EAPI int
return ef->mode;
}
-EAPI void
+EAPI Eet_Error
eet_close(Eet_File *ef)
{
+ Eet_Error err;
+
/* check to see its' an eet file pointer */
if ((!ef) || (ef->magic != EET_MAGIC_FILE))
- return;
+ return EET_ERROR_BAD_OBJECT;
/* deref */
ef->references--;
/* if its still referenced - dont go any further */
- if (ef->references > 0) return;
+ if (ef->references > 0) return EET_ERROR_NONE;
/* if we are in cacheburst mode - dont free it - leave it in cache */
if (eet_cacheburst_mode)
{
- if (!ef->delete_me_now) return;
+ if (!ef->delete_me_now) return EET_ERROR_NONE;
}
/* remove from cache */
if (ef->mode == EET_FILE_MODE_READ)
else if ((ef->mode == EET_FILE_MODE_WRITE) || (ef->mode == EET_FILE_MODE_READ_WRITE))
eet_cache_del(ef, &eet_writers, &eet_writers_num, &eet_writers_alloc);
/* flush any writes */
- eet_flush(ef);
+ err = eet_flush(ef);
/* free up members */
if (ef->fp) fclose(ef->fp);
memset(ef, 0, sizeof(Eet_File));
/* free it */
free(ef);
+ return err;
}
EAPI void *