diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-15 10:30:46 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-15 10:30:46 +0100 |
commit | f43a3244ddb0d2789e6b097868e4472bc403a09a (patch) | |
tree | cb6d5a0d268840b55d3d258537762fc096445fac /src | |
parent | a2ed9d553a54f48f771a74280fb63f95a8b228ae (diff) | |
download | advtime-f43a3244ddb0d2789e6b097868e4472bc403a09a.tar.gz advtime-f43a3244ddb0d2789e6b097868e4472bc403a09a.tar.bz2 advtime-f43a3244ddb0d2789e6b097868e4472bc403a09a.zip |
pgm_save: Check whether file could be opened
Diffstat (limited to 'src')
-rw-r--r-- | src/advtime.c | 6 | ||||
-rw-r--r-- | src/util.c | 8 | ||||
-rw-r--r-- | src/util.h | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/advtime.c b/src/advtime.c index e4cd9a9..402da31 100644 --- a/src/advtime.c +++ b/src/advtime.c @@ -113,8 +113,10 @@ main(int argc, char **argv) if (diff > 40.0) { snprintf(filename, BUFSIZ, "img/%04i.pgm", i); frame_mix(frame_a, frame_b); - pgm_save(frame_a->data, frame_a->stride, frame_a->width, - frame_a->height, filename); + if (pgm_save(frame_a->data, frame_a->stride, + frame_a->width, frame_a->height, + filename) < 0) + exit(EXIT_FAILURE); } printf("\n"); @@ -3,17 +3,21 @@ #include "video_decode.h" #include "util.h" -void +int pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) { FILE *f; int i; f = fopen(filename, "w"); + if (f == NULL) + return -1; fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255); - for(i=0; i < ysize; i++) + for(i = 0; i < ysize; i++) fwrite(buf + i * wrap, 1, xsize, f); fclose(f); + + return 0; } void @@ -1,7 +1,7 @@ #ifndef _UTIL_H_ #define _UTIL_H_ -void +int pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename); /* Store half of frame_a and half of frame_b in frame_a */ |