---
name: "Eet_File_Group"
section: "3"
platform: "linux"
package: "libeet-doc"
version: "1.3.2-1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/Eet_File_Group"
---

# Eet\_File\_Group(3)

Functions to create, destroy and do basic manipulation of Eet\_File handles.

## NAME

Eet File Main Functions -

Functions to create, destroy and do basic manipulation of **Eet\_File** handles.

### Modules

**Eet File Ciphered Main Functions**\

*Most of the* **Eet File Main Functions** *have alternative versions that accounts for ciphers to protect their content.*

### Typedefs

typedef enum **\_Eet\_File\_Mode** **Eet\_File\_Mode**\
 *Modes that a file can be opened.*  typedef struct \_Eet\_File **Eet\_File**\
 *Opaque handle that defines an Eet file (or memory).*  typedef struct \_Eet\_Dictionary **Eet\_Dictionary**\
 *Opaque handle that defines a file-backed (mmaped) dictionary of strings.*

### Enumerations

enum **\_Eet\_File\_Mode** { , **EET\_FILE\_MODE\_READ**, **EET\_FILE\_MODE\_WRITE**, **EET\_FILE\_MODE\_READ\_WRITE** }\
 *Modes that a file can be opened.*

### Functions

EAPI **Eet\_File** \* **eet\_open** (const char \*file, **Eet\_File\_Mode** mode)\
 *Open an eet file on disk, and returns a handle to it.*  EAPI **Eet\_File** \* **eet\_memopen\_read** (const void \*data, size\_t size)\
 *Open an eet file directly from a memory location.*  EAPI **Eet\_File\_Mode** **eet\_mode\_get** (**Eet\_File** \*ef)\
 *Get the mode an Eet\_File was opened with.*  EAPI **Eet\_Error** **eet\_close** (**Eet\_File** \*ef)\
 *Close an eet file handle and flush and writes pending.*  EAPI **Eet\_Error** **eet\_sync** (**Eet\_File** \*ef)\
 *Sync content of an eet file handle, flushing pending writes.*  EAPI **Eet\_Dictionary** \* **eet\_dictionary\_get** (**Eet\_File** \*ef)\
 *Return a handle to the shared string dictionary of the Eet file.*  EAPI int **eet\_dictionary\_string\_check** (**Eet\_Dictionary** \*ed, const char \*string)\
 *Check if a given string comes from a given dictionary.*  EAPI void \* **eet\_read** (**Eet\_File** \*ef, const char \*name, int \*size\_ret)\
 *Read a specified entry from an eet file and return data.*  EAPI const void \* **eet\_read\_direct** (**Eet\_File** \*ef, const char \*name, int \*size\_ret)\
 *Read a specified entry from an eet file and return data.*  EAPI int **eet\_write** (**Eet\_File** \*ef, const char \*name, const void \*data, int size, int compress)\
 *Write a specified entry to an eet file handle.*  EAPI int **eet\_delete** (**Eet\_File** \*ef, const char \*name)\
 *Delete a specified entry from an Eet file being written or re-written.*  EAPI char \*\* **eet\_list** (**Eet\_File** \*ef, const char \*glob, int \*count\_ret)\
 *List all entries in eet file matching shell glob.*  EAPI int **eet\_num\_entries** (**Eet\_File** \*ef)\
 *Return the number of entries in the specified eet file.*

## Detailed Description

Functions to create, destroy and do basic manipulation of **Eet\_File** handles.

## Typedef Documentation

### Eet\_File

Opaque handle that defines an Eet file (or memory). **See also:**

**eet\_open()**

**eet\_memopen\_read()**

**eet\_close()**

### typedef enum \_Eet\_File\_Mode Eet\_File\_Mode

Modes that a file can be opened.

## Enumeration Type Documentation

### enum \_Eet\_File\_Mode

Modes that a file can be opened.

**Enumerator:**

- *EET\_FILE\_MODE\_READ*

  *File is read-only.*

- *EET\_FILE\_MODE\_WRITE*

  *File is write-only.*

- *EET\_FILE\_MODE\_READ\_WRITE*

  *File is for both read and write.*

## Function Documentation

### EAPI Eet\_Error eet\_close (Eet\_File \* ef)

*Close an eet file handle and flush and writes pending.* **Parameters:**

*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.*

**Since:**

*1.0.0*

### EAPI int eet\_delete (Eet\_File \* ef, const char \* name)

*Delete a specified entry from an Eet file being written or re-written.* **Parameters:**

*ef A valid eet file handle opened for writing.* \
 *name Name of the entry. eg: '/base/file\_i\_want'.*

**Returns:**

*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 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.*

**Since:**

*1.0.0*

*References EET\_FILE\_MODE\_READ.*

### EAPI Eet\_Dictionary\* eet\_dictionary\_get (Eet\_File \* ef)

*Return a handle to the shared string dictionary of the Eet file.* **Parameters:**

*ef A valid eet file handle.*

**Returns:**

*A handle to the dictionary of the file*

*This function returns a handle to the dictionary of an Eet file whose handle is* `ef`*, if a dictionary exists. NULL is returned otherwise or if the file handle is known to be invalid.*

**See also:**

**eet\_dictionary\_string\_check()** *to know if given string came from the dictionary or it was dynamically allocated using the* **Eet\_Data\_Descriptor\_Class** *instructrions.*

**Since:**

*1.0.0*

*Referenced by eet\_data\_dump\_cipher(), eet\_data\_node\_read\_cipher(), eet\_data\_node\_write\_cipher(), eet\_data\_read\_cipher(), eet\_data\_undump\_cipher(), and eet\_data\_write\_cipher().*

### EAPI int eet\_dictionary\_string\_check (Eet\_Dictionary \* ed, const char \* string)

*Check if a given string comes from a given dictionary.* **Parameters:**

*ed A valid dictionary handle* \
 *string A valid 0 byte terminated C string*

**Returns:**

*1 if it is in the dictionary, 0 otherwise*

*This checks the given dictionary to see if the given string is actually inside that dictionary (i.e. comes from it) and returns 1 if it does. If the dictionary handle is invlide, the string is NULL or the string is not in the dictionary, 0 is returned.*

**Since:**

*1.0.0*

### EAPI char\*\* eet\_list (Eet\_File \* ef, const char \* glob, int \* count\_ret)

*List all entries in eet file matching shell glob.* **Parameters:**

*ef A valid eet file handle.* \
 *glob A shell glob to match against.* \
 *count\_ret Number of entries found to match.*

**Returns:**

*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 '\*'.*

**Since:**

*1.0.0*

*References EET\_FILE\_MODE\_READ, and EET\_FILE\_MODE\_READ\_WRITE.*

### EAPI Eet\_File\* eet\_memopen\_read (const void \* data, size\_t size)

*Open an eet file directly from a memory location. The data are not copied, so you must keep them around as long as the eet file is open. Their is currently no cache for this kind of Eet\_File, so it's reopen every time you do use eet\_memopen\_read.*

**Since:**

*1.1.0*

### EAPI Eet\_File\_Mode eet\_mode\_get (Eet\_File \* ef)

*Get the mode an Eet\_File was opened with.* **Parameters:**

*ef A valid eet file handle.*

**Returns:**

*The mode ef was opened with.*

**Since:**

*1.0.0*

### EAPI int eet\_num\_entries (Eet\_File \* ef)

*Return the number of entries in the specified eet file.* **Parameters:**

*ef A valid eet file handle.*

**Returns:**

*Number of entries in ef or -1 if the number of entries cannot be read due to open mode restrictions.*

**Since:**

*1.0.0*

*References EET\_FILE\_MODE\_READ, and EET\_FILE\_MODE\_READ\_WRITE.*

### EAPI Eet\_File\* eet\_open (const char \* file, Eet\_File\_Mode mode)

*Open an eet file on disk, and returns a handle to it.* **Parameters:**

*file The file path to the eet file. eg:* `'/tmp/file.eet'`*.* \
 *mode The mode for opening. Either* **EET\_FILE\_MODE\_READ***,* **EET\_FILE\_MODE\_WRITE** *or* **EET\_FILE\_MODE\_READ\_WRITE***.*

**Returns:**

*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.*

*You can also open the file for read/write. If you then write a key that does not exist it will be created, if the key exists it will be replaced by the new data.*

*Example:*

```
 #include <Eet.h>
 #include <stdio.h>
 #include <string.h>
 int
 main(int argc, char **argv)
 {
   Eet_File *ef;
   char buf[1024], *ret, **list;
   int size, num, i;
   eet_init();
   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(stderr, 'Error writing data!0);
   eet_close(ef);
   ef = eet_open('/tmp/my_file.eet', EET_FILE_MODE_READ);
   if (!ef) return -1;
   list = eet_list(ef, '*', &num);
   if (list)
     {
       for (i = 0; i < num; i++)
         printf('Key stored: %s0, list[i]);
       free(list);
     }
   ret = eet_read(ef, '/key/to_store/at', &size);
   if (ret)
     {
       printf('Data read (%i bytes):0s0, size, ret);
       free(ret);
     }
   eet_close(ef);
   eet_shutdown();
   return 0;
 }
```

**Since:**

*1.0.0*

*References EET\_FILE\_MODE\_READ, EET\_FILE\_MODE\_READ\_WRITE, EET\_FILE\_MODE\_WRITE, and eet\_sync().*

### EAPI void\* eet\_read (Eet\_File \* ef, const char \* name, int \* size\_ret)

*Read a specified entry from an eet file and return data.* **Parameters:**

*ef A valid eet file handle opened for reading.* \
 *name Name of the entry. eg: '/base/file\_i\_want'.* \
 *size\_ret Number of bytes read from entry and returned.*

**Returns:**

*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.*

**See also:**

**eet\_read\_cipher()**

**Since:**

*1.0.0*

*References eet\_read\_cipher().*

### EAPI const void\* eet\_read\_direct (Eet\_File \* ef, const char \* name, int \* size\_ret)

*Read a specified entry from an eet file and return data.* **Parameters:**

*ef A valid eet file handle opened for reading.* \
 *name Name of the entry. eg: '/base/file\_i\_want'.* \
 *size\_ret Number of bytes read from entry and returned.*

**Returns:**

*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 if not compressed and successful. NULL is returned if the lookup fails or if memory errors are encountered or if the data is comrpessed. The calling program must never 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.*

**Since:**

*1.0.0*

*References EET\_FILE\_MODE\_READ, and EET\_FILE\_MODE\_READ\_WRITE.*

*Referenced by eet\_data\_dump\_cipher(), eet\_data\_image\_header\_read\_cipher(), eet\_data\_image\_read\_cipher(), eet\_data\_image\_read\_to\_surface\_cipher(), eet\_data\_node\_read\_cipher(), and eet\_data\_read\_cipher().*

### EAPI Eet\_Error eet\_sync (Eet\_File \* ef)

*Sync content of an eet file handle, flushing pending writes.* **Parameters:**

*ef A valid eet file handle.*

*This function will flush any pending writes to disk. The eet file must be opened for write.*

*If the eet file handle is not valid nothing will be done.*

**Since:**

*1.2.4*

*References EET\_FILE\_MODE\_READ\_WRITE, and EET\_FILE\_MODE\_WRITE.*

*Referenced by eet\_open().*

### EAPI int eet\_write (Eet\_File \* ef, const char \* name, const void \* data, int size, int compress)

*Write a specified entry to an eet file handle.* **Parameters:**

*ef A valid eet file handle opened for writing.* \
 *name Name of the entry. eg: '/base/file\_i\_want'.* \
 *data Pointer to the data to be stored.* \
 *size Length in bytes in the data to be stored.* \
 *compress Compression flags (1 == compress, 0 = don't compress).*

**Returns:**

*bytes written on successful write, 0 on failure.*

*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 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).*

**See also:**

**eet\_write\_cipher()**

**Since:**

*1.0.0*

*References eet\_write\_cipher().*

## Author

*Generated automatically by Doxygen for Eet from the source code.*
