dwarves: Introduce cus__fprintf_load_files_err()

Out of code in pdwtags and pahole, will be used in the other tools.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2016-03-15 14:25:58 -03:00
parent 0e64636350
commit 10515a7c4d
4 changed files with 11 additions and 4 deletions

View File

@ -1495,6 +1495,13 @@ int cus__load_files(struct cus *cus, struct conf_load *conf,
return 0;
}
int cus__fprintf_load_files_err(struct cus *cus, const char *tool, char *argv[], int err, FILE *output)
{
/* errno is not properly preserved in some cases, sigh */
return fprintf(output, "%s: %s: %s\n", tool, argv[-err - 1],
errno ? strerror(errno) : "No debugging information found");
}
struct cus *cus__new(void)
{
struct cus *cus = malloc(sizeof(*cus));

View File

@ -84,6 +84,8 @@ int cus__load_file(struct cus *cus, struct conf_load *conf,
const char *filename);
int cus__load_files(struct cus *cus, struct conf_load *conf,
char *filenames[]);
int cus__fprintf_load_files_err(struct cus *cus, const char *tool,
char *argv[], int err, FILE *output);
int cus__load_dir(struct cus *cus, struct conf_load *conf,
const char *dirname, const char *filename_mask,
const int recursive);

View File

@ -1249,9 +1249,7 @@ int main(int argc, char *argv[])
err = cus__load_files(cus, &conf_load, argv + remaining);
if (err != 0) {
/* errno is not properly preserved in some cases, sigh */
fprintf(stderr, "pahole: %s: %s\n", argv[remaining + -err - 1],
errno ? strerror(errno) : "No debugging information found");
cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
goto out_cus_delete;
}

View File

@ -147,7 +147,7 @@ int main(int argc, char *argv[])
goto out;
}
fprintf(stderr, "%s: %s: %s\n", basename(argv[0]), argv[remaining + -err - 1], strerror(errno));
cus__fprintf_load_files_err(cus, "pdwtags", argv + remaining, err, stderr);
out:
cus__delete(cus);
dwarves__exit();