Tizen Native API  6.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).

Since (EFL) :
1.19

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_FULL(str)   {.len = strlen((str)) + 1, .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 Documentation

#define EINA_RW_SLICE_DECLARE (   name,
  length 
)
Value:
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.

Parameters:
[in]namethe name of the variable to be the Eina_Rw_Slice.
[in]lengththe size in bytes of the storage.
Since (EFL) :
1.19
#define EINA_SLICE_ARRAY (   buf)    {.len = ((sizeof(buf) / sizeof((buf)[0])) * sizeof((buf)[0])), .mem = (buf)}

Initializer for arrays of any kind.

Parameters:
[in]bufThe array to create the slice from.
Returns:
The initialized slice object.

It is often useful for globals.

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
 static uint8_t buf[1024];
 static Eina_Slice rw_slice = EINA_SLICE_ARRAY(buf);
See also:
EINA_SLICE_STR_LITERAL() for specific version that checks for string literals.
Since (EFL) :
1.19
#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()

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
 Eina_Slice s = EINA_SLICE_STR_LITERAL("hello");
 printf("s=" EINA_SLICE_FMT "\n", EINA_SLICE_PRINT(s));
Since (EFL) :
1.19
#define EINA_SLICE_FOREACH (   s,
  itr 
)
Value:
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).

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
Be aware of memory alignment! Accessing unaligned memory may not be supported in some architectures.
Parameters:
[in]sThe slice.
[in,out]itrthe iterator to hold each byte. Use a proper type, not "void*" or "const void*" as it doesn't have an intrinsic size.
Since (EFL) :
1.19
#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.

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
Parameters:
[in]sThe slice.
Returns:
The arguments for an EINA_SLICE_FMT formatted printf.
 Eina_Slice s = EINA_SLICE_STR_LITERAL("hello");
 printf("s=" EINA_SLICE_FMT "\n", EINA_SLICE_PRINT(s));
Since (EFL) :
1.19
#define EINA_SLICE_STR (   str)    {.len = strlen((str)), .mem = (str)}

Initializer for strings (uses strlen()).

Parameters:
[in]strThe string to create the slice from.
Returns:
The initialized slice object.
Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
 Eina_Slice ro_slice = EINA_SLICE_STR("hello world");
See also:
EINA_SLICE_STR() for specific version using literals.
Since (EFL) :
1.19
#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()

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
Since (EFL) :
1.19
#define EINA_SLICE_STR_FULL (   str)    {.len = strlen((str)) + 1, .mem = (str)}

Same as EINA_SLICE_STR_FULL, but it also contains the \0 element of the string

Parameters:
[in]strThe string to create the slice from.
Returns:
The initialized slice object.
Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
 Eina_Slice ro_slice = EINA_SLICE_STR_FULL("hello world");
See also:
EINA_SLICE_STR_FULL() for specific version using literals.
Since (EFL) :
1.24
#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.

Parameters:
[in]bufThe array to create the slice from.
Returns:
The initialized slice object.
Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
 static const Eina_Slice ro_slice = EINA_SLICE_STR_LITERAL("hello world");
See also:
EINA_SLICE_STR() for more generic version.
EINA_SLICE_ARRAY() for version that uses a general array.
Since (EFL) :
1.19
#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.

Parameters:
[in]sThe slice.
Returns:
The arguments for an EINA_SLICE_STR_FMT formatted printf.

Use with EINA_SLICE_STR_FMT.

Note:
This macro is usable with both Eina_Slice or Eina_Rw_Slice.
Since (EFL) :
1.19

Typedef Documentation

Defines a read-and-write able memory region.

The slice is a memory starting at mem and accessible up to len bytes.

See also:
Eina_Slice for read-only memory regions.
Since (EFL) :
1.19

Defines a read-only memory region.

The slice is a memory starting at mem and accessible up to len bytes.

See also:
Eina_Rw_Slice for read-write memory regions.
Since (EFL) :
1.19

Function Documentation

static int eina_rw_slice_compare ( const Eina_Rw_Slice  a,
const Eina_Rw_Slice  b 
) [static]

Compare two slices, similar to memcmp()

Parameters:
[in]athe first slice to compare.
[in]bthe second slice to compare.
Returns:
0 if equal, < 0 if a < b, > 0 if a > b
Since (EFL) :
1.19
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().

Parameters:
[in]destwhere to write the memory.
[in]srcwhere to load memory.
Returns:
a new slice with the resulting write. Note that the length (len) will be the smallest of dest and src.
See also:
eina_rw_slice_dup()
eina_slice_dup()
Since (EFL) :
1.19
static Eina_Rw_Slice eina_rw_slice_dup ( const Eina_Rw_Slice  rw_slice) [static]

Creates a duplicate of slice's memory.

Parameters:
[in]rw_slicethe input to duplicate
Returns:
a new read-write slice with new mem that matches slice contents. The new mem is allocated with malloc() and must be released with free().
See also:
eina_rw_slice_copy()
eina_slice_dup()
Since (EFL) :
1.19
static void* eina_rw_slice_end_get ( const Eina_Rw_Slice  rw_slice) [static]

The memory position where the slice ends.

Note:
this is out-of the slice, the first byte after it ends and must not be accessed.
Parameters:
[in]rw_slicethe reference memory.
Returns:
the first byte after the slice ends.
Since (EFL) :
1.19
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.

Parameters:
[in]slicethe reference memory.
[in]suffixthe slice to check if slice ends with.
Returns:
EINA_TRUE if slice ends with suffix, EINA_FALSE otherwise.
Since (EFL) :
1.19
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().

Parameters:
[in]rw_slicethe reference memory.
[in]needlewhat to find.
Returns:
the memory within slice or NULL if not found.
Since (EFL) :
1.19
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().

Parameters:
[in]rw_slicethe containing slice to seek inside.
[in]offsethow to get to the new position.
[in]whenceSEEK_SET, SEEK_END as fseek().
Returns:
a new slice contained inside, it will start at the given offset and have a length that goes until the end of the rw_slice. If an invalid whence, a zero-sized slice starting at rw_slice mem will be returned. The slice is guaranteed to be contained within rw_slice, even if offset causes it to go out of bounds, then it will be clamped to 0 and slice.len.
Since (EFL) :
1.19
static Eina_Slice eina_rw_slice_slice_get ( const Eina_Rw_Slice  rw_slice) [static]

Convert the Read-write slice to read-only.

Parameters:
[in]rw_slicethe read-write slice to convert.
Returns:
the red-only slice matching the slice.
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.

Parameters:
[in]slicethe reference memory.
[in]prefixthe slice to check if slice starts with.
Returns:
EINA_TRUE if slice starts with prefix, EINA_FALSE otherwise.
Since (EFL) :
1.19
static void* eina_rw_slice_strchr ( const Eina_Rw_Slice  rw_slice,
int  c 
) [static]

Find a character inside the slice, similar to memchr().

Parameters:
[in]rw_slicethe reference memory.
[in]cthe byte (character) to find.
Returns:
the memory within slice or NULL if not found.
Since (EFL) :
1.19
static char* eina_rw_slice_strdup ( const Eina_Rw_Slice  rw_slice) [static]

A null-terminated string for this slice.

Parameters:
[in]rw_slicethe reference memory.
Returns:
newly allocated memory or NULL on error
Since (EFL) :
1.19
static int eina_slice_compare ( const Eina_Slice  a,
const Eina_Slice  b 
) [static]

Compare two slices, similar to memcmp()

Parameters:
[in]athe first slice to compare.
[in]bthe second slice to compare.
Returns:
0 if equal, < 0 if a < b, > 0 if a > b
Since (EFL) :
1.19
static Eina_Rw_Slice eina_slice_dup ( const Eina_Slice  slice) [static]

Creates a duplicate of slice's memory.

Parameters:
[in]slicethe input to duplicate
Returns:
a new read-write slice with new mem that matches slice contents. The new mem is allocated with malloc() and must be released with free().
See also:
eina_rw_slice_copy()
eina_rw_slice_dup()
Since (EFL) :
1.19
static const void* eina_slice_end_get ( const Eina_Slice  slice) [static]

The memory position where the slice ends.

Note:
this is out-of the slice, the first byte after it ends and must not be accessed.
Parameters:
[in]slicethe reference memory.
Returns:
the first byte after the slice ends.
Since (EFL) :
1.19
static Eina_Bool eina_slice_endswith ( const Eina_Slice  slice,
const Eina_Slice  suffix 
) [static]

Checks if the slice ends with a suffix.

Parameters:
[in]slicethe reference memory.
[in]suffixthe slice to check if slice ends with.
Returns:
EINA_TRUE if slice ends with suffix, EINA_FALSE otherwise.
Since (EFL) :
1.19
static const void* eina_slice_find ( const Eina_Slice  slice,
const Eina_Slice  needle 
) [static]

Find a needle inside the slice, similar to memmem().

Parameters:
[in]slicethe reference memory.
[in]needlewhat to find.
Returns:
the memory within slice or NULL if not found.
Since (EFL) :
1.19
static Eina_Slice eina_slice_seek ( const Eina_Slice  slice,
ssize_t  offset,
int  whence 
) [static]

Seek within a slice, similar to fseek().

Parameters:
[in]slicethe containing slice to seek inside.
[in]offsethow to get to the new position.
[in]whenceSEEK_SET, SEEK_END as fseek().
Returns:
a new slice contained inside, it will start at the given offset and have a length that goes until the end of the slice. If an invalid whence, a zero-sized slice starting at slice mem will be returned. The slice is guaranteed to be contained within slice, even if offset causes it to go out of bounds, then it will be clamped to 0 and slice.len.
Since (EFL) :
1.19
static Eina_Bool eina_slice_startswith ( const Eina_Slice  slice,
const Eina_Slice  prefix 
) [static]

Checks if the slice starts with a prefix.

Parameters:
[in]slicethe reference memory.
[in]prefixthe slice to check if slice starts with.
Returns:
EINA_TRUE if slice starts with prefix, EINA_FALSE otherwise.
Since (EFL) :
1.19
static const void* eina_slice_strchr ( const Eina_Slice  slice,
int  c 
) [static]

Find a character inside the slice, similar to memchr().

Parameters:
[in]slicethe reference memory.
[in]cthe byte (character) to find.
Returns:
the memory within slice or NULL if not found.
Since (EFL) :
1.19
static char* eina_slice_strdup ( const Eina_Slice  slice) [static]

A null-terminated string for this slice.

Parameters:
[in]slicethe reference memory.
Returns:
newly allocated memory or NULL on error
Since (EFL) :
1.19