#include <stdio.h>
#include <string.h>
static int
create_eet_file(void)
{
char buf[1024], *ptr;
int size, len, i;
const char *some_strings[] = {
"And some more strings",
"spread across several",
"elements of an array!"
};
const char some_data[] =
"\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35"
"\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11"
"\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f"
"\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69"
"\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68"
"\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79"
"\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68"
"\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f"
"\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d"
"\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f"
"\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20"
"\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64"
"\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f"
"\x72\x79\x2e\x0a\x00";
if (!ef) return 0;
strcpy(buf, "Here is a string of data to save!");
size =
eet_write(ef,
"/key/to_store/at", buf,
sizeof(buf), 1);
if (!size)
{
fprintf(stderr, "Error writing data!\n");
return 0;
}
len = strlen(buf);
printf("strlen() = %d, eet_write() = %d\n", len, size);
ptr = buf;
for (i = 0; i < 3; i++)
{
len = strlen(some_strings[i]) + 1;
memcpy(ptr, some_strings[i], len);
ptr += len;
}
eet_write(ef,
"/several/strings", buf,
sizeof(buf), 1);
eet_write(ef,
"/some/mysterious/data", some_data,
sizeof(some_data) - 1, 1);
}
int
main(void)
{
char *ret, **list;
int size, num, i;
if (!create_eet_file())
return -1;
if (!ef) return -1;
if (list)
{
for (i = 0; i < num; i++)
printf("Key stored: %s\n", list[i]);
free(list);
}
ret =
eet_read(ef,
"/key/to_store/at", &size);
if (ret)
{
printf("Data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret =
eet_read(ef,
"/several/strings", &size);
if (ret)
{
printf("More data read (%i bytes):\n%s\n", size, ret);
free(ret);
}
ret =
eet_read(ef,
"/some/mysterious/data", &size);
if (ret)
{
printf("Mysterious data has %d entries\n", num);
printf("Mysterious data:\n%s\n",
free(ret);
}
return 0;
}
The file that provides the eet functions.
EAPI Eet_Error eet_close(Eet_File *ef)
Closes an eet file handle and flush pending writes.
Definition: eet_lib.c:1899
EAPI Eet_File * eet_memopen_read(const void *data, size_t size)
Opens an eet file directly from a memory location.
Definition: eet_lib.c:1387
EAPI const void * eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
Reads a specified entry from an eet file and return data.
Definition: eet_lib.c:2014
EAPI int eet_num_entries(Eet_File *ef)
Returns the number of entries in the specified eet file.
Definition: eet_lib.c:2657
EAPI Eet_File * eet_open(const char *file, Eet_File_Mode mode)
Opens an eet file on disk, and returns a handle to it.
Definition: eet_lib.c:1499
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.
Definition: eet_lib.c:2492
struct _Eet_File Eet_File
Opaque handle that defines an Eet file (or memory).
Definition: Eet.h:527
EAPI int eet_delete(Eet_File *ef, const char *name)
Deletes a specified entry from an Eet file being written or re-written.
Definition: eet_lib.c:2502
EAPI char ** eet_list(Eet_File *ef, const char *glob, int *count_ret)
Lists all entries in eet file matching shell glob.
Definition: eet_lib.c:2573
EAPI void * eet_read(Eet_File *ef, const char *name, int *size_ret)
Reads a specified entry from an eet file and return data.
Definition: eet_lib.c:2006
EAPI Eet_Error eet_sync(Eet_File *ef)
Syncs content of an eet file handle, flushing pending writes.
Definition: eet_lib.c:651
@ EET_FILE_MODE_READ
File is read-only.
Definition: Eet.h:479
@ EET_FILE_MODE_WRITE
File is write-only.
Definition: Eet.h:480
EAPI int eet_init(void)
Initializes the EET library.
Definition: eet_lib.c:540
EAPI int eet_shutdown(void)
Shuts down the EET library.
Definition: eet_lib.c:594
@ EET_ERROR_NONE
No error, it's all fine!
Definition: Eet.h:202