src/java.base/unix/native/libjli/java_md_common.c

Print this page




   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
  23  * questions.
  24  */
  25 #include "java.h"

  26 
  27 /*
  28  * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
  29  * "/foo" into buf.
  30  */
  31 jboolean
  32 GetApplicationHome(char *buf, jint bufsize)
  33 {
  34     const char *execname = GetExecName();
  35     if (execname != NULL) {
  36         JLI_Snprintf(buf, bufsize, "%s", execname);
  37         buf[bufsize-1] = '\0';
  38     } else {
  39         return JNI_FALSE;
  40     }
  41 
  42     if (JLI_StrRChr(buf, '/') == 0) {
  43         buf[0] = '\0';
  44         return JNI_FALSE;
  45     }


 129                     FILE_SEPARATOR, s);
 130             result = Resolve(dir, program);
 131         }
 132         if (result != 0) break;
 133     }
 134 
 135     JLI_MemFree(tmp_path);
 136     return result;
 137 }
 138 
 139 void JLI_ReportErrorMessage(const char* fmt, ...) {
 140     va_list vl;
 141     va_start(vl, fmt);
 142     vfprintf(stderr, fmt, vl);
 143     fprintf(stderr, "\n");
 144     va_end(vl);
 145 }
 146 
 147 void JLI_ReportErrorMessageSys(const char* fmt, ...) {
 148     va_list vl;
 149     char *emsg;
 150 
 151     /*
 152      * TODO: its safer to use strerror_r but is not available on
 153      * Solaris 8. Until then....
 154      */
 155     emsg = strerror(errno);
 156     if (emsg != NULL) {
 157         fprintf(stderr, "%s\n", emsg);
 158     }
 159 
 160     va_start(vl, fmt);
 161     vfprintf(stderr, fmt, vl);
 162     fprintf(stderr, "\n");
 163     va_end(vl);
 164 }
 165 
 166 void  JLI_ReportExceptionDescription(JNIEnv * env) {
 167   (*env)->ExceptionDescribe(env);
 168 }
 169 
 170 /*
 171  *      Since using the file system as a registry is a bit risky, perform
 172  *      additional sanity checks on the identified directory to validate
 173  *      it as a valid jre/sdk.
 174  *
 175  *      Return 0 if the tests fail; otherwise return non-zero (true).
 176  *
 177  *      Note that checking for anything more than the existence of an
 178  *      executable object at bin/java relative to the path being checked




   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
  23  * questions.
  24  */
  25 #include "java.h"
  26 // #include "jdk_strerror.h"
  27 
  28 /*
  29  * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
  30  * "/foo" into buf.
  31  */
  32 jboolean
  33 GetApplicationHome(char *buf, jint bufsize)
  34 {
  35     const char *execname = GetExecName();
  36     if (execname != NULL) {
  37         JLI_Snprintf(buf, bufsize, "%s", execname);
  38         buf[bufsize-1] = '\0';
  39     } else {
  40         return JNI_FALSE;
  41     }
  42 
  43     if (JLI_StrRChr(buf, '/') == 0) {
  44         buf[0] = '\0';
  45         return JNI_FALSE;
  46     }


 130                     FILE_SEPARATOR, s);
 131             result = Resolve(dir, program);
 132         }
 133         if (result != 0) break;
 134     }
 135 
 136     JLI_MemFree(tmp_path);
 137     return result;
 138 }
 139 
 140 void JLI_ReportErrorMessage(const char* fmt, ...) {
 141     va_list vl;
 142     va_start(vl, fmt);
 143     vfprintf(stderr, fmt, vl);
 144     fprintf(stderr, "\n");
 145     va_end(vl);
 146 }
 147 
 148 void JLI_ReportErrorMessageSys(const char* fmt, ...) {
 149     va_list vl;
 150     char buf[1024];
 151 
 152     // jdk_strerror(errno, buf, (size_t) 1024)
 153     fprintf(stderr, "%s\n", strerror(errno));






 154 
 155     va_start(vl, fmt);
 156     vfprintf(stderr, fmt, vl);
 157     fprintf(stderr, "\n");
 158     va_end(vl);
 159 }
 160 
 161 void  JLI_ReportExceptionDescription(JNIEnv * env) {
 162   (*env)->ExceptionDescribe(env);
 163 }
 164 
 165 /*
 166  *      Since using the file system as a registry is a bit risky, perform
 167  *      additional sanity checks on the identified directory to validate
 168  *      it as a valid jre/sdk.
 169  *
 170  *      Return 0 if the tests fail; otherwise return non-zero (true).
 171  *
 172  *      Note that checking for anything more than the existence of an
 173  *      executable object at bin/java relative to the path being checked