Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions suite/cstest/include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <stddef.h>

#include "../../../utils.h"

#define MAX_ASM_TXT_MEM 1024
#define X86_16 0
#define X86_32 1
Expand Down
2 changes: 1 addition & 1 deletion suite/cstest/src/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ char *cs_strndup(const char *s, size_t n)
if (!s) {
return NULL;
}
size_t l = strnlen(s, n);
size_t l = cs_strnlen(s, n);
if (l == SIZE_MAX) {
return NULL;
}
Expand Down
15 changes: 15 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ char *cs_strdup(const char *str)
return (char *)memmove(new, str, len);
}

// Portable strnlen replacement for platforms that lack it
// (e.g. Mac OS X 10.5 Leopard).
size_t cs_strnlen(const char *str, size_t n)
{
if (!str)
return 0;

size_t l = 0;

while (l < n && str[l] != '\0')
Comment thread
Rot127 marked this conversation as resolved.
l++;

return l;
}

// we need this since Windows doesn't have snprintf()
int cs_snprintf(char *buffer, size_t size, const char *fmt, ...)
{
Expand Down
5 changes: 5 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ unsigned int count_positive8(const unsigned char *list);

char *cs_strdup(const char *str);

// Portable strnlen replacement. Returns the length of @str,
// up to a maximum of @n. Needed because strnlen() is not
// available on all platforms (e.g. Mac OS X 10.5 Leopard).
size_t cs_strnlen(const char *str, size_t n);

#define MIN(x, y) ((x) < (y) ? (x) : (y))

// we need this since Windows doesn't have snprintf()
Expand Down
Loading