Lock output file before writing; close #18
This commit is contained in:
parent
9dd60534e4
commit
94974653c1
13
qoi.h
13
qoi.h
@ -584,20 +584,21 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int qoi_write(const char *filename, const void *data, const qoi_desc *desc) {
|
int qoi_write(const char *filename, const void *data, const qoi_desc *desc) {
|
||||||
int size;
|
FILE *f = fopen(filename, "wb");
|
||||||
void *encoded = qoi_encode(data, desc, &size);
|
if (!f) {
|
||||||
if (!encoded) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *f = fopen(filename, "wb");
|
int size;
|
||||||
if (!f) {
|
void *encoded = qoi_encode(data, desc, &size);
|
||||||
QOI_FREE(encoded);
|
if (!encoded) {
|
||||||
|
fclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(encoded, 1, size, f);
|
fwrite(encoded, 1, size, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
QOI_FREE(encoded);
|
QOI_FREE(encoded);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user