[PATCH V2 2/3] load_image: always print a message on failure if filename is not empty
Pekka Paalanen
ppaalanen at gmail.com
Thu Sep 11 03:13:22 PDT 2014
On Tue, 19 Aug 2014 18:13:10 -0700
Bill Spitzak <spitzak at gmail.com> wrote:
> It was rather inconsistent before. This may help users figure out why
> backgrounds and icons don't show up. A better api where the error can
> be queried might be nice, but this seems sufficient for current Weston use.
> ---
> shared/image-loader.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/shared/image-loader.c b/shared/image-loader.c
> index 35dadd3..0d04b03 100644
> --- a/shared/image-loader.c
> +++ b/shared/image-loader.c
> @@ -23,6 +23,7 @@
>
> #include "config.h"
>
> +#include <errno.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> @@ -374,12 +375,18 @@ load_image(const char *filename)
> FILE *fp;
> unsigned int i;
>
> + if (!filename || !*filename)
> + return NULL;
> +
> fp = fopen(filename, "rb");
> - if (fp == NULL)
> + if (!fp) {
> + fprintf(stderr, "%s: %s\n", filename, strerror(errno));
> return NULL;
> + }
>
> if (fread(header, sizeof header, 1, fp) != 1) {
> fclose(fp);
> + fprintf(stderr, "%s: unable to read file header\n", filename);
> return NULL;
> }
>
> @@ -395,10 +402,13 @@ load_image(const char *filename)
> fclose(fp);
>
> if (i == ARRAY_LENGTH(loaders)) {
> - fprintf(stderr, "unrecognized file header for %s: "
> + fprintf(stderr, "%s: unrecognized file header "
> "0x%02x 0x%02x 0x%02x 0x%02x\n",
> filename, header[0], header[1], header[2], header[3]);
> image = NULL;
> + } else if (!image) {
> + /* load probably printed something, but just in case */
> + fprintf(stderr, "%s: error reading image\n", filename);
> }
>
> return image;
Yes, at least there is something always printed now. Compositor-x11.c
is using load_image() directly to load the icon for the X11 window.
When that fails, we should really use weston_log() for the error
message, but I see that is a bit labourious to implement without
losing the exact header error message, so as you wrote, this is
sufficient for now.
I removed one stray space.
Pushed.
Thanks,
pq
More information about the wayland-devel
mailing list