< prev index next >

src/java.base/windows/native/libjava/canonicalize_md.c

Print this page




 317     }
 318 
 319     if (dst >= dend) {
 320         errno = ENAMETOOLONG;
 321         return -1;
 322     }
 323     *dst = L'\0';
 324     return 0;
 325 }
 326 
 327 /* Non-Wide character version of canonicalize.
 328    Converts to wchar and delegates to wcanonicalize. */
 329 JNIEXPORT int
 330 JDK_Canonicalize(const char *orig, char *out, int len) {
 331     wchar_t* wpath = NULL;
 332     wchar_t* wresult = NULL;
 333     int wpath_len;
 334     int ret = -1;
 335 
 336     /* Get required buffer size to convert to Unicode */
 337     wpath_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 338                                     orig, -1, NULL, 0);
 339     if (wpath_len == 0) {
 340         goto finish;
 341     }
 342 
 343     if ((wpath = (wchar_t*) malloc(sizeof(wchar_t) * wpath_len)) == NULL) {
 344         goto finish;
 345     }
 346 
 347     if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS,
 348                             orig, -1, wpath, wpath_len) == 0) {
 349         goto finish;
 350     }
 351 
 352     if ((wresult = (wchar_t*) malloc(sizeof(wchar_t) * len)) == NULL) {
 353         goto finish;
 354     }
 355 
 356     if (wcanonicalize(wpath, wresult, len) != 0) {
 357         goto finish;
 358     }
 359 
 360     if (WideCharToMultiByte(CP_THREAD_ACP, 0,
 361                             wresult, -1, out, len, NULL, NULL) == 0) {
 362         goto finish;
 363     }
 364 
 365     // Change return value to success.
 366     ret = 0;
 367 
 368 finish:
 369     free(wresult);
 370     free(wpath);
 371 
 372     return ret;
 373 }
 374 
 375 /* The appropriate location of getPrefixed() is io_util_md.c, but it is
 376    also used in a non-OpenJDK context within Oracle. There, canonicalize_md.c
 377    is already pulled in and compiled, so to avoid more complicated solutions
 378    we keep this method here.
 379  */
 380 




 317     }
 318 
 319     if (dst >= dend) {
 320         errno = ENAMETOOLONG;
 321         return -1;
 322     }
 323     *dst = L'\0';
 324     return 0;
 325 }
 326 
 327 /* Non-Wide character version of canonicalize.
 328    Converts to wchar and delegates to wcanonicalize. */
 329 JNIEXPORT int
 330 JDK_Canonicalize(const char *orig, char *out, int len) {
 331     wchar_t* wpath = NULL;
 332     wchar_t* wresult = NULL;
 333     int wpath_len;
 334     int ret = -1;
 335 
 336     /* Get required buffer size to convert to Unicode */
 337     wpath_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 338                                     orig, -1, NULL, 0);
 339     if (wpath_len == 0) {
 340         goto finish;
 341     }
 342 
 343     if ((wpath = (wchar_t*) malloc(sizeof(wchar_t) * wpath_len)) == NULL) {
 344         goto finish;
 345     }
 346 
 347     if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
 348                             orig, -1, wpath, wpath_len) == 0) {
 349         goto finish;
 350     }
 351 
 352     if ((wresult = (wchar_t*) malloc(sizeof(wchar_t) * len)) == NULL) {
 353         goto finish;
 354     }
 355 
 356     if (wcanonicalize(wpath, wresult, len) != 0) {
 357         goto finish;
 358     }
 359 
 360     if (WideCharToMultiByte(CP_ACP, 0,
 361                             wresult, -1, out, len, NULL, NULL) == 0) {
 362         goto finish;
 363     }
 364 
 365     // Change return value to success.
 366     ret = 0;
 367 
 368 finish:
 369     free(wresult);
 370     free(wpath);
 371 
 372     return ret;
 373 }
 374 
 375 /* The appropriate location of getPrefixed() is io_util_md.c, but it is
 376    also used in a non-OpenJDK context within Oracle. There, canonicalize_md.c
 377    is already pulled in and compiled, so to avoid more complicated solutions
 378    we keep this method here.
 379  */
 380 


< prev index next >