summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/utils.c27
-rw-r--r--src/utils.h10
2 files changed, 35 insertions, 2 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;
+}
diff --git a/src/utils.h b/src/utils.h
index 5979064..0fdf312 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,4 +1,4 @@
-/* $Id: utils.h,v 1.11 2001-11-22 00:31:10 rjkaes Exp $
+/* $Id: utils.h,v 1.12 2001-11-23 01:19:15 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*
@@ -23,6 +23,12 @@
#include "conns.h"
+/*
+ * Error codes used within the utility functions.
+ */
+#define EERROR 1 /* Generic error */
+#define ENOMEMORY 2 /* Out of memory (or allocation error) */
+
extern int send_http_message(struct conn_s *connptr, int http_code,
const char *error_title, const char *message);
extern int httperr(struct conn_s *connptr, int err, const char *msg);
@@ -40,6 +46,8 @@ extern size_t strlcat(char *dst, const char *src, size_t size);
extern size_t strlcpy(char *dst, const char *src, size_t size);
#endif /* HAVE_STRLCPY */
+extern size_t chomp(char *buffer, size_t length);
+
/*
* The following is to allow for better memory checking.
*/