summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-06-17 11:18:27 +0200
committerAlexander Larsson <alexl@redhat.com>2010-06-17 11:21:03 +0200
commit1d1792c217bee2f7aed28cbee60fc170bb56ecae (patch)
tree25fada7c66c76943eaf71f6b19d250a22c4e71ae /common
parent3d7c1eaa185f91d597ccbe732aa9eff8e5336a62 (diff)
downloadspice-1d1792c217bee2f7aed28cbee60fc170bb56ecae.tar.gz
spice-1d1792c217bee2f7aed28cbee60fc170bb56ecae.tar.xz
spice-1d1792c217bee2f7aed28cbee60fc170bb56ecae.zip
Add spice_strnlen
Diffstat (limited to 'common')
-rw-r--r--common/mem.c12
-rw-r--r--common/mem.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/common/mem.c b/common/mem.c
index ec274bb3..ffb2fa45 100644
--- a/common/mem.c
+++ b/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;
diff --git a/common/mem.h b/common/mem.h
index 20877607..9b257ade 100644
--- a/common/mem.h
+++ b/common/mem.h
@@ -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.
*/