aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-10-06 14:23:32 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-10-06 14:23:32 -0700
commit979a2d52e987032c95924045d8a4f5985452ff85 (patch)
tree5f0baed2707adc928c80743d060ca3d481c79072
parentaa977bf9b0d368a85193717360ee5af96526d64a (diff)
downloadlwip-979a2d52e987032c95924045d8a4f5985452ff85.tar.gz
lwip-979a2d52e987032c95924045d8a4f5985452ff85.tar.xz
lwip-979a2d52e987032c95924045d8a4f5985452ff85.zip
core: strbuf: fix the strbuf interfaces
Fix compilation problems in the strbuf interfaces, and change them to take a pointer to the actual structure pointer. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/fs/pxe/strbuf.c63
-rw-r--r--core/fs/pxe/strbuf.h11
2 files changed, 50 insertions, 24 deletions
diff --git a/core/fs/pxe/strbuf.c b/core/fs/pxe/strbuf.c
index 3526e2af..2b25a9c0 100644
--- a/core/fs/pxe/strbuf.c
+++ b/core/fs/pxe/strbuf.c
@@ -15,37 +15,44 @@
struct strbuf __strbuf_error_buf = {
.size = 0,
- .len = -1,
+ .len = 0,
+ .str = ""
};
-void strbuf_free(struct strbuf *buf)
+void strbuf_free(struct strbuf **bufp)
{
- if (buf != &__strbuf_error_buf)
- free(buf);
+ if (*bufp != &__strbuf_error_buf)
+ free(*bufp);
+ *bufp = NULL;
}
-struct strbuf *strbuf_cat(struct strbuf *buf, const char *str)
+#if 0
+
+void *strbuf_cat(struct strbuf **bufp, const char *str)
{
struct strbuf *buf, *xbuf;
size_t len = strlen(str);
size_t size;
+ buf = *bufp;
+
if (buf == &__strbuf_error_buf)
- return buf; /* Buffer in error state */
- return buf;
+ return;
if (!buf) {
size = (len+SIZESTEP) & ~(SIZESTEP-1);
if (size < MINSIZE)
size = MINSIZE;
buf = malloc(sizeof(struct strbuf) + MINSIZE);
- if (!buf)
- return &__strbuf_error_buf;
+ if (!buf) {
+ *bufp = &__strbuf_error_buf;
+ return;
+ }
buf->len = len;
buf->size = size;
memcpy(buf->str, str, len+1);
- return buf;
+ return;
}
if (buf->size - buf->len > len) {
@@ -53,18 +60,34 @@ struct strbuf *strbuf_cat(struct strbuf *buf, const char *str)
xbuf = realloc(buf, sizeof(struct strbuf) + MINSIZE);
if (!xbuf) {
free(buf);
- return &__strbuf_error_buf;
+ *bufp = &__strbuf_error_buf;
+ return;
}
- buf = xbuf;
+ *bufp = buf = xbuf;
buf->size = size;
}
memcpy(buf->str + buf->len, str, len+1);
buf->len += len;
- return buf;
}
-struct strbuf *sbprintf(struct strbuf *buf, const char *fmt, ...)
+#else
+void strbuf_cat(struct strbuf **bufp, const char *str)
+{
+ return sbprintf(bufp, "%s", str);
+}
+#endif
+
+void strbuf_putc(struct strbuf **bufp, char c)
+{
+ char str[2];
+
+ str[0] = c;
+ str[1] = '\0';
+ return strbuf_cat(bufp, str);
+}
+
+void sbprintf(struct strbuf **bufp, const char *fmt, ...)
{
struct strbuf *buf, *xbuf;
size_t len;
@@ -73,8 +96,10 @@ struct strbuf *sbprintf(struct strbuf *buf, const char *fmt, ...)
va_list ap;
char *p;
+ buf = *bufp;
+
if (buf == &__strbuf_error_buf)
- return buf; /* Buffer in error state */
+ return; /* Buffer in error state */
va_start(ap, fmt);
@@ -91,7 +116,7 @@ struct strbuf *sbprintf(struct strbuf *buf, const char *fmt, ...)
if (len < slack) {
buf->len += len;
- return buf; /* It all fit */
+ return; /* It all fit */
}
size = (strbuf_len(buf) + len + SIZESTEP) & ~SIZESTEP;
@@ -101,11 +126,12 @@ struct strbuf *sbprintf(struct strbuf *buf, const char *fmt, ...)
xbuf = realloc(buf, sizeof(struct strbuf) + size);
if (!xbuf) {
free(buf);
- return &__strbuf_error_buf;
+ *bufp = &__strbuf_error_buf;
+ return;
}
if (!buf)
xbuf->len = 0;
- buf = xbuf;
+ *bufp = buf = xbuf;
buf->size = size;
@@ -114,5 +140,4 @@ struct strbuf *sbprintf(struct strbuf *buf, const char *fmt, ...)
va_end(ap);
buf->len += len;
- return buf;
}
diff --git a/core/fs/pxe/strbuf.h b/core/fs/pxe/strbuf.h
index 976c74e2..c6ad3525 100644
--- a/core/fs/pxe/strbuf.h
+++ b/core/fs/pxe/strbuf.h
@@ -14,17 +14,18 @@ struct strbuf {
char str[];
};
-struct strbuf *strbuf_cat(struct strbuf *, const char *);
-struct strbuf *sbprintf(struct strbuf *, const char *, ...);
-void strbuf_free(struct strbuf *);
+void strbuf_cat(struct strbuf **, const char *);
+void strbuf_putc(struct strbuf **, char);
+void sbprintf(struct strbuf **, const char *, ...);
+void strbuf_free(struct strbuf **);
static inline const char *strbuf_str(struct strbuf *__sb)
{
- return __sb ? __sb.str : NULL;
+ return __sb ? __sb->str : "";
}
static inline size_t strbuf_len(struct strbuf *__sb)
{
- return __sb ? __sb.len : 0;
+ return __sb ? __sb->len : 0;
}
extern struct strbuf __strbuf_error_buf;