[MINOR] buffers: add buffer_feed2() and make buffer_feed() measure string length

It's inconvenient to always have to compute string lengths when calling
buffer_feed(), so change that.
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index e061b2c..89f7467 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -358,7 +358,7 @@
 }
 
 /* Try to write character <c> into buffer <buf> after length controls. This
- * work like buffer_feed(buf, &c, 1).
+ * work like buffer_feed2(buf, &c, 1).
  * Returns non-zero in case of success, 0 if the buffer was full.
  * The send limit is automatically adjusted with the amount of data written.
  */
@@ -389,7 +389,7 @@
 }
 
 int buffer_write(struct buffer *buf, const char *msg, int len);
-int buffer_feed(struct buffer *buf, const char *str, int len);
+int buffer_feed2(struct buffer *buf, const char *str, int len);
 int buffer_si_putchar(struct buffer *buf, char c);
 int buffer_si_peekline(struct buffer *buf, char *str, int len);
 int buffer_replace(struct buffer *b, char *pos, char *end, const char *str);
@@ -426,12 +426,23 @@
 {
 	int ret;
 
-	ret = buffer_feed(buf, chunk->str, chunk->len);
+	ret = buffer_feed2(buf, chunk->str, chunk->len);
 	if (ret == -1)
 		chunk->len = 0;
 	return ret;
 }
 
+/* Try to write string <str> into buffer <buf> after length controls. This is
+ * the equivalent of buffer_feed2() except that string length is measured by
+ * the function. Returns -1 in case of success, -2 if it is larger than the
+ * buffer size, or the number of bytes available otherwise. The send limit is
+ * automatically adjusted with the amount of data written.
+ */
+static inline int buffer_feed(struct buffer *buf, const char *str)
+{
+	return buffer_feed2(buf, str, strlen(str));
+}
+
 static inline void chunk_init(struct chunk *chk, char *str, size_t size) {
 	chk->str  = str;
 	chk->len  = 0;
diff --git a/src/buffers.c b/src/buffers.c
index ee00f1c..f5a8c8b 100644
--- a/src/buffers.c
+++ b/src/buffers.c
@@ -1,7 +1,7 @@
 /*
  * Buffer management functions.
  *
- * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -78,7 +78,7 @@
  * otherwise. The send limit is automatically adjusted with the amount of data
  * written.
  */
-int buffer_feed(struct buffer *buf, const char *str, int len)
+int buffer_feed2(struct buffer *buf, const char *str, int len)
 {
 	int max;
 
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 63696d8..dcbccf7 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -64,20 +64,10 @@
 	"  show sess      : report the list of current sessions\n"
 	"";
 
-const struct chunk stats_sock_usage = {
-        .str = (char *)&stats_sock_usage_msg,
-        .len = sizeof(stats_sock_usage_msg)-1
-};
-
 const char stats_permission_denied_msg[] =
 	"Permission denied\n"
 	"";
 
-const struct chunk stats_permission_denied = {
-        .str = (char *)&stats_permission_denied_msg,
-        .len = sizeof(stats_permission_denied_msg)-1
-};
-
 /* This function parses a "stats" statement in the "global" section. It returns
  * -1 if there is any error, otherwise zero. If it returns -1, it may write an
  * error message into ther <err> buffer, for at most <errlen> bytes, trailing
@@ -313,14 +303,14 @@
 		else if (strcmp(args[1], "sess") == 0) {
 			s->data_state = DATA_ST_INIT;
 			if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
-				buffer_feed(si->ib, stats_permission_denied.str, stats_permission_denied.len);
+				buffer_feed(si->ib, stats_permission_denied_msg);
 				return 1;
 			}
 			si->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer
 		}
 		else if (strcmp(args[1], "errors") == 0) {
 			if (s->listener->perm.ux.level < ACCESS_LVL_OPER) {
-				buffer_feed(si->ib, stats_permission_denied.str, stats_permission_denied.len);
+				buffer_feed(si->ib, stats_permission_denied_msg);
 				return 1;
 			}
 			if (*args[2])
@@ -348,7 +338,7 @@
 			/* check permissions */
 			if (s->listener->perm.ux.level < ACCESS_LVL_OPER ||
 			    (clrall && s->listener->perm.ux.level < ACCESS_LVL_ADMIN)) {
-				buffer_feed(si->ib, stats_permission_denied.str, stats_permission_denied.len);
+				buffer_feed(si->ib, stats_permission_denied_msg);
 				return 1;
 			}
 
@@ -495,7 +485,7 @@
 
 			switch (si->st0) {
 			case STAT_CLI_O_HELP:
-				if (buffer_feed(si->ib, stats_sock_usage.str, stats_sock_usage.len) < 0)
+				if (buffer_feed(si->ib, stats_sock_usage_msg) < 0)
 					si->st0 = STAT_CLI_PROMPT;
 				break;
 			case STAT_CLI_O_INFO:
@@ -517,7 +507,7 @@
 
 			/* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
 			if (si->st0 == STAT_CLI_PROMPT) {
-				if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n", si->st1 ? 3 : 1) < 0)
+				if (buffer_feed(si->ib, si->st1 ? "\n> " : "\n") < 0)
 					si->st0 = STAT_CLI_GETREQ;
 			}