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