|
16 | 16 | * Lesser General Public License for more details. |
17 | 17 | */ |
18 | 18 |
|
| 19 | +#include "dispatch.h" |
| 20 | + |
| 21 | +#include <string.h> |
| 22 | + |
19 | 23 | #if defined(_WIN32) |
20 | 24 | #define WIN32_LEAN_AND_MEAN |
21 | 25 | #include <windows.h> |
|
45 | 49 | #else |
46 | 50 | #include <dlfcn.h> |
47 | 51 | #include <errno.h> |
| 52 | +#include <assert.h> |
48 | 53 | #define STRTYPE char* |
49 | 54 | #ifdef USE_DEFAULT_LIBNAME_ENCODING |
50 | 55 | #define NAME2CSTR(ENV,JSTR) newCString(ENV,JSTR) |
|
53 | 58 | #endif |
54 | 59 | #define DEFAULT_LOAD_OPTS (RTLD_LAZY|RTLD_GLOBAL) |
55 | 60 | #define LOAD_LIBRARY(NAME,OPTS) dlopen(NAME, OPTS) |
56 | | -#define LOAD_ERROR(BUF,LEN) (snprintf(BUF, LEN, "%s", dlerror()), BUF) |
57 | | -#define STR_ERROR(CODE,BUF,LEN) (strerror_r(CODE, BUF, LEN), BUF) |
| 61 | +static inline char * LOAD_ERROR(char * buf, size_t len) { |
| 62 | + const size_t count = snprintf(buf, len, "%s", dlerror()); |
| 63 | + assert(count <= len && "snprintf() output has been truncated"); |
| 64 | + return buf; |
| 65 | +} |
| 66 | +static inline char * STR_ERROR(int code, char * buf, size_t len) { |
| 67 | + // The conversion will fail if code is not a valid error code. |
| 68 | + int err = strerror_r(code, buf, len); |
| 69 | + if (err) |
| 70 | + // Depending on glib version, "Unknown error" error code |
| 71 | + // may be returned or passed using errno. |
| 72 | + err = strerror_r(err > 0 ? err : errno, buf, len); |
| 73 | + assert(err == 0 && "strerror_r() conversion has failed"); |
| 74 | + return buf; |
| 75 | +} |
58 | 76 | #define FREE_LIBRARY(HANDLE) dlclose(HANDLE) |
59 | 77 | #define FIND_ENTRY(HANDLE, NAME) dlsym(HANDLE, NAME) |
60 | 78 | #endif |
|
67 | 85 | #endif |
68 | 86 |
|
69 | 87 | #include <stdlib.h> |
70 | | -// Force XSI-compliant strerror_r (http://unixhelp.ed.ac.uk/CGI/man-cgi?strerror) |
71 | | -#ifndef _XOPEN_SOURCE |
72 | | -#define _XOPEN_SOURCE 600 |
73 | | -#endif |
74 | | -#include <string.h> |
| 88 | +#include <alloca.h> |
75 | 89 | #include <wchar.h> |
76 | 90 | #include <jni.h> |
77 | 91 |
|
78 | | -#include "dispatch.h" |
79 | | - |
80 | 92 | #ifndef NO_JAWT |
81 | 93 | #include <jawt.h> |
82 | 94 | #include <jawt_md.h> |
|
0 commit comments