mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 22:48:19 +00:00
Add spice_strnlen
This commit is contained in:
parent
3d7c1eaa18
commit
1d1792c217
12
common/mem.c
12
common/mem.c
@ -28,6 +28,18 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t spice_strnlen(const char *str, size_t max_len)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (len < max_len && *str != 0) {
|
||||
len++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
char *spice_strdup(const char *str)
|
||||
{
|
||||
char *copy;
|
||||
|
||||
@ -33,6 +33,8 @@ void *spice_malloc_n_m(size_t n_blocks, size_t n_block_bytes, size_t extra_size)
|
||||
void *spice_malloc0_n(size_t n_blocks, size_t n_block_bytes) SPICE_GNUC_MALLOC SPICE_GNUC_ALLOC_SIZE2(1,2);
|
||||
void *spice_realloc_n(void *mem, size_t n_blocks, size_t n_block_bytes) SPICE_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
size_t spice_strnlen(const char *str, size_t max_len);
|
||||
|
||||
/* Optimize: avoid the call to the (slower) _n function if we can
|
||||
* determine at compile-time that no overflow happens.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user