comparison wave.c @ 520:6e9d1a8c1b08

Fix check of fwrite return value in wave_finalize so that the data subchunk size gets written
author Michael Pavone <pavone@retrodev.com>
date Tue, 11 Feb 2014 12:45:15 -0800
parents 140af5509ce7
children efc75ea79164
comparison
equal deleted inserted replaced
514:f66c78cbdcaa 520:6e9d1a8c1b08
1 /* 1 /*
2 Copyright 2013 Michael Pavone 2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm. 3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5 */ 5 */
6 #include "wave.h" 6 #include "wave.h"
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
29 int wave_finalize(FILE * f) 29 int wave_finalize(FILE * f)
30 { 30 {
31 uint32_t size = ftell(f); 31 uint32_t size = ftell(f);
32 fseek(f, offsetof(wave_header, chunk.size), SEEK_SET); 32 fseek(f, offsetof(wave_header, chunk.size), SEEK_SET);
33 size -= 8; 33 size -= 8;
34 if (fwrite(&size, sizeof(size), 1, f) != sizeof(size)) { 34 if (fwrite(&size, sizeof(size), 1, f) != 1) {
35 fclose(f); 35 fclose(f);
36 return 0; 36 return 0;
37 } 37 }
38 fseek(f, offsetof(wave_header, data_header.size), SEEK_SET); 38 fseek(f, offsetof(wave_header, data_header.size), SEEK_SET);
39 size -= 36; 39 size -= 36;
40 if (fwrite(&size, sizeof(size), 1, f)) { 40 if (fwrite(&size, sizeof(size), 1, f) != 1) {
41 fclose(f); 41 fclose(f);
42 return 0; 42 return 0;
43 } 43 }
44 fclose(f); 44 fclose(f);
45 return 1; 45 return 1;