summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-15 10:30:46 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-15 10:30:46 +0100
commitf43a3244ddb0d2789e6b097868e4472bc403a09a (patch)
treecb6d5a0d268840b55d3d258537762fc096445fac /src
parenta2ed9d553a54f48f771a74280fb63f95a8b228ae (diff)
downloadadvtime-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.c6
-rw-r--r--src/util.c8
-rw-r--r--src/util.h2
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");
diff --git a/src/util.c b/src/util.c
index 9ab6e25..d9c8f35 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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
diff --git a/src/util.h b/src/util.h
index 8e0503a..bcc2828 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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 */