diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-11-23 01:19:15 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-11-23 01:19:15 +0000 |
commit | 4aa5e79cdf2435d9b53898130e63811e3a2a013c (patch) | |
tree | 42a2a96445c49501b086e23516aa3e7b94bb4da2 /src/utils.c | |
parent | fd3b313e9f11a298fe709246c34983438df02029 (diff) |
Added the chomp() function (to replace the trim() function reqs.c)
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c index 5c83729..b65655b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,4 @@ -/* $Id: utils.c,v 1.17 2001-11-22 00:31:10 rjkaes Exp $ +/* $Id: utils.c,v 1.18 2001-11-23 01:19:15 rjkaes Exp $ * * Misc. routines which are used by the various functions to handle strings * and memory allocation and pretty much anything else we can think of. Also, @@ -345,3 +345,28 @@ strlcat(char *dst, const char *src, size_t size) return ret; } #endif + +/* + * Removes any new-line or carriage-return characters from the end of the + * string. This function is named afrer the same function in Perl. + * "length" should be the number of characters in the buffer, not including + * the trailing NULL. + * + * Returns the number of characters removed from the end of the string. + */ +size_t +chomp(char *buffer, size_t length) +{ + size_t chars = 0; + + --length; + while (buffer[length] == '\r' || buffer[length] == '\n') { + buffer[length--] = '\0'; + chars++; + + if (length < 0) + break; + } + + return chars; +} |