OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [java-lang/] [java_lang_VMSystem.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* System.c -- native code for java.lang.System
2
   Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
#include "java_lang_VMSystem.h"
39
 
40
#include <jcl.h>
41
 
42
#include <sys/time.h>
43
#include <stdlib.h>
44
 
45
/*
46
 * Class:     java_lang_VMSystem
47
 * Method:    setIn0
48
 * Signature: (Ljava/io/InputStream;)V
49
 */
50
JNIEXPORT void JNICALL
51
Java_java_lang_VMSystem_setIn (JNIEnv * env,
52
                               jclass thisClass __attribute__ ((__unused__)),
53
                               jobject obj)
54
{
55
  jclass cls;
56
  jfieldID field;
57
 
58
  cls = JCL_FindClass (env, "java/lang/System");
59
  if (!cls)
60
    return;
61
 
62
  field = (*env)->GetStaticFieldID (env, cls, "in", "Ljava/io/InputStream;");
63
  if (!field)
64
    return;
65
  (*env)->SetStaticObjectField (env, cls, field, obj);
66
}
67
 
68
/*
69
 * Class:     java_lang_VMSystem
70
 * Method:    setOut0
71
 * Signature: (Ljava/io/PrintStream;)V
72
 */
73
JNIEXPORT void JNICALL
74
Java_java_lang_VMSystem_setOut (JNIEnv * env,
75
                                jclass thisClass __attribute__ ((__unused__)),
76
                                jobject obj)
77
{
78
  jclass cls;
79
  jfieldID field;
80
 
81
  cls = JCL_FindClass (env, "java/lang/System");
82
  if (!cls)
83
    return;
84
 
85
  field = (*env)->GetStaticFieldID (env, cls, "out", "Ljava/io/PrintStream;");
86
  if (!field)
87
    return;
88
  (*env)->SetStaticObjectField (env, cls, field, obj);
89
}
90
 
91
/*
92
 * Class:     java_lang_VMSystem
93
 * Method:    setErr0
94
 * Signature: (Ljava/io/PrintStream;)V
95
 */
96
JNIEXPORT void JNICALL
97
Java_java_lang_VMSystem_setErr (JNIEnv * env,
98
                                jclass thisClass __attribute__ ((__unused__)),
99
                                jobject obj)
100
{
101
  jclass cls;
102
  jfieldID field;
103
 
104
  cls = JCL_FindClass (env, "java/lang/System");
105
  if (!cls)
106
    return;
107
 
108
  field = (*env)->GetStaticFieldID (env, cls, "err", "Ljava/io/PrintStream;");
109
  if (!field)
110
    return;
111
  (*env)->SetStaticObjectField (env, cls, field, obj);
112
}
113
 
114
/*
115
 * Class:     java_lang_VMSystem
116
 * Method:    nanoTime
117
 * Signature: ()J
118
 */
119
JNIEXPORT jlong JNICALL
120
Java_java_lang_VMSystem_nanoTime
121
  (JNIEnv * env __attribute__ ((__unused__)),
122
   jclass thisClass __attribute__ ((__unused__)))
123
{
124
  /* Note: this implementation copied directly from Japhar's, by Chris Toshok. */
125
  jlong result;
126
  struct timeval tp;
127
 
128
  if (gettimeofday (&tp, NULL) == -1)
129
    (*env)->FatalError (env, "gettimeofday call failed.");
130
 
131
  result = (jlong) tp.tv_sec;
132
  result *= (jlong)1000000L;
133
  result += (jlong)tp.tv_usec;
134
  result *= (jlong)1000;
135
 
136
  return result;
137
}
138
 
139
JNIEXPORT jstring JNICALL
140
Java_java_lang_VMSystem_getenv (JNIEnv * env,
141
                                jclass klass __attribute__ ((__unused__)),
142
                                jstring jname)
143
{
144
  const char *cname;
145
  const char *envname;
146
 
147
  cname = JCL_jstring_to_cstring (env, jname);
148
  if (cname == NULL)
149
    return NULL;
150
 
151
  envname = getenv (cname);
152
  if (envname == NULL)
153
    return NULL;
154
 
155
  JCL_free_cstring (env, jname, cname);
156
  return (*env)->NewStringUTF (env, envname);
157
}
158
 
159
JNIEXPORT jobject JNICALL
160
Java_java_lang_VMSystem_environ (JNIEnv *env,
161
                                jclass klass __attribute__((__unused__)))
162
{
163
  char **env_pointer;
164
  jobject variables;
165
  jclass list_class;
166
  jmethodID list_constructor;
167
  jmethodID add;
168
 
169
  list_class = (*env)->FindClass(env, "java/util/LinkedList");
170
  if (list_class == NULL)
171
    return NULL;
172
  list_constructor = (*env)->GetMethodID(env, list_class, "<init>", "()V");
173
  if (list_constructor == NULL)
174
    return NULL;
175
  variables = (*env)->NewObject(env, list_class, list_constructor);
176
  if (variables == NULL)
177
    return NULL;
178
  add = (*env)->GetMethodID(env, list_class, "add", "(Ljava/lang/Object;)Z");
179
  if (add == NULL)
180
    return NULL;
181
  env_pointer = environ;
182
  while (*env_pointer != NULL)
183
    {
184
      jstring string = (*env)->NewStringUTF(env, *env_pointer);
185
      (*env)->CallBooleanMethod(env, variables, add, string);
186
      ++env_pointer;
187
    }
188
  return variables;
189
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.