summaryrefslogtreecommitdiff
path: root/sys/src/libplumb
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@flatbox.9hal>2012-03-09 09:11:12 +0100
committercinap_lenrek <cinap_lenrek@flatbox.9hal>2012-03-09 09:11:12 +0100
commit9e8b285562c35ef1c47f74ccafbda7f7624b22af (patch)
tree94326760edc35f051c21da6da035fbc333a9c05c /sys/src/libplumb
parent9b0fc40aee38cd7c8c21f28803fc25af0cc64db4 (diff)
plumber: use 16K stack, make libplumb thread safe
Diffstat (limited to 'sys/src/libplumb')
-rw-r--r--sys/src/libplumb/mesg.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/sys/src/libplumb/mesg.c b/sys/src/libplumb/mesg.c
index 1bc0f5be2..455d8ca1b 100644
--- a/sys/src/libplumb/mesg.c
+++ b/sys/src/libplumb/mesg.c
@@ -2,8 +2,6 @@
#include <libc.h>
#include "plumb.h"
-static char attrbuf[4096];
-
int
plumbopen(char *name, int omode)
{
@@ -70,20 +68,20 @@ Strcpy(char *s, char *t)
/* quote attribute value, if necessary */
static char*
-quote(char *s)
+quote(char *s, char *buf, char *bufe)
{
char *t;
int c;
if(s == nil){
- attrbuf[0] = '\0';
- return attrbuf;
+ buf[0] = '\0';
+ return buf;
}
if(strpbrk(s, " '=\t") == nil)
return s;
- t = attrbuf;
+ t = buf;
*t++ = '\'';
- while(t < attrbuf+sizeof attrbuf-2){
+ while(t < bufe-2){
c = *s++;
if(c == '\0')
break;
@@ -93,7 +91,7 @@ quote(char *s)
}
*t++ = '\'';
*t = '\0';
- return attrbuf;
+ return buf;
}
char*
@@ -101,13 +99,16 @@ plumbpackattr(Plumbattr *attr)
{
int n;
Plumbattr *a;
- char *s, *t;
+ char *s, *t, *buf, *bufe;
if(attr == nil)
return nil;
+ if((buf = malloc(4096)) == nil)
+ return nil;
+ bufe = buf + 4096;
n = 0;
for(a=attr; a!=nil; a=a->next)
- n += Strlen(a->name) + 1 + Strlen(quote(a->value)) + 1;
+ n += Strlen(a->name) + 1 + Strlen(quote(a->value, buf, bufe)) + 1;
s = malloc(n);
if(s == nil)
return nil;
@@ -118,11 +119,13 @@ plumbpackattr(Plumbattr *attr)
*t++ = ' ';
strcpy(t, a->name);
strcat(t, "=");
- strcat(t, quote(a->value));
+ strcat(t, quote(a->value, buf, bufe));
t += strlen(t);
}
if(t > s+n)
abort();
+ free(buf);
+
return s;
}
@@ -236,9 +239,12 @@ Plumbattr*
plumbunpackattr(char *p)
{
Plumbattr *attr, *prev, *a;
- char *q, *v;
+ char *q, *v, *buf, *bufe;
int c, quoting;
+ if((buf = malloc(4096)) == nil)
+ return nil;
+ bufe = buf + 4096;
attr = prev = nil;
while(*p!='\0' && *p!='\n'){
while(*p==' ' || *p=='\t')
@@ -262,10 +268,10 @@ plumbunpackattr(char *p)
a->name[q-p] = '\0';
/* process quotes in value */
q++; /* skip '=' */
- v = attrbuf;
+ v = buf;
quoting = 0;
while(*q!='\0' && *q!='\n'){
- if(v >= attrbuf+sizeof attrbuf)
+ if(v >= bufe)
break;
c = *q++;
if(quoting){
@@ -287,14 +293,14 @@ plumbunpackattr(char *p)
}
*v++ = c;
}
- a->value = malloc(v-attrbuf+1);
+ a->value = malloc(v-buf+1);
if(a->value == nil){
free(a->name);
free(a);
break;
}
- memmove(a->value, attrbuf, v-attrbuf);
- a->value[v-attrbuf] = '\0';
+ memmove(a->value, buf, v-buf);
+ a->value[v-buf] = '\0';
a->next = nil;
if(prev == nil)
attr = a;
@@ -303,6 +309,8 @@ plumbunpackattr(char *p)
prev = a;
p = q;
}
+ free(buf);
+
return attr;
}