Tizen Native API
5.5
|
These functions provide memory slices in read-only and read-write forms.
Memory slices define a contiguous linear memory starting at a given pointer (mem
) and spanning for a given length (len
).
They may be read-only (Eina_Slice) or read-write (Eina_Rw_Slice).
Functions | |
static Eina_Slice | eina_rw_slice_slice_get (const Eina_Rw_Slice rw_slice) |
Convert the Read-write slice to read-only. | |
static Eina_Rw_Slice | eina_slice_dup (const Eina_Slice slice) |
Creates a duplicate of slice's memory. | |
static Eina_Rw_Slice | eina_rw_slice_dup (const Eina_Rw_Slice rw_slice) |
Creates a duplicate of slice's memory. | |
static int | eina_slice_compare (const Eina_Slice a, const Eina_Slice b) |
Compare two slices, similar to memcmp() | |
static int | eina_rw_slice_compare (const Eina_Rw_Slice a, const Eina_Rw_Slice b) |
Compare two slices, similar to memcmp() | |
static Eina_Rw_Slice | eina_rw_slice_copy (const Eina_Rw_Slice dest, const Eina_Slice src) |
Copy a read-only slice to a read-write one, similar to memcpy(). | |
static Eina_Slice | eina_slice_seek (const Eina_Slice slice, ssize_t offset, int whence) |
Seek within a slice, similar to fseek(). | |
static Eina_Rw_Slice | eina_rw_slice_seek (const Eina_Rw_Slice rw_slice, ssize_t offset, int whence) |
Seek within a read-write slice, similar to fseek(). | |
static const void * | eina_slice_strchr (const Eina_Slice slice, int c) |
Find a character inside the slice, similar to memchr(). | |
static const void * | eina_slice_find (const Eina_Slice slice, const Eina_Slice needle) |
Find a needle inside the slice, similar to memmem(). | |
static Eina_Bool | eina_slice_startswith (const Eina_Slice slice, const Eina_Slice prefix) |
Checks if the slice starts with a prefix. | |
static Eina_Bool | eina_slice_endswith (const Eina_Slice slice, const Eina_Slice suffix) |
Checks if the slice ends with a suffix. | |
static void * | eina_rw_slice_strchr (const Eina_Rw_Slice rw_slice, int c) |
Find a character inside the slice, similar to memchr(). | |
static void * | eina_rw_slice_find (const Eina_Rw_Slice rw_slice, const Eina_Slice needle) |
Find a needle inside the slice, similar to memmem(). | |
static Eina_Bool | eina_rw_slice_startswith (const Eina_Rw_Slice slice, const Eina_Slice prefix) |
Checks if the slice starts with a prefix. | |
static Eina_Bool | eina_rw_slice_endswith (const Eina_Rw_Slice slice, const Eina_Slice suffix) |
Checks if the slice ends with a suffix. | |
static const void * | eina_slice_end_get (const Eina_Slice slice) |
The memory position where the slice ends. | |
static void * | eina_rw_slice_end_get (const Eina_Rw_Slice rw_slice) |
The memory position where the slice ends. | |
static char * | eina_slice_strdup (const Eina_Slice slice) |
A null-terminated string for this slice. | |
static char * | eina_rw_slice_strdup (const Eina_Rw_Slice rw_slice) |
A null-terminated string for this slice. | |
Typedefs | |
typedef struct _Eina_Slice | Eina_Slice |
typedef struct _Eina_Rw_Slice | Eina_Rw_Slice |
Defines | |
#define | EINA_SLICE_ARRAY(buf) {.len = ((sizeof(buf) / sizeof((buf)[0])) * sizeof((buf)[0])), .mem = (buf)} |
Initializer for arrays of any kind. | |
#define | EINA_RW_SLICE_DECLARE(name, length) |
#define | EINA_SLICE_STR_LITERAL(buf) {.len = (sizeof("" buf) - 1), .mem = (buf)} |
#define | EINA_SLICE_STR(str) {.len = strlen((str)), .mem = (str)} |
#define | EINA_SLICE_STR_FMT "%.*s" |
#define | EINA_SLICE_STR_PRINT(s) (int)(s).len, (const char *)(s).mem |
To be used in printf()-like statements when EINA_SLICE_STR_FMT was used, it will print the slice as a string up to len . | |
#define | EINA_SLICE_FMT "%p+%zu" |
#define | EINA_SLICE_PRINT(s) (s).mem, (s).len |
#define | EINA_SLICE_FOREACH(s, itr) |
#define EINA_RW_SLICE_DECLARE | ( | name, | |
length | |||
) |
uint8_t _eina_slice_storage_ ## name [(length)] = { 0 }; \ Eina_Rw_Slice name = EINA_SLICE_ARRAY(_eina_slice_storage_ ## name)
Declare a local (stack) array for storage at given length and initialize an Eina_Rw_Slice called name.
[in] | name | the name of the variable to be the Eina_Rw_Slice. |
[in] | length | the size in bytes of the storage. |
#define EINA_SLICE_ARRAY | ( | buf | ) | {.len = ((sizeof(buf) / sizeof((buf)[0])) * sizeof((buf)[0])), .mem = (buf)} |
Initializer for arrays of any kind.
[in] | buf | The array to create the slice from. |
It is often useful for globals.
static uint8_t buf[1024]; static Eina_Slice rw_slice = EINA_SLICE_ARRAY(buf);
#define EINA_SLICE_FMT "%p+%zu" |
To be used in printf()-like statements, prints the slice as 0x1234+12
(mem
+ len
).
Use with EINA_SLICE_PRINT()
Eina_Slice s = EINA_SLICE_STR_LITERAL("hello"); printf("s=" EINA_SLICE_FMT "\n", EINA_SLICE_PRINT(s));
#define EINA_SLICE_FOREACH | ( | s, | |
itr | |||
) |
for ((itr) = (s).mem; \ (void *)(itr) < (void *)((s).bytes + (s).len); \ (itr)++)
Iterate over the slice memory, using itr
. Each increment will be using the size of itr
pointer (int32_t* will do in increments of 4 bytes).
[in] | s | The slice. |
[in,out] | itr | the iterator to hold each byte. Use a proper type, not "void*" or "const void*" as it doesn't have an intrinsic size. |
#define EINA_SLICE_PRINT | ( | s | ) | (s).mem, (s).len |
To be used in printf()-like statements when EINA_SLICE_FMT was used, it will print the slice mem
and len
.
Use with EINA_SLICE_FMT.
[in] | s | The slice. |
Eina_Slice s = EINA_SLICE_STR_LITERAL("hello"); printf("s=" EINA_SLICE_FMT "\n", EINA_SLICE_PRINT(s));
#define EINA_SLICE_STR | ( | str | ) | {.len = strlen((str)), .mem = (str)} |
Initializer for strings (uses strlen()).
[in] | str | The string to create the slice from. |
Eina_Slice ro_slice = EINA_SLICE_STR("hello world");
#define EINA_SLICE_STR_FMT "%.*s" |
To be used in printf()-like statements, prints the slice as a string, its len
is to be used, then it doesn't need the null terminator.
Use with EINA_SLICE_STR_PRINT()
Eina_Slice s = EINA_SLICE_STR_LITERAL("hello"); printf("s=" EINA_SLICE_STR_FMT "\n", EINA_SLICE_STR_PRINT(s));
#define EINA_SLICE_STR_LITERAL | ( | buf | ) | {.len = (sizeof("" buf) - 1), .mem = (buf)} |
Initializer for string literals (those declared as double-quoted). The size will NOT include the trailing null-terminator.
It is often useful for globals.
[in] | buf | The array to create the slice from. |
static const Eina_Slice ro_slice = EINA_SLICE_STR_LITERAL("hello world");
#define EINA_SLICE_STR_PRINT | ( | s | ) | (int)(s).len, (const char *)(s).mem |
To be used in printf()-like statements when EINA_SLICE_STR_FMT was used, it will print the slice as a string up to len
.
[in] | s | The slice. |
Use with EINA_SLICE_STR_FMT.
Eina_Slice s = EINA_SLICE_STR_LITERAL("hello"); printf("s=" EINA_SLICE_STR_FMT "\n", EINA_SLICE_STR_PRINT(s));
Defines a read-and-write able memory region.
The slice is a memory starting at mem
and accessible up to len
bytes.
Defines a read-only memory region.
The slice is a memory starting at mem
and accessible up to len
bytes.
static int eina_rw_slice_compare | ( | const Eina_Rw_Slice | a, |
const Eina_Rw_Slice | b | ||
) | [static] |
Compare two slices, similar to memcmp()
[in] | a | the first slice to compare. |
[in] | b | the second slice to compare. |
static Eina_Rw_Slice eina_rw_slice_copy | ( | const Eina_Rw_Slice | dest, |
const Eina_Slice | src | ||
) | [static] |
Copy a read-only slice to a read-write one, similar to memcpy().
[in] | dest | where to write the memory. |
[in] | src | where to load memory. |
len
) will be the smallest of dest and src.static Eina_Rw_Slice eina_rw_slice_dup | ( | const Eina_Rw_Slice | rw_slice | ) | [static] |
Creates a duplicate of slice's memory.
[in] | rw_slice | the input to duplicate |
mem
that matches slice contents. The new mem
is allocated with malloc() and must be released with free().static void* eina_rw_slice_end_get | ( | const Eina_Rw_Slice | rw_slice | ) | [static] |
The memory position where the slice ends.
[in] | rw_slice | the reference memory. |
static Eina_Bool eina_rw_slice_endswith | ( | const Eina_Rw_Slice | slice, |
const Eina_Slice | suffix | ||
) | [static] |
Checks if the slice ends with a suffix.
[in] | slice | the reference memory. |
[in] | suffix | the slice to check if slice ends with. |
static void* eina_rw_slice_find | ( | const Eina_Rw_Slice | rw_slice, |
const Eina_Slice | needle | ||
) | [static] |
Find a needle inside the slice, similar to memmem().
[in] | rw_slice | the reference memory. |
[in] | needle | what to find. |
NULL
if not found.static Eina_Rw_Slice eina_rw_slice_seek | ( | const Eina_Rw_Slice | rw_slice, |
ssize_t | offset, | ||
int | whence | ||
) | [static] |
Seek within a read-write slice, similar to fseek().
[in] | rw_slice | the containing slice to seek inside. |
[in] | offset | how to get to the new position. |
[in] | whence | SEEK_SET, SEEK_END as fseek(). |
static Eina_Slice eina_rw_slice_slice_get | ( | const Eina_Rw_Slice | rw_slice | ) | [static] |
Convert the Read-write slice to read-only.
[in] | rw_slice | the read-write slice to convert. |
static Eina_Bool eina_rw_slice_startswith | ( | const Eina_Rw_Slice | slice, |
const Eina_Slice | prefix | ||
) | [static] |
Checks if the slice starts with a prefix.
[in] | slice | the reference memory. |
[in] | prefix | the slice to check if slice starts with. |
static void* eina_rw_slice_strchr | ( | const Eina_Rw_Slice | rw_slice, |
int | c | ||
) | [static] |
Find a character inside the slice, similar to memchr().
[in] | rw_slice | the reference memory. |
[in] | c | the byte (character) to find. |
NULL
if not found.static char* eina_rw_slice_strdup | ( | const Eina_Rw_Slice | rw_slice | ) | [static] |
A null-terminated string for this slice.
[in] | slice | the reference memory. |
NULL
on errorstatic int eina_slice_compare | ( | const Eina_Slice | a, |
const Eina_Slice | b | ||
) | [static] |
Compare two slices, similar to memcmp()
[in] | a | the first slice to compare. |
[in] | b | the second slice to compare. |
static Eina_Rw_Slice eina_slice_dup | ( | const Eina_Slice | slice | ) | [static] |
Creates a duplicate of slice's memory.
[in] | slice | the input to duplicate |
mem
that matches slice contents. The new mem
is allocated with malloc() and must be released with free().static const void* eina_slice_end_get | ( | const Eina_Slice | slice | ) | [static] |
The memory position where the slice ends.
[in] | slice | the reference memory. |
static Eina_Bool eina_slice_endswith | ( | const Eina_Slice | slice, |
const Eina_Slice | suffix | ||
) | [static] |
Checks if the slice ends with a suffix.
[in] | slice | the reference memory. |
[in] | suffix | the slice to check if slice ends with. |
static const void* eina_slice_find | ( | const Eina_Slice | slice, |
const Eina_Slice | needle | ||
) | [static] |
Find a needle inside the slice, similar to memmem().
[in] | slice | the reference memory. |
[in] | needle | what to find. |
NULL
if not found.static Eina_Slice eina_slice_seek | ( | const Eina_Slice | slice, |
ssize_t | offset, | ||
int | whence | ||
) | [static] |
Seek within a slice, similar to fseek().
[in] | slice | the containing slice to seek inside. |
[in] | offset | how to get to the new position. |
[in] | whence | SEEK_SET, SEEK_END as fseek(). |
static Eina_Bool eina_slice_startswith | ( | const Eina_Slice | slice, |
const Eina_Slice | prefix | ||
) | [static] |
Checks if the slice starts with a prefix.
[in] | slice | the reference memory. |
[in] | prefix | the slice to check if slice starts with. |
static const void* eina_slice_strchr | ( | const Eina_Slice | slice, |
int | c | ||
) | [static] |
Find a character inside the slice, similar to memchr().
[in] | slice | the reference memory. |
[in] | c | the byte (character) to find. |
NULL
if not found.static char* eina_slice_strdup | ( | const Eina_Slice | slice | ) | [static] |
A null-terminated string for this slice.
[in] | slice | the reference memory. |
NULL
on error