diff options
author | Qi Wang <interwq@gwu.edu> | 2018-04-06 11:40:44 -0700 |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2018-04-09 16:50:30 -0700 |
commit | d3e0976a2c1591b9fe433e7a383d8825683995f0 (patch) | |
tree | 1f611f54eb6fdfb99390497572333deb14d7b905 /include/jemalloc/internal/malloc_io.h | |
parent | 4df483f0fd76a64e116b1c4f316f8b941078114d (diff) | |
download | platform_external_jemalloc_new-d3e0976a2c1591b9fe433e7a383d8825683995f0.tar.gz platform_external_jemalloc_new-d3e0976a2c1591b9fe433e7a383d8825683995f0.tar.bz2 platform_external_jemalloc_new-d3e0976a2c1591b9fe433e7a383d8825683995f0.zip |
Fix type warning on Windows.
Add cast since read / write has unsigned return type on windows.
Diffstat (limited to 'include/jemalloc/internal/malloc_io.h')
-rw-r--r-- | include/jemalloc/internal/malloc_io.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/jemalloc/internal/malloc_io.h b/include/jemalloc/internal/malloc_io.h index 4992d1d8..bfe556b5 100644 --- a/include/jemalloc/internal/malloc_io.h +++ b/include/jemalloc/internal/malloc_io.h @@ -63,4 +63,40 @@ void malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque, const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4); void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2); +static inline ssize_t +malloc_write_fd(int fd, const void *buf, size_t count) { +#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_write) + /* + * Use syscall(2) rather than write(2) when possible in order to avoid + * the possibility of memory allocation within libc. This is necessary + * on FreeBSD; most operating systems do not have this problem though. + * + * syscall() returns long or int, depending on platform, so capture the + * result in the widest plausible type to avoid compiler warnings. + */ + long result = syscall(SYS_write, fd, buf, count); +#else + ssize_t result = (ssize_t)write(fd, buf, +#ifdef _WIN32 + (unsigned int) +#endif + count); +#endif + return (ssize_t)result; +} + +static inline ssize_t +malloc_read_fd(int fd, void *buf, size_t count) { +#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_read) + long result = syscall(SYS_read, fd, buf, count); +#else + ssize_t result = read(fd, buf, +#ifdef _WIN32 + (unsigned int) +#endif + count); +#endif + return (ssize_t)result; +} + #endif /* JEMALLOC_INTERNAL_MALLOC_IO_H */ |