cregit-Linux how code gets into the kernel

Release 4.10 tools/perf/util/strlist.c

Directory: tools/perf/util
/*
 * (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
 *
 * Licensed under the GPLv2.
 */

#include "strlist.h"
#include "util.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


static struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry) { const char *s = entry; struct rb_node *rc = NULL; struct strlist *strlist = container_of(rblist, struct strlist, rblist); struct str_node *snode = malloc(sizeof(*snode)); if (snode != NULL) { if (strlist->dupstr) { s = strdup(s); if (s == NULL) goto out_delete; } snode->s = s; rc = &snode->rb_node; } return rc; out_delete: free(snode); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo6655.46%150.00%
david aherndavid ahern5344.54%150.00%
Total119100.00%2100.00%


static void str_node__delete(struct str_node *snode, bool dupstr) { if (dupstr) zfree((char **)&snode->s); free(snode); }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo3597.22%375.00%
namhyung kimnamhyung kim12.78%125.00%
Total36100.00%4100.00%


static void strlist__node_delete(struct rblist *rblist, struct rb_node *rb_node) { struct strlist *slist = container_of(rblist, struct strlist, rblist); struct str_node *snode = container_of(rb_node, struct str_node, rb_node); str_node__delete(snode, slist->dupstr); }

Contributors

PersonTokensPropCommitsCommitProp
david aherndavid ahern4276.36%150.00%
arnaldo carvalho de meloarnaldo carvalho de melo1323.64%150.00%
Total55100.00%2100.00%


static int strlist__node_cmp(struct rb_node *rb_node, const void *entry) { const char *str = entry; struct str_node *snode = container_of(rb_node, struct str_node, rb_node); return strcmp(snode->s, str); }

Contributors

PersonTokensPropCommitsCommitProp
david aherndavid ahern2552.08%150.00%
arnaldo carvalho de meloarnaldo carvalho de melo2347.92%150.00%
Total48100.00%2100.00%


int strlist__add(struct strlist *slist, const char *new_entry) { return rblist__add_node(&slist->rblist, new_entry); }

Contributors

PersonTokensPropCommitsCommitProp
david aherndavid ahern1765.38%133.33%
arnaldo carvalho de meloarnaldo carvalho de melo934.62%266.67%
Total26100.00%3100.00%


int strlist__load(struct strlist *slist, const char *filename) { char entry[1024]; int err; FILE *fp = fopen(filename, "r"); if (fp == NULL) return -errno; while (fgets(entry, sizeof(entry), fp) != NULL) { const size_t len = strlen(entry); if (len == 0) continue; entry[len - 1] = '\0'; err = strlist__add(slist, entry); if (err != 0) goto out; } err = 0; out: fclose(fp); return err; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo120100.00%3100.00%
Total120100.00%3100.00%


void strlist__remove(struct strlist *slist, struct str_node *snode) { rblist__remove_node(&slist->rblist, &snode->rb_node); }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo1760.71%133.33%
suzuki k poulosesuzuki k poulose828.57%133.33%
david aherndavid ahern310.71%133.33%
Total28100.00%3100.00%


struct str_node *strlist__find(struct strlist *slist, const char *entry) { struct str_node *snode = NULL; struct rb_node *rb_node = rblist__find(&slist->rblist, entry); if (rb_node) snode = container_of(rb_node, struct str_node, rb_node); return snode; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo3458.62%133.33%
david aherndavid ahern2034.48%133.33%
masami hiramatsumasami hiramatsu46.90%133.33%
Total58100.00%3100.00%


static int strlist__parse_list_entry(struct strlist *slist, const char *s, const char *subst_dir) { int err; char *subst = NULL; if (strncmp(s, "file://", 7) == 0) return strlist__load(slist, s + 7); if (subst_dir) { err = -ENOMEM; if (asprintf(&subst, "%s/%s", subst_dir, s) < 0) goto out; if (access(subst, F_OK) == 0) { err = strlist__load(slist, subst); goto out; } if (slist->file_only) { err = -ENOENT; goto out; } } err = strlist__add(slist, s); out: free(subst); return err; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo12788.81%375.00%
namhyung kimnamhyung kim1611.19%125.00%
Total143100.00%4100.00%


static int strlist__parse_list(struct strlist *slist, const char *s, const char *subst_dir) { char *sep; int err; while ((sep = strchr(s, ',')) != NULL) { *sep = '\0'; err = strlist__parse_list_entry(slist, s, subst_dir); *sep = ','; if (err != 0) return err; s = sep + 1; } return *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo96100.00%4100.00%
Total96100.00%4100.00%


struct strlist *strlist__new(const char *list, const struct strlist_config *config) { struct strlist *slist = malloc(sizeof(*slist)); if (slist != NULL) { bool dupstr = true; bool file_only = false; const char *dirname = NULL; if (config) { dupstr = !config->dont_dupstr; dirname = config->dirname; file_only = config->file_only; } rblist__init(&slist->rblist); slist->rblist.node_cmp = strlist__node_cmp; slist->rblist.node_new = strlist__node_new; slist->rblist.node_delete = strlist__node_delete; slist->dupstr = dupstr; slist->file_only = file_only; if (list && strlist__parse_list(slist, list, dirname) != 0) goto out_error; } return slist; out_error: free(slist); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo11673.89%562.50%
david aherndavid ahern2314.65%112.50%
namhyung kimnamhyung kim1710.83%112.50%
ananth n. mavinakayanahalliananth n. mavinakayanahalli10.64%112.50%
Total157100.00%8100.00%


void strlist__delete(struct strlist *slist) { if (slist != NULL) rblist__delete(&slist->rblist); }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo2291.67%266.67%
david aherndavid ahern28.33%133.33%
Total24100.00%3100.00%


struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx) { struct str_node *snode = NULL; struct rb_node *rb_node; rb_node = rblist__entry(&slist->rblist, idx); if (rb_node) snode = container_of(rb_node, struct str_node, rb_node); return snode; }

Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo3558.33%150.00%
david aherndavid ahern2541.67%150.00%
Total60100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
arnaldo carvalho de meloarnaldo carvalho de melo73274.01%857.14%
david aherndavid ahern21021.23%17.14%
namhyung kimnamhyung kim343.44%214.29%
suzuki k poulosesuzuki k poulose80.81%17.14%
masami hiramatsumasami hiramatsu40.40%17.14%
ananth n. mavinakayanahalliananth n. mavinakayanahalli10.10%17.14%
Total989100.00%14100.00%
Directory: tools/perf/util
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.