struct event_format *event_format__new(const char *sys, const char *name) { int fd, n; char *filename; void *bf = NULL, *nbf; size_t size = 0, alloc_size = 0; struct event_format *format = NULL; if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, name) < 0) goto out; fd = open(filename, O_RDONLY); if (fd < 0) goto out_free_filename; do { if (size == alloc_size) { alloc_size += BUFSIZ; nbf = realloc(bf, alloc_size); if (nbf == NULL) goto out_free_bf; bf = nbf; } n = read(fd, bf + size, BUFSIZ); if (n < 0) goto out_free_bf; size += n; } while (n > 0); pevent_parse_format(&format, bf, size, sys); out_free_bf: free(bf); close(fd); out_free_filename: free(filename); out: return format; }
/* * Returns pointer with encoded error via <linux/err.h> interface. */ static struct event_format* tp_format(const char *sys, const char *name) { struct pevent *pevent = tevent.pevent; struct event_format *event = NULL; char path[PATH_MAX]; size_t size; char *data; int err; scnprintf(path, PATH_MAX, "%s/%s/%s/format", tracing_events_path, sys, name); err = filename__read_str(path, &data, &size); if (err) return ERR_PTR(err); pevent_parse_format(pevent, &event, data, size, sys); free(data); return event; }