Release 4.10 tools/perf/util/strbuf.c
#include "debug.h"
#include "util.h"
#include <linux/kernel.h>
int prefixcmp(const char *str, const char *prefix)
{
for (; ; str++, prefix++)
if (!*prefix)
return 0;
else if (*str != *prefix)
return (unsigned char)*prefix - (unsigned char)*str;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 58 | 100.00% | 1 | 100.00% |
| Total | 58 | 100.00% | 1 | 100.00% |
/*
* Used as the default ->buf value, so that people can always assume
* buf is non NULL and ->buf is NUL terminated even for a freshly
* initialized strbuf.
*/
char strbuf_slopbuf[1];
int strbuf_init(struct strbuf *sb, ssize_t hint)
{
sb->alloc = sb->len = 0;
sb->buf = strbuf_slopbuf;
if (hint)
return strbuf_grow(sb, hint);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 38 | 86.36% | 2 | 66.67% |
masami hiramatsu | masami hiramatsu | 6 | 13.64% | 1 | 33.33% |
| Total | 44 | 100.00% | 3 | 100.00% |
void strbuf_release(struct strbuf *sb)
{
if (sb->alloc) {
zfree(&sb->buf);
strbuf_init(sb, 0);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 31 | 93.94% | 1 | 50.00% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 2 | 6.06% | 1 | 50.00% |
| Total | 33 | 100.00% | 2 | 100.00% |
char *strbuf_detach(struct strbuf *sb, size_t *sz)
{
char *res = sb->alloc ? sb->buf : NULL;
if (sz)
*sz = sb->len;
strbuf_init(sb, 0);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 50 | 100.00% | 1 | 100.00% |
| Total | 50 | 100.00% | 1 | 100.00% |
int strbuf_grow(struct strbuf *sb, size_t extra)
{
char *buf;
size_t nr = sb->len + extra + 1;
if (nr < sb->alloc)
return 0;
if (nr <= sb->len)
return -E2BIG;
if (alloc_nr(sb->alloc) > nr)
nr = alloc_nr(sb->alloc);
/*
* Note that sb->buf == strbuf_slopbuf if sb->alloc == 0, and it is
* a static variable. Thus we have to avoid passing it to realloc.
*/
buf = realloc(sb->alloc ? sb->buf : NULL, nr * sizeof(*buf));
if (!buf)
return -ENOMEM;
sb->buf = buf;
sb->alloc = nr;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
masami hiramatsu | masami hiramatsu | 74 | 62.18% | 1 | 50.00% |
ingo molnar | ingo molnar | 45 | 37.82% | 1 | 50.00% |
| Total | 119 | 100.00% | 2 | 100.00% |
int strbuf_addch(struct strbuf *sb, int c)
{
int ret = strbuf_grow(sb, 1);
if (ret)
return ret;
sb->buf[sb->len++] = c;
sb->buf[sb->len] = '\0';
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 41 | 73.21% | 1 | 50.00% |
masami hiramatsu | masami hiramatsu | 15 | 26.79% | 1 | 50.00% |
| Total | 56 | 100.00% | 2 | 100.00% |
int strbuf_add(struct strbuf *sb, const void *data, size_t len)
{
int ret = strbuf_grow(sb, len);
if (ret)
return ret;
memcpy(sb->buf + sb->len, data, len);
return strbuf_setlen(sb, sb->len + len);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 30 | 48.39% | 1 | 33.33% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 18 | 29.03% | 1 | 33.33% |
masami hiramatsu | masami hiramatsu | 14 | 22.58% | 1 | 33.33% |
| Total | 62 | 100.00% | 3 | 100.00% |
static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
{
int len, ret;
va_list ap_saved;
if (!strbuf_avail(sb)) {
ret = strbuf_grow(sb, 64);
if (ret)
return ret;
}
va_copy(ap_saved, ap);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
if (len < 0)
return len;
if (len > strbuf_avail(sb)) {
ret = strbuf_grow(sb, len);
if (ret)
return ret;
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
va_end(ap_saved);
if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is broken");
return -EINVAL;
}
}
return strbuf_setlen(sb, sb->len + len);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 91 | 49.73% | 1 | 16.67% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 47 | 25.68% | 2 | 33.33% |
masami hiramatsu | masami hiramatsu | 33 | 18.03% | 1 | 16.67% |
namhyung kim | namhyung kim | 12 | 6.56% | 2 | 33.33% |
| Total | 183 | 100.00% | 6 | 100.00% |
int strbuf_addf(struct strbuf *sb, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = strbuf_addv(sb, fmt, ap);
va_end(ap);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
namhyung kim | namhyung kim | 40 | 81.63% | 1 | 50.00% |
masami hiramatsu | masami hiramatsu | 9 | 18.37% | 1 | 50.00% |
| Total | 49 | 100.00% | 2 | 100.00% |
ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)
{
size_t oldlen = sb->len;
size_t oldalloc = sb->alloc;
int ret;
ret = strbuf_grow(sb, hint ? hint : 8192);
if (ret)
return ret;
for (;;) {
ssize_t cnt;
cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
if (cnt < 0) {
if (oldalloc == 0)
strbuf_release(sb);
else
strbuf_setlen(sb, oldlen);
return cnt;
}
if (!cnt)
break;
sb->len += cnt;
ret = strbuf_grow(sb, 8192);
if (ret)
return ret;
}
sb->buf[sb->len] = '\0';
return sb->len - oldlen;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 86 | 52.44% | 2 | 50.00% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 56 | 34.15% | 1 | 25.00% |
masami hiramatsu | masami hiramatsu | 22 | 13.41% | 1 | 25.00% |
| Total | 164 | 100.00% | 4 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ingo molnar | ingo molnar | 438 | 52.52% | 2 | 20.00% |
masami hiramatsu | masami hiramatsu | 176 | 21.10% | 1 | 10.00% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 168 | 20.14% | 5 | 50.00% |
namhyung kim | namhyung kim | 52 | 6.24% | 2 | 20.00% |
| Total | 834 | 100.00% | 10 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.