Skip to content

Commit

Permalink
utils: Move vasprintf for MSVC into general since gdb_packet.c also u…
Browse files Browse the repository at this point in the history
…ses it
  • Loading branch information
amyspark authored and dragonmux committed Jan 22, 2024
1 parent 6786c80 commit d2532d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
17 changes: 16 additions & 1 deletion src/include/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ void debug_serial_send_stdout(const uint8_t *data, size_t len);
#define strcasecmp _stricmp
#define strncasecmp _strnicmp

#endif
// FIXME: BMDA still uses this function in gdb_packet.c
// It's defined here as an export from utils.c would pollute the ABI of libbmd
static inline int vasprintf(char **strp, const char *const fmt, va_list ap)
{
const int actual_size = vsnprintf(NULL, 0, fmt, ap);
if (actual_size < 0)
return -1;

*strp = malloc(actual_size + 1);
if (!*strp)
return -1;

return vsnprintf(*strp, actual_size + 1, fmt, ap);
}

#endif /* _MSC_VER */

#endif /* INCLUDE_GENERAL_H */
15 changes: 0 additions & 15 deletions src/platforms/hosted/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@
#include "timing.h"
#include "bmp_hosted.h"

#if defined(_WIN32) && !defined(__MINGW32__)
int vasprintf(char **strp, const char *const fmt, va_list ap)
{
const int actual_size = vsnprintf(NULL, 0, fmt, ap);
if (actual_size < 0)
return -1;

*strp = malloc(actual_size + 1);
if (!*strp)
return -1;

return vsnprintf(*strp, actual_size + 1, fmt, ap);
}
#endif

void platform_delay(uint32_t ms)
{
#if defined(_WIN32) && !defined(__MINGW32__)
Expand Down
1 change: 0 additions & 1 deletion src/platforms/hosted/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#define PLATFORMS_HOSTED_UTILS_H

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

bool begins_with(const char *str, size_t str_length, const char *value);
Expand Down

0 comments on commit d2532d7

Please sign in to comment.