Mercurial > geeqie.yaz
comparison src/thumb.c @ 1181:475986f8f298
Handle return values better to silent some warnings.
author | zas_ |
---|---|
date | Wed, 26 Nov 2008 20:39:50 +0000 |
parents | 95860439070b |
children | 8b89e3ff286b |
comparison
equal
deleted
inserted
replaced
1180:f5bea35b4316 | 1181:475986f8f298 |
---|---|
571 #define XV_BUFFER 2048 | 571 #define XV_BUFFER 2048 |
572 static guchar *load_xv_thumbnail(gchar *filename, gint *widthp, gint *heightp) | 572 static guchar *load_xv_thumbnail(gchar *filename, gint *widthp, gint *heightp) |
573 { | 573 { |
574 FILE *file; | 574 FILE *file; |
575 gchar buffer[XV_BUFFER]; | 575 gchar buffer[XV_BUFFER]; |
576 guchar *data; | 576 guchar *data = NULL; |
577 gint width, height, depth; | |
578 | 577 |
579 file = fopen(filename, "rt"); | 578 file = fopen(filename, "rt"); |
580 if (!file) return NULL; | 579 if (!file) return NULL; |
581 | 580 |
582 fgets(buffer, XV_BUFFER, file); | 581 if (fgets(buffer, XV_BUFFER, file) != NULL |
583 if (strncmp(buffer, "P7 332", 6) != 0) | 582 && strncmp(buffer, "P7 332", 6) == 0) |
584 { | 583 { |
585 fclose(file); | 584 gint width, height, depth; |
586 return NULL; | 585 |
587 } | 586 while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */; |
588 | 587 |
589 while (fgets(buffer, XV_BUFFER, file) && buffer[0] == '#') /* do_nothing() */; | 588 if (sscanf(buffer, "%d %d %d", &width, &height, &depth) == 3) |
590 | 589 { |
591 if (sscanf(buffer, "%d %d %d", &width, &height, &depth) != 3) | 590 gsize size = width * height; |
592 { | 591 |
593 fclose(file); | 592 data = g_new(guchar, size); |
594 return NULL; | 593 if (data && fread(data, 1, size, file) == size) |
595 } | 594 { |
596 | 595 *widthp = width; |
597 data = g_new(guchar, width * height); | 596 *heightp = height; |
598 fread(data, 1, width * height, file); | 597 } |
598 } | |
599 } | |
599 | 600 |
600 fclose(file); | 601 fclose(file); |
601 *widthp = width; | |
602 *heightp = height; | |
603 return data; | 602 return data; |
604 } | 603 } |
605 #undef XV_BUFFER | 604 #undef XV_BUFFER |
606 | 605 |
607 static void free_rgb_buffer(guchar *pixels, gpointer data) | 606 static void free_rgb_buffer(guchar *pixels, gpointer data) |