diff options
author | Jason Evans <je@facebook.com> | 2010-09-20 23:05:41 (GMT) |
---|---|---|
committer | Jason Evans <je@facebook.com> | 2010-09-20 23:05:41 (GMT) |
commit | a09f55c87d799e6e0e64972838ca6768027e9174 (patch) | |
tree | c62cf5b991d3aff066e0398d0a390c60f7ce5903 /jemalloc/src | |
parent | 28177d466fbbfd10927b4d05655c2ec6711faa1b (diff) | |
download | jemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.zip jemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.tar.gz jemalloc-a09f55c87d799e6e0e64972838ca6768027e9174.tar.bz2 |
Wrap strerror_r().
Create the buferror() function, which wraps strerror_r(). This is
necessary because glibc provides a non-standard strerror_r().
Diffstat (limited to 'jemalloc/src')
-rw-r--r-- | jemalloc/src/chunk_mmap.c | 11 | ||||
-rw-r--r-- | jemalloc/src/chunk_swap.c | 7 | ||||
-rw-r--r-- | jemalloc/src/jemalloc.c | 19 |
3 files changed, 29 insertions, 8 deletions
diff --git a/jemalloc/src/chunk_mmap.c b/jemalloc/src/chunk_mmap.c index a3d09e9..bc36755 100644 --- a/jemalloc/src/chunk_mmap.c +++ b/jemalloc/src/chunk_mmap.c @@ -28,7 +28,8 @@ static pthread_key_t mmap_unaligned_tsd; static void *pages_map(void *addr, size_t size, bool noreserve); static void pages_unmap(void *addr, size_t size); -static void *chunk_alloc_mmap_slow(size_t size, bool unaligned, bool noreserve); +static void *chunk_alloc_mmap_slow(size_t size, bool unaligned, + bool noreserve); static void *chunk_alloc_mmap_internal(size_t size, bool noreserve); /******************************************************************************/ @@ -57,9 +58,9 @@ pages_map(void *addr, size_t size, bool noreserve) * We succeeded in mapping memory, but not in the right place. */ if (munmap(ret, size) == -1) { - char buf[STRERROR_BUF]; + char buf[BUFERROR_BUF]; - strerror_r(errno, buf, sizeof(buf)); + buferror(errno, buf, sizeof(buf)); malloc_write("<jemalloc>: Error in munmap(): "); malloc_write(buf); malloc_write("\n"); @@ -79,9 +80,9 @@ pages_unmap(void *addr, size_t size) { if (munmap(addr, size) == -1) { - char buf[STRERROR_BUF]; + char buf[BUFERROR_BUF]; - strerror_r(errno, buf, sizeof(buf)); + buferror(errno, buf, sizeof(buf)); malloc_write("<jemalloc>: Error in munmap(): "); malloc_write(buf); malloc_write("\n"); diff --git a/jemalloc/src/chunk_swap.c b/jemalloc/src/chunk_swap.c index ed9e414..ee038ba 100644 --- a/jemalloc/src/chunk_swap.c +++ b/jemalloc/src/chunk_swap.c @@ -294,9 +294,10 @@ chunk_swap_enable(const int *fds, unsigned nfds, bool prezeroed) void *addr = mmap((void *)((uintptr_t)vaddr + voff), sizes[i], PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fds[i], 0); if (addr == MAP_FAILED) { - char buf[STRERROR_BUF]; + char buf[BUFERROR_BUF]; - strerror_r(errno, buf, sizeof(buf)); + + buferror(errno, buf, sizeof(buf)); malloc_write( "<jemalloc>: Error in mmap(..., MAP_FIXED, ...): "); malloc_write(buf); @@ -304,7 +305,7 @@ chunk_swap_enable(const int *fds, unsigned nfds, bool prezeroed) if (opt_abort) abort(); if (munmap(vaddr, voff) == -1) { - strerror_r(errno, buf, sizeof(buf)); + buferror(errno, buf, sizeof(buf)); malloc_write("<jemalloc>: Error in munmap(): "); malloc_write(buf); malloc_write("\n"); diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index 40c3a63..0b60ce6 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -139,6 +139,25 @@ choose_arena_hard(void) return (ret); } +/* + * glibc provides a non-standard strerror_r() when _GNU_SOURCE is defined, so + * provide a wrapper. + */ +int +buferror(int errnum, char *buf, size_t buflen) +{ +#ifdef _GNU_SOURCE + char *b = strerror_r(errno, buf, buflen); + if (b != buf) { + strncpy(buf, b, buflen); + buf[buflen-1] = '\0'; + } + return (0); +#else + return (strerror_r(errno, buf, buflen)); +#endif +} + static void stats_print_atexit(void) { |