< prev index next >

src/java.base/windows/native/libjli/java_md.c

Print this page




 487     /* force a null terminator, if something is amiss */
 488     if (rc < 0) {
 489         /* apply ansi semantics */
 490         buffer[size - 1] = '\0';
 491         return (int)size;
 492     } else if (rc == size) {
 493         /* force a null terminator */
 494         buffer[size - 1] = '\0';
 495     }
 496     return rc;
 497 }
 498 
 499 static errno_t convert_to_unicode(const char* path, const wchar_t* prefix, wchar_t** wpath) {
 500     int unicode_path_len;
 501     size_t prefix_len, wpath_len;
 502 
 503     /*
 504      * Get required buffer size to convert to Unicode.
 505      * The return value includes the terminating null character.
 506      */
 507     unicode_path_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 508                                            path, -1, NULL, 0);
 509     if (unicode_path_len == 0) {
 510         return EINVAL;
 511     }
 512 
 513     prefix_len = wcslen(prefix);
 514     wpath_len = prefix_len + unicode_path_len;
 515     *wpath = (wchar_t*)JLI_MemAlloc(wpath_len * sizeof(wchar_t));
 516     if (*wpath == NULL) {
 517         return ENOMEM;
 518     }
 519 
 520     wcsncpy(*wpath, prefix, prefix_len);
 521     if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 522                             path, -1, &((*wpath)[prefix_len]), (int)wpath_len) == 0) {
 523         JLI_MemFree(*wpath);
 524         *wpath = NULL;
 525         return EINVAL;
 526     }
 527 
 528     return ERROR_SUCCESS;
 529 }
 530 
 531 /* taken from hotspot and slightly adjusted for jli lib;
 532  * creates a UNC/ELP path from input 'path'
 533  * the return buffer is allocated in C heap and needs to be freed using
 534  * JLI_MemFree by the caller.
 535  */
 536 static wchar_t* create_unc_path(const char* path, errno_t* err) {
 537     wchar_t* wpath = NULL;
 538     size_t converted_chars = 0;
 539     size_t path_len = strlen(path) + 1; /* includes the terminating NULL */
 540     if (path[0] == '\\' && path[1] == '\\') {
 541         if (path[2] == '?' && path[3] == '\\') {




 487     /* force a null terminator, if something is amiss */
 488     if (rc < 0) {
 489         /* apply ansi semantics */
 490         buffer[size - 1] = '\0';
 491         return (int)size;
 492     } else if (rc == size) {
 493         /* force a null terminator */
 494         buffer[size - 1] = '\0';
 495     }
 496     return rc;
 497 }
 498 
 499 static errno_t convert_to_unicode(const char* path, const wchar_t* prefix, wchar_t** wpath) {
 500     int unicode_path_len;
 501     size_t prefix_len, wpath_len;
 502 
 503     /*
 504      * Get required buffer size to convert to Unicode.
 505      * The return value includes the terminating null character.
 506      */
 507     unicode_path_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 508                                            path, -1, NULL, 0);
 509     if (unicode_path_len == 0) {
 510         return EINVAL;
 511     }
 512 
 513     prefix_len = wcslen(prefix);
 514     wpath_len = prefix_len + unicode_path_len;
 515     *wpath = (wchar_t*)JLI_MemAlloc(wpath_len * sizeof(wchar_t));
 516     if (*wpath == NULL) {
 517         return ENOMEM;
 518     }
 519 
 520     wcsncpy(*wpath, prefix, prefix_len);
 521     if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 522                             path, -1, &((*wpath)[prefix_len]), (int)wpath_len) == 0) {
 523         JLI_MemFree(*wpath);
 524         *wpath = NULL;
 525         return EINVAL;
 526     }
 527 
 528     return ERROR_SUCCESS;
 529 }
 530 
 531 /* taken from hotspot and slightly adjusted for jli lib;
 532  * creates a UNC/ELP path from input 'path'
 533  * the return buffer is allocated in C heap and needs to be freed using
 534  * JLI_MemFree by the caller.
 535  */
 536 static wchar_t* create_unc_path(const char* path, errno_t* err) {
 537     wchar_t* wpath = NULL;
 538     size_t converted_chars = 0;
 539     size_t path_len = strlen(path) + 1; /* includes the terminating NULL */
 540     if (path[0] == '\\' && path[1] == '\\') {
 541         if (path[2] == '?' && path[3] == '\\') {


< prev index next >