ref: 77ad456b31b2258be4c2fa2f4842910a7c92062c
parent: e1ca49d625aaca1aae1dc570e7bc63a499d3e741
author: cinap_lenrek <[email protected]>
date: Mon Jan 1 23:47:42 EST 2018
libauth: simplify _attrfmt() using fmtprint() avoiding stack buffer
--- a/sys/src/libauth/attr.c
+++ b/sys/src/libauth/attr.c
@@ -5,28 +5,26 @@
int
_attrfmt(Fmt *fmt)
{
- char *b, buf[1024], *ebuf;
Attr *a;
+ int first = 1;
- ebuf = buf+sizeof buf;
- b = buf;
- strcpy(buf, " ");
- for(a=va_arg(fmt->args, Attr*); a; a=a->next){
+ for(a=va_arg(fmt->args, Attr*); a != nil; a=a->next){
if(a->name == nil)
continue;
switch(a->type){
+ default:
+ continue;
case AttrQuery:
- b = seprint(b, ebuf, " %q?", a->name);
+ fmtprint(fmt, first+" %q?", a->name);
break;
case AttrNameval:
- b = seprint(b, ebuf, " %q=%q", a->name, a->val);
- break;
case AttrDefault:
- b = seprint(b, ebuf, " %q:=%q", a->name, a->val);
+ fmtprint(fmt, first+" %q=%q", a->name, a->val);
break;
}
+ first = 0;
}
- return fmtstrcpy(fmt, buf+1);
+ return 0;
}
Attr*