Re: [PATCH v13 02/14] perf, tools, jevents: Program to convert JSON file to C style file

From: Jiri Olsa
Date: Wed Jun 03 2015 - 06:31:54 EST


On Tue, Jun 02, 2015 at 10:12:02AM -0700, Sukadev Bhattiprolu wrote:

SNIP

> + * If we fail to locate/process JSON and map files, create a NULL mapping
> + * table. This would at least allow perf to build even if we can't find/use
> + * the aliases.
> + */
> +static void create_empty_mapping(const char *output_file)
> +{
> + FILE *outfp;
> +
> + pr_info("%s: Creating empty pmu_events_map[] table\n", prog);
> +
> + /* Unlink file to clear any partial writes to it */
> + unlink(output_file);
> +
> + outfp = fopen(output_file, "a");

you could open with "w+" and save the unlink call

SNIP

> +int main(int argc, char *argv[])
> +{
> + int rc;
> + int flags;
> + int maxfds;
> + char dirname[PATH_MAX];
> +
> + const char *arch;
> + const char *output_file;
> + const char *start_dirname;
> +
> + prog = basename(argv[0]);
> + if (argc < 4) {
> + pr_err("Usage: %s <arch> <starting_dir> <output_file>\n", prog);
> + return 1;
> + }
> +
> + arch = argv[1];
> + start_dirname = argv[2];
> + output_file = argv[3];
> +
> + if (argc > 4)
> + verbose = atoi(argv[4]);
> +
> + unlink(output_file);
> + eventsfp = fopen(output_file, "a");

ditto

SNIP
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/