src/windows/native/common/jni_util_md.c

Print this page




 125         if (len == -1)
 126             return NULL;
 127         result = (char*) malloc(len);
 128         if (result != NULL) {
 129             if (wcstombs(result, utf16, len) == -1)
 130                 return NULL;
 131             (*env)->ReleaseStringChars(env, jstr, utf16);
 132             if (isCopy)
 133                 *isCopy = JNI_TRUE;
 134         }
 135         return result;
 136     }
 137     else
 138         return NULL;
 139 }
 140 
 141 void* getProcessHandle() {
 142     return (void*)GetModuleHandle(NULL);
 143 }
 144 









 145 /*
 146  * Windows symbols can be simple like JNI_OnLoad or __stdcall format
 147  * like _JNI_OnLoad@8. We need to handle both.
 148  */
 149 void buildJniFunctionName(const char *sym, const char *cname,
 150                           char *jniEntryName) {
 151     if (cname != NULL) {
 152         char *p = strrchr(sym, '@');
 153         if (p != NULL && p != sym) {
 154             // sym == _JNI_OnLoad@8
 155             strncpy(jniEntryName, sym, (p - sym));
 156             jniEntryName[(p-sym)] = '\0';
 157             // jniEntryName == _JNI_OnLoad
 158             strcat(jniEntryName, "_");
 159             strcat(jniEntryName, cname);
 160             strcat(jniEntryName, p);
 161             //jniEntryName == _JNI_OnLoad_cname@8
 162         } else {
 163             strcpy(jniEntryName, sym);
 164             strcat(jniEntryName, "_");


 125         if (len == -1)
 126             return NULL;
 127         result = (char*) malloc(len);
 128         if (result != NULL) {
 129             if (wcstombs(result, utf16, len) == -1)
 130                 return NULL;
 131             (*env)->ReleaseStringChars(env, jstr, utf16);
 132             if (isCopy)
 133                 *isCopy = JNI_TRUE;
 134         }
 135         return result;
 136     }
 137     else
 138         return NULL;
 139 }
 140 
 141 void* getProcessHandle() {
 142     return (void*)GetModuleHandle(NULL);
 143 }
 144 
 145 int
 146 getErrorString(int err, char *buf, size_t len)
 147 {
 148     int ret = 0;
 149     if (err == 0 || len < 1) return 0;
 150     ret = strerror_s(buf, len, err);
 151     return ret;
 152 }
 153 
 154 /*
 155  * Windows symbols can be simple like JNI_OnLoad or __stdcall format
 156  * like _JNI_OnLoad@8. We need to handle both.
 157  */
 158 void buildJniFunctionName(const char *sym, const char *cname,
 159                           char *jniEntryName) {
 160     if (cname != NULL) {
 161         char *p = strrchr(sym, '@');
 162         if (p != NULL && p != sym) {
 163             // sym == _JNI_OnLoad@8
 164             strncpy(jniEntryName, sym, (p - sym));
 165             jniEntryName[(p-sym)] = '\0';
 166             // jniEntryName == _JNI_OnLoad
 167             strcat(jniEntryName, "_");
 168             strcat(jniEntryName, cname);
 169             strcat(jniEntryName, p);
 170             //jniEntryName == _JNI_OnLoad_cname@8
 171         } else {
 172             strcpy(jniEntryName, sym);
 173             strcat(jniEntryName, "_");