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
26 #undef _LARGEFILE64_SOURCE
27 #define _LARGEFILE64_SOURCE 1
28
29 #include "jni.h"
30 #include "jvm.h"
31 #include "jvm_md.h"
32 #include "jni_util.h"
33 #include "io_util.h"
34
35 /*
36 * Platform-specific support for java.lang.Process
37 */
38 #include <assert.h>
39 #include <stddef.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include <ctype.h>
43 #include <sys/wait.h>
44 #include <signal.h>
45 #include <string.h>
46
47 #if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
48 #include <spawn.h>
231 {
232 return arr == NULL ? NULL :
233 (const char*) (*env)->GetByteArrayElements(env, arr, NULL);
234 }
235
236 static void
237 releaseBytes(JNIEnv *env, jbyteArray arr, const char* parr)
238 {
239 if (parr != NULL)
240 (*env)->ReleaseByteArrayElements(env, arr, (jbyte*) parr, JNI_ABORT);
241 }
242
243 #define IOE_FORMAT "error=%d, %s"
244
245 static void
246 throwIOException(JNIEnv *env, int errnum, const char *defaultDetail)
247 {
248 const char *detail = defaultDetail;
249 char *errmsg;
250 size_t fmtsize;
251 jstring s;
252
253 if (errnum != 0) {
254 const char *s = strerror(errnum);
255 if (strcmp(s, "Unknown error") != 0)
256 detail = s;
257 }
258 /* ASCII Decimal representation uses 2.4 times as many bits as binary. */
259 fmtsize = sizeof(IOE_FORMAT) + strlen(detail) + 3 * sizeof(errnum);
260 errmsg = NEW(char, fmtsize);
261 if (errmsg == NULL)
262 return;
263
264 snprintf(errmsg, fmtsize, IOE_FORMAT, errnum, detail);
265 s = JNU_NewStringPlatform(env, errmsg);
266 if (s != NULL) {
267 jobject x = JNU_NewObjectByName(env, "java/io/IOException",
268 "(Ljava/lang/String;)V", s);
269 if (x != NULL)
270 (*env)->Throw(env, x);
271 }
272 free(errmsg);
273 }
274
275 #ifdef DEBUG_PROCESS
276 /* Debugging process code is difficult; where to write debug output? */
|
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
26 #undef _LARGEFILE64_SOURCE
27 #define _LARGEFILE64_SOURCE 1
28
29 #include "jdk_strerror.h"
30 #include "jni.h"
31 #include "jvm.h"
32 #include "jvm_md.h"
33 #include "jni_util.h"
34 #include "io_util.h"
35
36 /*
37 * Platform-specific support for java.lang.Process
38 */
39 #include <assert.h>
40 #include <stddef.h>
41 #include <stdlib.h>
42 #include <sys/types.h>
43 #include <ctype.h>
44 #include <sys/wait.h>
45 #include <signal.h>
46 #include <string.h>
47
48 #if defined(__solaris__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
49 #include <spawn.h>
232 {
233 return arr == NULL ? NULL :
234 (const char*) (*env)->GetByteArrayElements(env, arr, NULL);
235 }
236
237 static void
238 releaseBytes(JNIEnv *env, jbyteArray arr, const char* parr)
239 {
240 if (parr != NULL)
241 (*env)->ReleaseByteArrayElements(env, arr, (jbyte*) parr, JNI_ABORT);
242 }
243
244 #define IOE_FORMAT "error=%d, %s"
245
246 static void
247 throwIOException(JNIEnv *env, int errnum, const char *defaultDetail)
248 {
249 const char *detail = defaultDetail;
250 char *errmsg;
251 size_t fmtsize;
252 char buf[1024];
253 jstring s;
254
255 if (errnum != 0) {
256 jdk_strerror(errnum, buf, (size_t) 1024);
257 if (strncmp(buf, "Unknown error", 13) != 0)
258 detail = buf;
259 }
260 /* ASCII Decimal representation uses 2.4 times as many bits as binary. */
261 fmtsize = sizeof(IOE_FORMAT) + strlen(detail) + 3 * sizeof(errnum);
262 errmsg = NEW(char, fmtsize);
263 if (errmsg == NULL)
264 return;
265
266 snprintf(errmsg, fmtsize, IOE_FORMAT, errnum, detail);
267 s = JNU_NewStringPlatform(env, errmsg);
268 if (s != NULL) {
269 jobject x = JNU_NewObjectByName(env, "java/io/IOException",
270 "(Ljava/lang/String;)V", s);
271 if (x != NULL)
272 (*env)->Throw(env, x);
273 }
274 free(errmsg);
275 }
276
277 #ifdef DEBUG_PROCESS
278 /* Debugging process code is difficult; where to write debug output? */
|