Skip to content

Commit

Permalink
Rip out asprintf.h
Browse files Browse the repository at this point in the history
2019 me was apparently counting individial bytes, and went through all
that effort to provide a platform-agnostic implementation of asprintf().

Grug brain says static buffer simple and good. Use static 2kB buffer +
snprintf() instead.
  • Loading branch information
vkoskiv committed Dec 3, 2023
1 parent 85278a6 commit 01d302b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
7 changes: 3 additions & 4 deletions src/driver/encoders/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "../imagefile.h"
#include "../../common/logging.h"
#include "../../vendored/asprintf.h"
#include "../../common/texture.h"
#include "../../common/assert.h"

#include "formats/png.h"
#include "formats/bmp.h"
#include "formats/qoi.h"
#include <stdio.h>

void writeImage(struct imageFile *image) {
char *suffix;
Expand All @@ -43,8 +43,8 @@ void writeImage(struct imageFile *image) {
image->type = png;
break;
}
char *buf = NULL;
asprintf(&buf, "%s%s_%04d.%s", image->filePath, image->fileName, image->count, suffix);
char buf[2048];
snprintf(buf, 2048 - 1, "%s%s_%04d.%s", image->filePath, image->fileName, image->count, suffix);
switch (image->type) {
case png:
encodePNGFromArray(buf, image->t->data.byte_p, image->t->width, image->t->height, image->info);
Expand All @@ -60,5 +60,4 @@ void writeImage(struct imageFile *image) {
ASSERT_NOT_REACHED();
break;
}
free(buf);
}
62 changes: 0 additions & 62 deletions src/vendored/asprintf.h

This file was deleted.

0 comments on commit 01d302b

Please sign in to comment.