Error check qoi_write() more strictly
simply checking the return value of fwrite() wouldn't be enough since stdio is typically buffered. and so force a flush and check for errors via ferror().
This commit is contained in:
		
							
								
								
									
										6
									
								
								qoi.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								qoi.h
									
									
									
									
									
								
							@@ -594,7 +594,7 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
 | 
			
		||||
 | 
			
		||||
int qoi_write(const char *filename, const void *data, const qoi_desc *desc) {
 | 
			
		||||
	FILE *f = fopen(filename, "wb");
 | 
			
		||||
	int size;
 | 
			
		||||
	int size, err;
 | 
			
		||||
	void *encoded;
 | 
			
		||||
 | 
			
		||||
	if (!f) {
 | 
			
		||||
@@ -608,10 +608,12 @@ int qoi_write(const char *filename, const void *data, const qoi_desc *desc) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fwrite(encoded, 1, size, f);
 | 
			
		||||
	fflush(f);
 | 
			
		||||
	err = ferror(f);
 | 
			
		||||
	fclose(f);
 | 
			
		||||
 | 
			
		||||
	QOI_FREE(encoded);
 | 
			
		||||
	return size;
 | 
			
		||||
	return err ? 0 : size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *qoi_read(const char *filename, qoi_desc *desc, int channels) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user