diff options
author | Timo Sirainen <cras@irssi.org> | 2004-03-23 22:07:55 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2004-03-23 22:07:55 +0000 |
commit | b886e97d5e1c087e94232ed003a9abcb1ec1f192 (patch) | |
tree | f845880ca935d1b7f79dd5f0b10fc72d5fc08ea6 /src | |
parent | 0e133595d1061713a711232160035b675fd4bc3b (diff) | |
download | irssi-b886e97d5e1c087e94232ed003a9abcb1ec1f192.zip |
added strocpy()
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3238 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/core/misc.c | 14 | ||||
-rw-r--r-- | src/core/misc.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 1359b71b..f080fd0f 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -778,6 +778,20 @@ char *escape_string(const char *str) return ret; } +int strocpy(char *dest, const char *src, size_t dstsize) +{ + if (dstsize == 0) + return -1; + + while (*src != '\0' && dstsize > 1) { + *dest++ = *src++; + dstsize--; + } + + *dest++ = '\0'; + return *src == '\0' ? 0 : -1; +} + int nearest_power(int num) { int n = 1; diff --git a/src/core/misc.h b/src/core/misc.h index 37a3953d..35a9dfc8 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -101,6 +101,9 @@ int expand_escape(const char **data); /* Escape all '"', "'" and '\' chars with '\' */ char *escape_string(const char *str); +/* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */ +int strocpy(char *dest, const char *src, size_t dstsize); + int nearest_power(int num); /* Returns TRUE / FALSE */ |