mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-22 11:04:57 -04:00
fix: correct write count in savePPM
Previously, the `fwrite` call always returned 3 if it succeeded, and so `savePPM` would return 1 even if the entire pixel buffer was successfully written to file (except in the trivial case `sx * sy == 1`). This changes `savePPM` to return 0 if it was successful.
This commit is contained in:
parent
91ba293616
commit
629e68cabf
5
util.c
5
util.c
@ -470,9 +470,10 @@ int savePPM(const char *path, const unsigned char *pixels, const unsigned int sx
|
|||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
fprintf(fp, "P6\n%d %d\n255\n", sx, sy);
|
fprintf(fp, "P6\n%d %d\n255\n", sx, sy);
|
||||||
int written = fwrite(pixels, sx*sy, 3, fp);
|
size_t pixelsLen = 3 * sx * sy;
|
||||||
|
size_t written = fwrite(pixels, sizeof pixels[0], pixelsLen, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return (unsigned int)written != 3*sx*sy;
|
return written != pixelsLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user