mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
add snd_strlcat() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
e51cba0973
commit
8291d2c601
2 changed files with 35 additions and 7 deletions
|
|
@ -267,6 +267,7 @@ int _snd_safe_strtod(const char *str, double *val);
|
||||||
int snd_send_fd(int sock, void *data, size_t len, int fd);
|
int snd_send_fd(int sock, void *data, size_t len, int fd);
|
||||||
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
|
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
|
||||||
size_t snd_strlcpy(char *dst, const char *src, size_t size);
|
size_t snd_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
size_t snd_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* error messages
|
* error messages
|
||||||
|
|
|
||||||
27
src/error.c
27
src/error.c
|
|
@ -199,3 +199,30 @@ size_t snd_strlcpy(char *dst, const char *src, size_t size)
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Append a C-string into a sized buffer
|
||||||
|
* \param dst Where to append the string to
|
||||||
|
* \param src Where to copy the string from
|
||||||
|
* \param size Size of destination buffer
|
||||||
|
* \retval The total string length (no trimming)
|
||||||
|
*
|
||||||
|
* The result is always a valid NUL-terminated string that fits
|
||||||
|
* in the buffer (unless, of course, the buffer size is zero).
|
||||||
|
* It does not pad out the result.
|
||||||
|
*/
|
||||||
|
size_t snd_strlcat(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t dst_len = strlen(dst);
|
||||||
|
size_t len = strlen(src);
|
||||||
|
size_t ret = dst_len + len;
|
||||||
|
if (dst_len < size) {
|
||||||
|
dst += dst_len;
|
||||||
|
size -= dst_len;
|
||||||
|
if (len >= size)
|
||||||
|
len = size - 1;
|
||||||
|
memcpy(dst, src, len);
|
||||||
|
dst[len] = '\0';
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue