mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
Try to avoid strdup to avoid portability issues
This commit is contained in:
parent
40c889b562
commit
47ec7c0782
@ -104,7 +104,7 @@
|
|||||||
#include <string.h> /* for memcpy, memset */
|
#include <string.h> /* for memcpy, memset */
|
||||||
#include <stddef.h> /* for ptrdiff_t, size_t */
|
#include <stddef.h> /* for ptrdiff_t, size_t */
|
||||||
#include <stdint.h> /* for uint32_t */
|
#include <stdint.h> /* for uint32_t */
|
||||||
#include <string.h> /* for strdup */
|
#include <string.h> /* for strlen */
|
||||||
|
|
||||||
#define RHMAP_LEN(b) ((b) ? RHMAP__HDR(b)->len : 0)
|
#define RHMAP_LEN(b) ((b) ? RHMAP__HDR(b)->len : 0)
|
||||||
#define RHMAP_MAX(b) ((b) ? RHMAP__HDR(b)->maxlen : 0)
|
#define RHMAP_MAX(b) ((b) ? RHMAP__HDR(b)->maxlen : 0)
|
||||||
@ -261,7 +261,21 @@ RHMAP__UNUSED static ptrdiff_t rhmap__idx(struct rhmap__hdr* hdr, uint32_t key,
|
|||||||
}
|
}
|
||||||
if (!hdr->keys[i])
|
if (!hdr->keys[i])
|
||||||
{
|
{
|
||||||
if (add) { hdr->len++; hdr->keys[i] = key; if (str) hdr->key_strs[i] = strdup(str); return (ptrdiff_t)i; }
|
if (add)
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
char *t;
|
||||||
|
|
||||||
|
hdr->len++;
|
||||||
|
hdr->keys[i] = key;
|
||||||
|
l = strlen(str);
|
||||||
|
t = malloc(l + 1);
|
||||||
|
memcpy(t, s, l);
|
||||||
|
t[l] = '\0';
|
||||||
|
if (str)
|
||||||
|
hdr->key_strs[i] = t;
|
||||||
|
return (ptrdiff_t)i;
|
||||||
|
}
|
||||||
return (ptrdiff_t)-1;
|
return (ptrdiff_t)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user