< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 478     int rc;
 479     va_list vl;
 480     if (size == 0 || buffer == NULL)
 481         return -1;
 482     buffer[0] = '\0';
 483     va_start(vl, format);
 484     rc = vsnprintf(buffer, size, format, vl);
 485     va_end(vl);
 486     /* force a null terminator, if something is amiss */
 487     if (rc < 0) {
 488         /* apply ansi semantics */
 489         buffer[size - 1] = '\0';
 490         return (int)size;
 491     } else if (rc == size) {
 492         /* force a null terminator */
 493         buffer[size - 1] = '\0';
 494     }
 495     return rc;
 496 }
 497 
 498 void
 499 JLI_ReportErrorMessage(const char* fmt, ...) {
 500     va_list vl;
 501     va_start(vl,fmt);
 502 
 503     if (IsJavaw()) {
 504         char *message;
 505 
 506         /* get the length of the string we need */
 507         int n = _vscprintf(fmt, vl);
 508 
 509         message = (char *)JLI_MemAlloc(n + 1);
 510         _vsnprintf(message, n, fmt, vl);
 511         message[n]='\0';
 512         MessageBox(NULL, message, "Java Virtual Machine Launcher",
 513             (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 514         JLI_MemFree(message);
 515     } else {
 516         vfprintf(stderr, fmt, vl);
 517         fprintf(stderr, "\n");
 518     }
 519     va_end(vl);
 520 }
 521 
 522 /*
 523  * Just like JLI_ReportErrorMessage, except that it concatenates the system
 524  * error message if any, its upto the calling routine to correctly
 525  * format the separation of the messages.
 526  */
 527 void
 528 JLI_ReportErrorMessageSys(const char *fmt, ...)
 529 {
 530     va_list vl;
 531 
 532     int save_errno = errno;
 533     DWORD       errval;
 534     jboolean freeit = JNI_FALSE;
 535     char  *errtext = NULL;
 536 
 537     va_start(vl, fmt);
 538 
 539     if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
 540         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
 541             FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
 542             NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
 543         if (errtext == NULL || n == 0) {                /* Paranoia check */
 544             errtext = "";
 545             n = 0;
 546         } else {
 547             freeit = JNI_TRUE;


 571         if (freeit) {
 572            JLI_StrCat(message, errtext);
 573         }
 574 
 575         MessageBox(NULL, message, "Java Virtual Machine Launcher",
 576             (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 577 
 578         JLI_MemFree(message);
 579     } else {
 580         vfprintf(stderr, fmt, vl);
 581         if (freeit) {
 582            fprintf(stderr, "%s", errtext);
 583         }
 584     }
 585     if (freeit) {
 586         (void)LocalFree((HLOCAL)errtext);
 587     }
 588     va_end(vl);
 589 }
 590 
 591 void  JLI_ReportExceptionDescription(JNIEnv * env) {

 592     if (IsJavaw()) {
 593        /*
 594         * This code should be replaced by code which opens a window with
 595         * the exception detail message, for now atleast put a dialog up.
 596         */
 597         MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",
 598                (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 599     } else {
 600         (*env)->ExceptionDescribe(env);
 601     }
 602 }
 603 
 604 /*
 605  * Wrapper for platform dependent unsetenv function.
 606  */
 607 int
 608 UnsetEnv(char *name)
 609 {
 610     int ret;
 611     char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 478     int rc;
 479     va_list vl;
 480     if (size == 0 || buffer == NULL)
 481         return -1;
 482     buffer[0] = '\0';
 483     va_start(vl, format);
 484     rc = vsnprintf(buffer, size, format, vl);
 485     va_end(vl);
 486     /* force a null terminator, if something is amiss */
 487     if (rc < 0) {
 488         /* apply ansi semantics */
 489         buffer[size - 1] = '\0';
 490         return (int)size;
 491     } else if (rc == size) {
 492         /* force a null terminator */
 493         buffer[size - 1] = '\0';
 494     }
 495     return rc;
 496 }
 497 
 498 JNIEXPORT void JNICALL
 499 JLI_ReportErrorMessage(const char* fmt, ...) {
 500     va_list vl;
 501     va_start(vl,fmt);
 502 
 503     if (IsJavaw()) {
 504         char *message;
 505 
 506         /* get the length of the string we need */
 507         int n = _vscprintf(fmt, vl);
 508 
 509         message = (char *)JLI_MemAlloc(n + 1);
 510         _vsnprintf(message, n, fmt, vl);
 511         message[n]='\0';
 512         MessageBox(NULL, message, "Java Virtual Machine Launcher",
 513             (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 514         JLI_MemFree(message);
 515     } else {
 516         vfprintf(stderr, fmt, vl);
 517         fprintf(stderr, "\n");
 518     }
 519     va_end(vl);
 520 }
 521 
 522 /*
 523  * Just like JLI_ReportErrorMessage, except that it concatenates the system
 524  * error message if any, its upto the calling routine to correctly
 525  * format the separation of the messages.
 526  */
 527 JNIEXPORT void JNICALL
 528 JLI_ReportErrorMessageSys(const char *fmt, ...)
 529 {
 530     va_list vl;
 531 
 532     int save_errno = errno;
 533     DWORD       errval;
 534     jboolean freeit = JNI_FALSE;
 535     char  *errtext = NULL;
 536 
 537     va_start(vl, fmt);
 538 
 539     if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
 540         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
 541             FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
 542             NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
 543         if (errtext == NULL || n == 0) {                /* Paranoia check */
 544             errtext = "";
 545             n = 0;
 546         } else {
 547             freeit = JNI_TRUE;


 571         if (freeit) {
 572            JLI_StrCat(message, errtext);
 573         }
 574 
 575         MessageBox(NULL, message, "Java Virtual Machine Launcher",
 576             (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 577 
 578         JLI_MemFree(message);
 579     } else {
 580         vfprintf(stderr, fmt, vl);
 581         if (freeit) {
 582            fprintf(stderr, "%s", errtext);
 583         }
 584     }
 585     if (freeit) {
 586         (void)LocalFree((HLOCAL)errtext);
 587     }
 588     va_end(vl);
 589 }
 590 
 591 JNIEXPORT void JNICALL
 592 JLI_ReportExceptionDescription(JNIEnv * env) {
 593     if (IsJavaw()) {
 594        /*
 595         * This code should be replaced by code which opens a window with
 596         * the exception detail message, for now atleast put a dialog up.
 597         */
 598         MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",
 599                (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
 600     } else {
 601         (*env)->ExceptionDescribe(env);
 602     }
 603 }
 604 
 605 /*
 606  * Wrapper for platform dependent unsetenv function.
 607  */
 608 int
 609 UnsetEnv(char *name)
 610 {
 611     int ret;
 612     char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);


< prev index next >