32 |
#include <fcntl.h> |
#include <fcntl.h> |
33 |
#include <unistd.h> |
#include <unistd.h> |
34 |
#include <sys/stat.h> |
#include <sys/stat.h> |
35 |
|
#include <malloc.h> |
36 |
|
|
37 |
#include <jni.h> |
#include <jni.h> |
38 |
|
#include <jcl.h> |
39 |
|
|
40 |
#include "javaio.h" |
#include "javaio.h" |
41 |
|
|
|
#include <malloc.h> |
|
42 |
|
|
43 |
/* |
/* |
44 |
* Function to open a file |
* Function to open a file |
59 |
if (fd == -1) |
if (fd == -1) |
60 |
{ |
{ |
61 |
if (errno == ENOENT) |
if (errno == ENOENT) |
62 |
_javaio_ThrowException(env, "java/io/FileNotFoundException", |
JCL_ThrowException(env, "java/io/FileNotFoundException", |
63 |
strerror(errno)); |
strerror(errno)); |
64 |
else |
else |
65 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
66 |
} |
} |
67 |
|
|
68 |
return(fd); |
return(fd); |
81 |
|
|
82 |
rc = close(fd); |
rc = close(fd); |
83 |
if (rc == -1) |
if (rc == -1) |
84 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
85 |
} |
} |
86 |
|
|
87 |
/*************************************************************************/ |
/*************************************************************************/ |
97 |
|
|
98 |
cur = lseek(fd, 0, SEEK_CUR); |
cur = lseek(fd, 0, SEEK_CUR); |
99 |
if (cur == -1) |
if (cur == -1) |
100 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
101 |
|
|
102 |
new = lseek(fd, num_bytes, SEEK_CUR); |
new = lseek(fd, num_bytes, SEEK_CUR); |
103 |
if (new == -1) |
if (new == -1) |
104 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
105 |
|
|
106 |
return(new - cur); |
return(new - cur); |
107 |
} |
} |
121 |
rc = fstat(fd, &buf); |
rc = fstat(fd, &buf); |
122 |
if (rc == -1) |
if (rc == -1) |
123 |
{ |
{ |
124 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
125 |
return(-1); |
return(-1); |
126 |
} |
} |
127 |
|
|
144 |
bufptr = (*env)->GetByteArrayElements(env, buf, JNI_FALSE); |
bufptr = (*env)->GetByteArrayElements(env, buf, JNI_FALSE); |
145 |
if (!bufptr) |
if (!bufptr) |
146 |
{ |
{ |
147 |
_javaio_ThrowException(env, "java/io/IOException", "Internal Error"); |
JCL_ThrowException(env, "java/io/IOException", "Internal Error"); |
148 |
return(-1); |
return(-1); |
149 |
} |
} |
150 |
|
|
151 |
rc = read(fd, (bufptr + offset), len); |
rc = read(fd, (bufptr + offset), len); |
152 |
if (rc == -1) |
if (rc == -1) |
153 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
154 |
|
|
155 |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
156 |
|
|
176 |
bufptr = (*env)->GetByteArrayElements(env, buf, 0); |
bufptr = (*env)->GetByteArrayElements(env, buf, 0); |
177 |
if (!bufptr) |
if (!bufptr) |
178 |
{ |
{ |
179 |
_javaio_ThrowException(env, "java/io/IOException", "Internal Error"); |
JCL_ThrowException(env, "java/io/IOException", "Internal Error"); |
180 |
return(-1); |
return(-1); |
181 |
} |
} |
182 |
|
|
183 |
rc = write(fd, (bufptr + offset), len); |
rc = write(fd, (bufptr + offset), len); |
184 |
if (rc == -1) |
if (rc == -1) |
185 |
_javaio_ThrowException(env, "java/io/IOException", strerror(errno)); |
JCL_ThrowException(env, "java/io/IOException", strerror(errno)); |
186 |
|
|
187 |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
(*env)->ReleaseByteArrayElements(env, buf, bufptr, 0); |
188 |
|
|