Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/eet

Dir     : e17/libs/eet/src/lib


Modified Files:
        Eet.h Eet_private.h eet_lib.c 


Log Message:


return write errors on close.

===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/Eet.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -3 -r1.31 -r1.32
--- Eet.h       4 Mar 2006 02:46:23 -0000       1.31
+++ Eet.h       20 May 2006 02:44:24 -0000      1.32
@@ -61,15 +61,26 @@
 
 /***************************************************************************/
 
-   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;
@@ -183,14 +194,14 @@
     * }
     * @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.
@@ -202,7 +213,7 @@
     *
     * 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
@@ -221,7 +232,7 @@
     * 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
@@ -246,7 +257,7 @@
     * 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
@@ -263,7 +274,7 @@
     *
     * 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.
@@ -292,7 +303,7 @@
     * 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.
@@ -300,7 +311,7 @@
     * @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);
 
 /***************************************************************************/
 
@@ -335,7 +346,7 @@
     * 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.
@@ -370,7 +381,7 @@
     * 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.
@@ -402,7 +413,7 @@
     * 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.
@@ -435,7 +446,7 @@
     * 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.
@@ -470,7 +481,7 @@
     * 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.
@@ -501,7 +512,7 @@
     * 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);
 
 /***************************************************************************/
 
@@ -694,7 +705,7 @@
     * 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.
@@ -705,7 +716,7 @@
     * 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.
@@ -745,7 +756,7 @@
     * 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.
===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/Eet_private.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- Eet_private.h       4 Mar 2006 02:46:23 -0000       1.10
+++ Eet_private.h       20 May 2006 02:44:24 -0000      1.11
@@ -11,6 +11,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
 #if HAVE_ALLOCA_H
 #include <alloca.h>
 #endif
===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/eet_lib.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -3 -r1.60 -r1.61
--- eet_lib.c   4 Mar 2006 02:46:24 -0000       1.60
+++ eet_lib.c   20 May 2006 02:44:24 -0000      1.61
@@ -79,7 +79,7 @@
 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);
 
@@ -253,7 +253,7 @@
 }
 
 /* flush out writes to an eet file */
-static void
+static Eet_Error
 eet_flush(Eet_File *ef)
 {
    int i, count, size, num, offset;
@@ -263,11 +263,11 @@
 
    /* 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;
@@ -340,7 +340,24 @@
                  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;
               }
          }
@@ -353,12 +370,13 @@
             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
@@ -721,20 +739,22 @@
      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)
@@ -742,7 +762,7 @@
    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);
@@ -779,6 +799,7 @@
    memset(ef, 0, sizeof(Eet_File));
    /* free it */
    free(ef);
+   return err;
 }
 
 EAPI void *




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to