Skip to content
This repository was archived by the owner on Jul 14, 2019. It is now read-only.

Commit d35f3f0

Browse files
author
Lior Amram
committed
ribify more malloc.h funcs
1 parent efcdafc commit d35f3f0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

include/ribify.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ void ribify_free(void *ptr);
2727
void *ribify_calloc(size_t nmemb, size_t size);
2828
void *ribify_realloc(void *ptr, size_t size);
2929
char *ribify_strdup(const char *s);
30+
char *ribify_wcsdup(const wchar_t *s);
31+
size_t ribify_malloc_usable_size(void *ptr);
3032

3133
#endif // _RIBIFY__H_

make/ribs.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ifeq ($(GCCVER_GTE_4_7),1)
3636
CFLAGS+=-ftrack-macro-expansion=2
3737
endif
3838

39-
RIBIFY_SYMS+=write read socket connect fcntl recv recvfrom recvmsg send sendto sendmsg readv writev pipe pipe2 nanosleep usleep sleep sendfile malloc calloc realloc free strdup close
39+
RIBIFY_SYMS+=write read socket connect fcntl recv recvfrom recvmsg send sendto sendmsg readv writev pipe pipe2 nanosleep usleep sleep sendfile malloc calloc realloc free strdup close wcsdup malloc_usable_size
4040

4141
ifdef UGLY_GETADDRINFO_WORKAROUND
4242
LDFLAGS+=-lanl

src/ribify.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <signal.h>
3030
#include <sys/timerfd.h>
3131
#include <sys/sendfile.h>
32+
#include <wchar.h>
3233

3334
int _ribified_socket(int domain, int type, int protocol) {
3435
int sockfd = socket(domain, type | SOCK_NONBLOCK, protocol);
@@ -223,15 +224,28 @@ char *_ribified_strdup(const char *s) {
223224
return mem;
224225
}
225226

227+
char *_ribified_wcsdup(const wchar_t *s) {
228+
size_t l = (wcslen(s) + 1) * sizeof(wchar_t);
229+
char *mem = _ribified_malloc(l);
230+
memcpy(mem, s, l);
231+
return mem;
232+
}
233+
234+
size_t _ribified_malloc_usable_size(void *ptr) {
235+
return *(uint32_t *)(ptr - sizeof(uint32_t));
236+
}
237+
226238
int _ribified_close(int fd) {
227239
return ribs_close(fd);
228240
}
229241

230242
void *ribify_malloc(size_t size) __attribute__ ((weak, alias("_ribified_malloc")));
243+
size_t ribify_malloc_usable_size(void *ptr) __attribute__ ((weak, alias("_ribified_malloc_usable_size")));
231244
void ribify_free(void *ptr) __attribute__ ((weak, alias("_ribified_free")));
232245
void *ribify_calloc(size_t nmemb, size_t size) __attribute__ ((weak, alias("_ribified_calloc")));
233246
void *ribify_realloc(void *ptr, size_t size) __attribute__ ((weak, alias("_ribified_realloc")));
234247
char *ribify_strdup(const char *s) __attribute__ ((weak, alias("_ribified_strdup")));
248+
char *ribify_wcsdup(const wchar_t *s) __attribute__ ((weak, alias("_ribified_wcsdup")));
235249

236250
#ifdef UGLY_GETADDRINFO_WORKAROUND
237251
int _ribified_getaddrinfo(const char *node, const char *service,

0 commit comments

Comments
 (0)