added zap_strndup

git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@928 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Moises Silva 2009-12-04 18:25:48 +00:00
parent ff473f4adc
commit c376f9d092
2 changed files with 19 additions and 0 deletions

View File

@ -652,6 +652,7 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl
/*! \brief Duplicate string */
OZ_DECLARE(char *) zap_strdup(const char *str);
OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen);
OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen);
OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits);

View File

@ -3252,6 +3252,24 @@ OZ_DECLARE(char *) zap_strdup(const char *str)
return (char *)memcpy(new, str, len);
}
OZ_DECLARE(char *) zap_strndup(const char *str, zap_size_t inlen)
{
char *new = NULL;
zap_size_t len = strlen(str) + 1;
if (len > (inlen+1)) {
len = inlen+1;
}
new = (char *)zap_malloc(len);
if (!new) {
return NULL;
}
memcpy(new, str, len-1);
new[len-1] = 0;
return new;
}
/* For Emacs:
* Local Variables: