~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core.qnx/library/spawner/iostream.c

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2002 - 2005 QNX Software Systems and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     QNX Software Systems - initial API and implementation
 
10
 *******************************************************************************/
 
11
/*  iostream.c
 
12
 *
 
13
 *  This is a JNI implementation of access to standard i/o streams 
 
14
 */
 
15
#include <string.h>
 
16
#include <stdlib.h>
 
17
#include <unistd.h>
 
18
#include <sys/uio.h>
 
19
#include <errno.h>
 
20
 
 
21
#include "SpawnerInputStream.h"
 
22
#include "SpawnerOutputStream.h"
 
23
 
 
24
 
 
25
#include "jni.h"
 
26
 
 
27
 
 
28
void ThrowByName(JNIEnv *env, const char *name, const char *msg);
 
29
 
 
30
#define BUFF_SIZE  (1024)
 
31
 
 
32
/* Inaccessible static: skipBuffer */
 
33
/*
 
34
 * Class:     SpawnerInputStream
 
35
 * Method:    read0
 
36
 * Signature: (I)I
 
37
 */
 
38
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0
 
39
  (JNIEnv * env, jobject proc, jint fd, jbyteArray buf, jint len)
 
40
{
 
41
        unsigned char tmpBuf[BUFF_SIZE];        
 
42
        int nBuffOffset = 0;
 
43
//      printf("Come to read0\n");
 
44
        while(len > nBuffOffset)
 
45
                {
 
46
                int nReadLen = min(len - nBuffOffset, BUFF_SIZE);
 
47
                int nread;
 
48
                nread = read(fd, tmpBuf, nReadLen);
 
49
                if(nread > 0)
 
50
                        (*env) -> SetByteArrayRegion(env, buf, nBuffOffset, nReadLen, tmpBuf);
 
51
                else
 
52
                        break;
 
53
                nBuffOffset += nread;
 
54
                if(nread != nReadLen)
 
55
                        break;
 
56
                }
 
57
//    printf("Leave read with %i bytes read\n", nBuffOffset);
 
58
        return nBuffOffset; // This is a real full readed length
 
59
 
 
60
}
 
61
 
 
62
/*
 
63
 * Class:     SpawnerInputStream
 
64
 * Method:    close0
 
65
 * Signature: (I)I
 
66
 */
 
67
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0
 
68
  (JNIEnv * env, jobject proc, jint fd)
 
69
{
 
70
        return close(fd);
 
71
}
 
72
 
 
73
/*
 
74
 * Class:     SpawnerOutputStream
 
75
 * Method:    write0
 
76
 * Signature: (I[BI)I
 
77
 */
 
78
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0
 
79
  (JNIEnv * env, jobject proc, jint fd, jbyteArray buf, jint len)
 
80
{
 
81
        unsigned char tmpBuf[BUFF_SIZE];        
 
82
        int nBuffOffset = 0;
 
83
//      int rc = 0;
 
84
//   printf("Come to write0, len = %i\n", len);
 
85
        while(len > nBuffOffset)
 
86
                {
 
87
                int nWriteLen = min(len - nBuffOffset, BUFF_SIZE);
 
88
                (*env) -> GetByteArrayRegion(env, buf, nBuffOffset, nWriteLen, tmpBuf);
 
89
//              printf("Write %i bytes; last byte = %#x\n", nWriteLen, (int)tmpBuf[nWriteLen - 1]);
 
90
                if(nWriteLen != write(fd, tmpBuf, nWriteLen)) 
 
91
                        {
 
92
//              printf("Error: written %i bytes; errno = %i, fd = %i, len = %i ", nWriteLen, errno, fd, rc);
 
93
                        ThrowByName(env, "java/io/IOException", strerror(errno));
 
94
                        }
 
95
                nBuffOffset += nWriteLen;
 
96
                }
 
97
        return 0;
 
98
}
 
99
 
 
100
/*
 
101
 * Class:     SpawnerOutputStream
 
102
 * Method:    close0
 
103
 * Signature: (I)I
 
104
 */
 
105
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0
 
106
  (JNIEnv * env, jobject proc, jint fd)
 
107
{
 
108
        return close(fd);       
 
109
}