File: | file.c |
Location: | line 335, column 9 |
Description: | Value stored to 'towrite' is never read |
1 | /* Licensed to the Apache Software Foundation (ASF) under one or more |
2 | * contributor license agreements. See the NOTICE file distributed with |
3 | * this work for additional information regarding copyright ownership. |
4 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
5 | * (the "License"); you may not use this file except in compliance with |
6 | * the License. You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | /* |
18 | * |
19 | * @author Mladen Turk |
20 | * @version $Id: file.c 1442587 2013-02-05 13:49:48Z rjung $ |
21 | */ |
22 | |
23 | #include "tcn.h" |
24 | #include "apr_file_io.h" |
25 | |
26 | |
27 | TCN_IMPLEMENT_CALL(jint, File, close)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_close(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
28 | { |
29 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
30 | UNREFERENCED_STDARGSe = e; o = o; |
31 | return (jint)apr_file_close(f); |
32 | } |
33 | |
34 | TCN_IMPLEMENT_CALL(jint, File, eof)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_eof(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
35 | { |
36 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
37 | UNREFERENCED_STDARGSe = e; o = o; |
38 | return (jint)apr_file_eof(f); |
39 | } |
40 | |
41 | TCN_IMPLEMENT_CALL(jint, File, flush)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_flush(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
42 | { |
43 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
44 | UNREFERENCED_STDARGSe = e; o = o; |
45 | return (jint)apr_file_flush(f); |
46 | } |
47 | |
48 | TCN_IMPLEMENT_CALL(jint, File, unlock)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_unlock(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
49 | { |
50 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
51 | UNREFERENCED_STDARGSe = e; o = o; |
52 | return (jint)apr_file_unlock(f); |
53 | } |
54 | |
55 | TCN_IMPLEMENT_CALL(jint, File, flagsGet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_flagsGet(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
56 | { |
57 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
58 | UNREFERENCED_STDARGSe = e; o = o; |
59 | return (jint)apr_file_flags_get(f); |
60 | } |
61 | |
62 | TCN_IMPLEMENT_CALL(jint, File, lock)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_lock(TCN_STDARGSJNIEnv *e, jobject o, jlong file, jint flags) |
63 | { |
64 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
65 | UNREFERENCED_STDARGSe = e; o = o; |
66 | return (jint)apr_file_lock(f, (int)flags); |
67 | } |
68 | |
69 | TCN_IMPLEMENT_CALL(jint, File, trunc)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_trunc(TCN_STDARGSJNIEnv *e, jobject o, jlong file, jlong off) |
70 | { |
71 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
72 | UNREFERENCED_STDARGSe = e; o = o; |
73 | return (jint)apr_file_trunc(f, (apr_off_t)off); |
74 | } |
75 | |
76 | TCN_IMPLEMENT_CALL(jlong, File, open)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_File_open(TCN_STDARGSJNIEnv *e, jobject o, jstring fname, |
77 | jint flag, jint perm, |
78 | jlong pool) |
79 | { |
80 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
81 | apr_file_t *f = NULL((void*)0); |
82 | TCN_ALLOC_CSTRING(fname)const char *cfname = fname ? (const char *)((*e)->GetStringUTFChars (e, fname, 0)) : ((void*)0); |
83 | |
84 | UNREFERENCED(o)(o) = (o); |
85 | TCN_THROW_IF_ERR(apr_file_open(&f, J2S(fname), (apr_int32_t)flag,if (1) { apr_status_t R = (apr_file_open(&f, cfname, (apr_int32_t )flag, (apr_fileperms_t)perm, p)); if (R != 0) { tcn_ThrowAPRException (e, R); (f) = 0; goto cleanup; } } else (void)(0) |
86 | (apr_fileperms_t)perm, p), f)if (1) { apr_status_t R = (apr_file_open(&f, cfname, (apr_int32_t )flag, (apr_fileperms_t)perm, p)); if (R != 0) { tcn_ThrowAPRException (e, R); (f) = 0; goto cleanup; } } else (void)(0); |
87 | |
88 | cleanup: |
89 | TCN_FREE_CSTRING(fname)if (cfname) (*e)->ReleaseStringUTFChars(e, fname, cfname); |
90 | return P2J(f)((jlong)((long)(f))); |
91 | } |
92 | |
93 | TCN_IMPLEMENT_CALL(jlong, File, mktemp)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_File_mktemp(TCN_STDARGSJNIEnv *e, jobject o, jstring templ, |
94 | jint flags, |
95 | jlong pool) |
96 | { |
97 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
98 | apr_file_t *f = NULL((void*)0); |
99 | char *ctempl = tcn_strdup(e, templ); |
100 | |
101 | UNREFERENCED(o)(o) = (o); |
102 | if (!ctempl) { |
103 | TCN_THROW_OS_ERROR(e)tcn_ThrowAPRException((e), ((*__errno_location ()))); |
104 | return 0; |
105 | } |
106 | TCN_THROW_IF_ERR(apr_file_mktemp(&f, ctempl,if (1) { apr_status_t R = (apr_file_mktemp(&f, ctempl, (apr_int32_t )flags, p)); if (R != 0) { tcn_ThrowAPRException(e, R); (f) = 0; goto cleanup; } } else (void)(0) |
107 | (apr_int32_t)flags, p), f)if (1) { apr_status_t R = (apr_file_mktemp(&f, ctempl, (apr_int32_t )flags, p)); if (R != 0) { tcn_ThrowAPRException(e, R); (f) = 0; goto cleanup; } } else (void)(0); |
108 | |
109 | cleanup: |
110 | free(ctempl); |
111 | return P2J(f)((jlong)((long)(f))); |
112 | } |
113 | |
114 | TCN_IMPLEMENT_CALL(jint, File, remove)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_remove(TCN_STDARGSJNIEnv *e, jobject o, jstring path, jlong pool) |
115 | { |
116 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
117 | TCN_ALLOC_CSTRING(path)const char *cpath = path ? (const char *)((*e)->GetStringUTFChars (e, path, 0)) : ((void*)0); |
118 | apr_status_t rv; |
119 | |
120 | UNREFERENCED(o)(o) = (o); |
121 | rv = apr_file_remove(J2S(path)cpath, p); |
122 | TCN_FREE_CSTRING(path)if (cpath) (*e)->ReleaseStringUTFChars(e, path, cpath); |
123 | return (jint)rv; |
124 | } |
125 | |
126 | TCN_IMPLEMENT_CALL(jint, File, rename)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_rename(TCN_STDARGSJNIEnv *e, jobject o, jstring from, |
127 | jstring to, jlong pool) |
128 | { |
129 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
130 | TCN_ALLOC_CSTRING(from)const char *cfrom = from ? (const char *)((*e)->GetStringUTFChars (e, from, 0)) : ((void*)0); |
131 | TCN_ALLOC_CSTRING(to)const char *cto = to ? (const char *)((*e)->GetStringUTFChars (e, to, 0)) : ((void*)0); |
132 | apr_status_t rv; |
133 | |
134 | UNREFERENCED(o)(o) = (o); |
135 | rv = apr_file_rename(J2S(from)cfrom, J2S(to)cto, p); |
136 | TCN_FREE_CSTRING(from)if (cfrom) (*e)->ReleaseStringUTFChars(e, from, cfrom); |
137 | TCN_FREE_CSTRING(to)if (cto) (*e)->ReleaseStringUTFChars(e, to, cto); |
138 | return (jint)rv; |
139 | } |
140 | |
141 | TCN_IMPLEMENT_CALL(jint, File, copy)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_copy(TCN_STDARGSJNIEnv *e, jobject o, jstring from, |
142 | jstring to, jint perms, jlong pool) |
143 | { |
144 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
145 | TCN_ALLOC_CSTRING(from)const char *cfrom = from ? (const char *)((*e)->GetStringUTFChars (e, from, 0)) : ((void*)0); |
146 | TCN_ALLOC_CSTRING(to)const char *cto = to ? (const char *)((*e)->GetStringUTFChars (e, to, 0)) : ((void*)0); |
147 | apr_status_t rv; |
148 | |
149 | UNREFERENCED(o)(o) = (o); |
150 | rv = apr_file_copy(J2S(from)cfrom, J2S(to)cto, (apr_fileperms_t)perms, p); |
151 | TCN_FREE_CSTRING(from)if (cfrom) (*e)->ReleaseStringUTFChars(e, from, cfrom); |
152 | TCN_FREE_CSTRING(to)if (cto) (*e)->ReleaseStringUTFChars(e, to, cto); |
153 | return (jint)rv; |
154 | } |
155 | |
156 | TCN_IMPLEMENT_CALL(jint, File, append)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_append(TCN_STDARGSJNIEnv *e, jobject o, jstring from, |
157 | jstring to, jint perms, jlong pool) |
158 | { |
159 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
160 | TCN_ALLOC_CSTRING(from)const char *cfrom = from ? (const char *)((*e)->GetStringUTFChars (e, from, 0)) : ((void*)0); |
161 | TCN_ALLOC_CSTRING(to)const char *cto = to ? (const char *)((*e)->GetStringUTFChars (e, to, 0)) : ((void*)0); |
162 | apr_status_t rv; |
163 | |
164 | UNREFERENCED(o)(o) = (o); |
165 | rv = apr_file_append(J2S(from)cfrom, J2S(to)cto, (apr_fileperms_t)perms, p); |
166 | TCN_FREE_CSTRING(from)if (cfrom) (*e)->ReleaseStringUTFChars(e, from, cfrom); |
167 | TCN_FREE_CSTRING(to)if (cto) (*e)->ReleaseStringUTFChars(e, to, cto); |
168 | return (jint)rv; |
169 | } |
170 | |
171 | TCN_IMPLEMENT_CALL(jstring, File, nameGet)__attribute__((visibility("default"))) jstring Java_org_apache_tomcat_jni_File_nameGet(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
172 | { |
173 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
174 | jstring name = NULL((void*)0); |
175 | const char *fname; |
176 | |
177 | UNREFERENCED(o)(o) = (o); |
178 | if (apr_file_name_get(&fname, f) == APR_SUCCESS0) |
179 | name = AJP_TO_JSTRING(fname)(*e)->NewStringUTF((e), (fname)); |
180 | |
181 | return name; |
182 | } |
183 | |
184 | TCN_IMPLEMENT_CALL(jint, File, permsSet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_permsSet(TCN_STDARGSJNIEnv *e, jobject o, jstring file, jint perms) |
185 | { |
186 | TCN_ALLOC_CSTRING(file)const char *cfile = file ? (const char *)((*e)->GetStringUTFChars (e, file, 0)) : ((void*)0); |
187 | apr_status_t rv; |
188 | |
189 | UNREFERENCED(o)(o) = (o); |
190 | rv = apr_file_perms_set(J2S(file)cfile, (apr_fileperms_t)perms); |
191 | TCN_FREE_CSTRING(file)if (cfile) (*e)->ReleaseStringUTFChars(e, file, cfile); |
192 | return (jint)rv; |
193 | } |
194 | |
195 | TCN_IMPLEMENT_CALL(jint, File, attrsSet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_attrsSet(TCN_STDARGSJNIEnv *e, jobject o, jstring file, jint attrs, |
196 | jint mask, jlong pool) |
197 | { |
198 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
199 | TCN_ALLOC_CSTRING(file)const char *cfile = file ? (const char *)((*e)->GetStringUTFChars (e, file, 0)) : ((void*)0); |
200 | apr_status_t rv; |
201 | |
202 | UNREFERENCED(o)(o) = (o); |
203 | rv = apr_file_attrs_set(J2S(file)cfile, (apr_fileattrs_t)attrs, |
204 | (apr_fileattrs_t)mask, p); |
205 | TCN_FREE_CSTRING(file)if (cfile) (*e)->ReleaseStringUTFChars(e, file, cfile); |
206 | return (jint)rv; |
207 | } |
208 | |
209 | TCN_IMPLEMENT_CALL(jint, File, mtimeSet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_mtimeSet(TCN_STDARGSJNIEnv *e, jobject o, jstring file, jlong mtime, |
210 | jlong pool) |
211 | { |
212 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
213 | TCN_ALLOC_CSTRING(file)const char *cfile = file ? (const char *)((*e)->GetStringUTFChars (e, file, 0)) : ((void*)0); |
214 | apr_status_t rv; |
215 | |
216 | UNREFERENCED(o)(o) = (o); |
217 | rv = apr_file_mtime_set(J2S(file)cfile, J2T(mtime)(apr_time_t)((mtime)), p); |
218 | TCN_FREE_CSTRING(file)if (cfile) (*e)->ReleaseStringUTFChars(e, file, cfile); |
219 | return (jint)rv; |
220 | } |
221 | |
222 | TCN_IMPLEMENT_CALL(jlong, File, seek)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_File_seek(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
223 | jint where, jlong offset) |
224 | { |
225 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
226 | apr_off_t pos = (apr_off_t)offset; |
227 | apr_seek_where_t w; |
228 | UNREFERENCED(o)(o) = (o); |
229 | switch (where) { |
230 | case 1: |
231 | w = APR_CUR1; |
232 | break; |
233 | case 2: |
234 | w = APR_END2; |
235 | break; |
236 | default: |
237 | w = APR_SET0; |
238 | break; |
239 | } |
240 | TCN_THROW_IF_ERR(apr_file_seek(f, w, &pos), pos)if (1) { apr_status_t R = (apr_file_seek(f, w, &pos)); if (R != 0) { tcn_ThrowAPRException(e, R); (pos) = 0; goto cleanup ; } } else (void)(0); |
241 | |
242 | cleanup: |
243 | return (jlong)pos; |
244 | } |
245 | |
246 | TCN_IMPLEMENT_CALL(jint, File, putc)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_putc(TCN_STDARGSJNIEnv *e, jobject o, jbyte c, jlong file) |
247 | { |
248 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
249 | UNREFERENCED_STDARGSe = e; o = o; |
250 | return (jint)apr_file_putc((char)c, f); |
251 | } |
252 | |
253 | TCN_IMPLEMENT_CALL(jint, File, getc)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_getc(TCN_STDARGSJNIEnv *e, jobject o, jlong file) |
254 | { |
255 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
256 | char ch; |
257 | |
258 | UNREFERENCED_STDARGSe = e; o = o; |
259 | TCN_THROW_IF_ERR(apr_file_getc(&ch, f), ch)if (1) { apr_status_t R = (apr_file_getc(&ch, f)); if (R != 0) { tcn_ThrowAPRException(e, R); (ch) = 0; goto cleanup; } } else (void)(0); |
260 | |
261 | cleanup: |
262 | return (jint)ch; |
263 | } |
264 | |
265 | TCN_IMPLEMENT_CALL(jint, File, ungetc)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_ungetc(TCN_STDARGSJNIEnv *e, jobject o, jbyte c, jlong file) |
266 | { |
267 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
268 | UNREFERENCED_STDARGSe = e; o = o; |
269 | return (jint)apr_file_ungetc((char)c, f); |
270 | } |
271 | |
272 | TCN_IMPLEMENT_CALL(jint, File, puts)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_puts(TCN_STDARGSJNIEnv *e, jobject o, jbyteArray str, jlong file) |
273 | { |
274 | apr_status_t rv = APR_EINVAL22; |
275 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
276 | jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, str, NULL((void*)0)); |
277 | |
278 | UNREFERENCED(o)(o) = (o); |
279 | if (bytes) { |
280 | rv = apr_file_puts((const char *)bytes, f); |
281 | (*e)->ReleasePrimitiveArrayCritical(e, str, bytes, JNI_ABORT2); |
282 | } |
283 | return (jint)rv; |
284 | } |
285 | |
286 | TCN_IMPLEMENT_CALL(jint, File, write)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_write(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
287 | jbyteArray buf, jint offset, jint towrite) |
288 | { |
289 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
290 | apr_size_t nbytes = (apr_size_t)towrite; |
291 | jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL((void*)0)); |
292 | apr_status_t ss; |
293 | |
294 | UNREFERENCED(o)(o) = (o); |
295 | if (towrite < 0) |
296 | towrite = (*e)->GetArrayLength(e, buf); |
297 | ss = apr_file_write(f, bytes + offset, &nbytes); |
298 | |
299 | (*e)->ReleasePrimitiveArrayCritical(e, buf, bytes, JNI_ABORT2); |
300 | if (ss == APR_SUCCESS0) |
301 | return (jint)nbytes; |
302 | else |
303 | return -(jint)ss; |
304 | } |
305 | |
306 | TCN_IMPLEMENT_CALL(jint, File, writeb)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_writeb(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
307 | jobject buf, jint offset, jint towrite) |
308 | { |
309 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
310 | apr_size_t nbytes = (apr_size_t)towrite; |
311 | char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); |
312 | apr_status_t ss = APR_EINVAL22; |
313 | |
314 | UNREFERENCED(o)(o) = (o); |
315 | if (bytes) |
316 | ss = apr_file_write(f, bytes + offset, &nbytes); |
317 | |
318 | if (ss == APR_SUCCESS0) |
319 | return (jint)nbytes; |
320 | else |
321 | return -(jint)ss; |
322 | } |
323 | |
324 | TCN_IMPLEMENT_CALL(jint, File, writeFull)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_writeFull(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
325 | jbyteArray buf, jint offset, jint towrite) |
326 | { |
327 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
328 | apr_size_t nbytes = (apr_size_t)towrite; |
329 | apr_size_t written = 0; |
330 | apr_status_t ss; |
331 | jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL((void*)0)); |
332 | |
333 | UNREFERENCED(o)(o) = (o); |
334 | if (towrite < 0) |
335 | towrite = (*e)->GetArrayLength(e, buf); |
Value stored to 'towrite' is never read | |
336 | ss = apr_file_write_full(f, bytes + offset, nbytes, &written); |
337 | |
338 | (*e)->ReleaseByteArrayElements(e, buf, bytes, JNI_ABORT2); |
339 | if (ss == APR_SUCCESS0) |
340 | return (jint)written; |
341 | else |
342 | return -(jint)ss; |
343 | } |
344 | |
345 | TCN_IMPLEMENT_CALL(jint, File, writeFullb)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_writeFullb(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
346 | jobject buf, jint offset, jint towrite) |
347 | { |
348 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
349 | apr_size_t nbytes = (apr_size_t)towrite; |
350 | apr_size_t written = 0; |
351 | apr_status_t ss = APR_EINVAL22; |
352 | char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); |
353 | |
354 | UNREFERENCED(o)(o) = (o); |
355 | if (bytes) |
356 | ss = apr_file_write_full(f, bytes + offset, nbytes, &written); |
357 | |
358 | if (ss == APR_SUCCESS0) |
359 | return (jint)written; |
360 | else |
361 | return -(jint)ss; |
362 | } |
363 | |
364 | TCN_IMPLEMENT_CALL(jint, File, writev)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_writev(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
365 | jobjectArray bufs) |
366 | { |
367 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
368 | jsize nvec = (*e)->GetArrayLength(e, bufs); |
369 | jsize i; |
370 | struct iovec vec[APR_MAX_IOVEC_SIZE1024]; |
371 | jobject ba[APR_MAX_IOVEC_SIZE1024]; |
372 | apr_size_t written = 0; |
373 | apr_status_t ss; |
374 | |
375 | UNREFERENCED(o)(o) = (o); |
376 | |
377 | if (nvec >= APR_MAX_IOVEC_SIZE1024) { |
378 | /* TODO: Throw something here */ |
379 | return 0; |
380 | } |
381 | for (i = 0; i < nvec; i++) { |
382 | ba[i] = (*e)->GetObjectArrayElement(e, bufs, i); |
383 | vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]); |
384 | vec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, ba[i], NULL((void*)0))); |
385 | } |
386 | |
387 | ss = apr_file_writev(f, vec, nvec, &written); |
388 | |
389 | for (i = 0; i < nvec; i++) { |
390 | (*e)->ReleaseByteArrayElements(e, ba[i], (jbyte *)vec[i].iov_base, JNI_ABORT2); |
391 | } |
392 | if (ss == APR_SUCCESS0) |
393 | return (jint)written; |
394 | else |
395 | return -(jint)ss; |
396 | } |
397 | |
398 | TCN_IMPLEMENT_CALL(jint, File, writevFull)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_writevFull(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
399 | jobjectArray bufs) |
400 | { |
401 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
402 | jsize nvec = (*e)->GetArrayLength(e, bufs); |
403 | jsize i; |
404 | struct iovec vec[APR_MAX_IOVEC_SIZE1024]; |
405 | jobject ba[APR_MAX_IOVEC_SIZE1024]; |
406 | apr_size_t written = 0; |
407 | apr_status_t ss; |
408 | |
409 | UNREFERENCED(o)(o) = (o); |
410 | |
411 | if (nvec >= APR_MAX_IOVEC_SIZE1024) { |
412 | /* TODO: Throw something here */ |
413 | return 0; |
414 | } |
415 | for (i = 0; i < nvec; i++) { |
416 | ba[i] = (*e)->GetObjectArrayElement(e, bufs, i); |
417 | vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]); |
418 | vec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, ba[i], NULL((void*)0))); |
419 | } |
420 | #if (APR_VERSION_MAJOR >= 1) && (APR_VERSION_MINOR >= 1) |
421 | ss = apr_file_writev_full(f, vec, nvec, &written); |
422 | #else |
423 | ss = apr_file_writev(f, vec, nvec, &written); |
424 | #endif |
425 | |
426 | for (i = 0; i < nvec; i++) { |
427 | (*e)->ReleaseByteArrayElements(e, ba[i], (jbyte *)vec[i].iov_base, |
428 | JNI_ABORT2); |
429 | } |
430 | if (ss == APR_SUCCESS0) |
431 | return (jint)written; |
432 | else |
433 | return -(jint)ss; |
434 | } |
435 | |
436 | TCN_IMPLEMENT_CALL(jint, File, read)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_read(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
437 | jbyteArray buf, jint offset, |
438 | jint toread) |
439 | { |
440 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
441 | apr_size_t nbytes = (apr_size_t)toread; |
442 | jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL((void*)0)); |
443 | apr_status_t ss; |
444 | |
445 | UNREFERENCED(o)(o) = (o); |
446 | ss = apr_file_read(f, bytes + offset, &nbytes); |
447 | |
448 | (*e)->ReleaseByteArrayElements(e, buf, bytes, |
449 | ss == APR_SUCCESS0 ? 0 : JNI_ABORT2); |
450 | if (ss == APR_SUCCESS0) |
451 | return (jint)nbytes; |
452 | else |
453 | return -(jint)ss; |
454 | } |
455 | |
456 | TCN_IMPLEMENT_CALL(jint, File, readb)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_readb(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
457 | jobject buf, jint offset, |
458 | jint toread) |
459 | { |
460 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
461 | apr_size_t nbytes = (apr_size_t)toread; |
462 | char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); |
463 | apr_status_t ss = APR_EINVAL22; |
464 | |
465 | UNREFERENCED(o)(o) = (o); |
466 | if (bytes) |
467 | ss = apr_file_read(f, bytes + offset, &nbytes); |
468 | |
469 | if (ss == APR_SUCCESS0) |
470 | return (jint)nbytes; |
471 | else |
472 | return -(jint)ss; |
473 | } |
474 | |
475 | TCN_IMPLEMENT_CALL(jint, File, readFull)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_readFull(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
476 | jbyteArray buf, jint offset, |
477 | jint toread) |
478 | { |
479 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
480 | apr_size_t nbytes = (apr_size_t)toread; |
481 | apr_size_t nread = 0; |
482 | apr_status_t ss; |
483 | jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL((void*)0)); |
484 | |
485 | UNREFERENCED(o)(o) = (o); |
486 | ss = apr_file_read_full(f, bytes + offset, nbytes, &nread); |
487 | |
488 | (*e)->ReleaseByteArrayElements(e, buf, bytes, |
489 | ss == APR_SUCCESS0 ? 0 : JNI_ABORT2); |
490 | if (ss == APR_SUCCESS0) |
491 | return (jint)nread; |
492 | else |
493 | return -(jint)ss; |
494 | } |
495 | |
496 | TCN_IMPLEMENT_CALL(jint, File, readFullb)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_readFullb(TCN_STDARGSJNIEnv *e, jobject o, jlong file, |
497 | jobject buf, jint offset, |
498 | jint toread) |
499 | { |
500 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
501 | apr_size_t nbytes = (apr_size_t)toread; |
502 | apr_size_t nread = 0; |
503 | char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf); |
504 | apr_status_t ss = APR_EINVAL22; |
505 | |
506 | UNREFERENCED(o)(o) = (o); |
507 | if (bytes) |
508 | ss = apr_file_read_full(f, bytes + offset, nbytes, &nread); |
509 | |
510 | if (ss == APR_SUCCESS0) |
511 | return (jint)nread; |
512 | else |
513 | return -(jint)ss; |
514 | } |
515 | |
516 | TCN_IMPLEMENT_CALL(jint, File, gets)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_gets(TCN_STDARGSJNIEnv *e, jobject o, jbyteArray buf, jint offset, |
517 | jlong file) |
518 | { |
519 | apr_status_t rv; |
520 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
521 | jsize nbytes = (*e)->GetArrayLength(e, buf); |
522 | jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL((void*)0)); |
523 | |
524 | UNREFERENCED(o)(o) = (o); |
525 | rv = apr_file_gets((char*)(bytes + offset),nbytes - offset, f); |
526 | (*e)->ReleaseByteArrayElements(e, buf, bytes, |
527 | rv == APR_SUCCESS0 ? 0 : JNI_ABORT2); |
528 | return (jint)rv; |
529 | } |
530 | |
531 | TCN_IMPLEMENT_CALL(jint, File, pipeCreate)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_pipeCreate(TCN_STDARGSJNIEnv *e, jobject o, jlongArray io, jlong pool) |
532 | { |
533 | apr_status_t rv; |
534 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
535 | jsize npipes = (*e)->GetArrayLength(e, io); |
536 | jlong *pipes = (*e)->GetLongArrayElements(e, io, NULL((void*)0)); |
537 | apr_file_t *in; |
538 | apr_file_t *out; |
539 | |
540 | UNREFERENCED(o)(o) = (o); |
541 | if (npipes < 2) { |
542 | (*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT2); |
543 | return APR_EINVAL22; |
544 | } |
545 | |
546 | rv = apr_file_pipe_create(&in, &out, p); |
547 | if (rv == APR_SUCCESS0) { |
548 | pipes[0] = P2J(in)((jlong)((long)(in))); |
549 | pipes[1] = P2J(out)((jlong)((long)(out))); |
550 | (*e)->ReleaseLongArrayElements(e, io, pipes, 0); |
551 | } |
552 | else |
553 | (*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT2); |
554 | |
555 | return (jint)rv; |
556 | } |
557 | |
558 | TCN_IMPLEMENT_CALL(jint, File, pipeTimeoutSet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_pipeTimeoutSet(TCN_STDARGSJNIEnv *e, jobject o, jlong pipe, |
559 | jlong timeout) |
560 | { |
561 | apr_file_t *f = J2P(pipe, apr_file_t *)((apr_file_t *)((long)((jlong)pipe))); |
562 | UNREFERENCED_STDARGSe = e; o = o; |
563 | return (jint)apr_file_pipe_timeout_set(f, J2T(timeout)(apr_time_t)((timeout))); |
564 | } |
565 | |
566 | TCN_IMPLEMENT_CALL(jlong, File, pipeTimeoutGet)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_File_pipeTimeoutGet(TCN_STDARGSJNIEnv *e, jobject o, jlong pipe) |
567 | { |
568 | apr_file_t *f = J2P(pipe, apr_file_t *)((apr_file_t *)((long)((jlong)pipe))); |
569 | apr_interval_time_t timeout; |
570 | |
571 | UNREFERENCED(o)(o) = (o); |
572 | TCN_THROW_IF_ERR(apr_file_pipe_timeout_get(f, &timeout), timeout)if (1) { apr_status_t R = (apr_file_pipe_timeout_get(f, & timeout)); if (R != 0) { tcn_ThrowAPRException(e, R); (timeout ) = 0; goto cleanup; } } else (void)(0); |
573 | |
574 | cleanup: |
575 | return (jlong)timeout; |
576 | } |
577 | |
578 | TCN_IMPLEMENT_CALL(jlong, File, dup)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_File_dup(TCN_STDARGSJNIEnv *e, jobject o, jlong newf, jlong file, |
579 | jlong pool) |
580 | { |
581 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
582 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
583 | apr_file_t *d = J2P(newf, apr_file_t *)((apr_file_t *)((long)((jlong)newf))); |
584 | |
585 | UNREFERENCED(o)(o) = (o); |
586 | TCN_THROW_IF_ERR(apr_file_dup(&d, f, p), d)if (1) { apr_status_t R = (apr_file_dup(&d, f, p)); if (R != 0) { tcn_ThrowAPRException(e, R); (d) = 0; goto cleanup; } } else (void)(0); |
587 | |
588 | cleanup: |
589 | return P2J(d)((jlong)((long)(d))); |
590 | } |
591 | |
592 | TCN_IMPLEMENT_CALL(jint, File, dup2)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_File_dup2(TCN_STDARGSJNIEnv *e, jobject o, jlong newf, jlong file, |
593 | jlong pool) |
594 | { |
595 | apr_file_t *f = J2P(file, apr_file_t *)((apr_file_t *)((long)((jlong)file))); |
596 | apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool))); |
597 | apr_file_t *d = J2P(newf, apr_file_t *)((apr_file_t *)((long)((jlong)newf))); |
598 | |
599 | UNREFERENCED_STDARGSe = e; o = o; |
600 | return (jint)apr_file_dup2(d, f, p); |
601 | } |