1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 package org.apache.tomcat.jni;
19 /* Import needed classes */
20 import java.nio.ByteBuffer;
21 
22 /** File
23  *
24  * @author Mladen Turk
25  */
26 public class File {
27 
28     /** Open the file for reading */
29     public static final int APR_FOPEN_READ       = 0x00001;
30     /** Open the file for writing */
31     public static final int APR_FOPEN_WRITE      = 0x00002;
32     /** Create the file if not there */
33     public static final int APR_FOPEN_CREATE     = 0x00004;
34     /** Append to the end of the file */
35     public static final int APR_FOPEN_APPEND     = 0x00008;
36     /** Open the file and truncate to 0 length */
37     public static final int APR_FOPEN_TRUNCATE   = 0x00010;
38     /** Open the file in binary mode */
39     public static final int APR_FOPEN_BINARY     = 0x00020;
40     /** Open should fail if APR_CREATE and file exists. */
41     public static final int APR_FOPEN_EXCL       = 0x00040;
42     /** Open the file for buffered I/O */
43     public static final int APR_FOPEN_BUFFERED   = 0x00080;
44     /** Delete the file after close */
45     public static final int APR_FOPEN_DELONCLOSE = 0x00100;
46     /** Platform dependent tag to open the file for
47      * use across multiple threads
48      */
49     public static final int APR_FOPEN_XTHREAD     = 0x00200;
50     /** Platform dependent support for higher level locked read/write
51      * access to support writes across process/machines
52      */
53     public static final int APR_FOPEN_SHARELOCK   = 0x00400;
54     /** Do not register a cleanup when the file is opened */
55     public static final int APR_FOPEN_NOCLEANUP   = 0x00800;
56     /** Advisory flag that this file should support
57      * apr_socket_sendfile operation
58      */
59     public static final int APR_FOPEN_SENDFILE_ENABLED = 0x01000;
60     /** Platform dependent flag to enable large file support;
61      * <br><b>Warning :</b> The APR_LARGEFILE flag only has effect on some platforms
62      * where sizeof(apr_off_t) == 4.  Where implemented, it allows opening
63      * and writing to a file which exceeds the size which can be
64      * represented by apr_off_t (2 gigabytes).  When a file's size does
65      * exceed 2Gb, apr_file_info_get() will fail with an error on the
66      * descriptor, likewise apr_stat()/apr_lstat() will fail on the
67      * filename.  apr_dir_read() will fail with APR_INCOMPLETE on a
68      * directory entry for a large file depending on the particular
69      * APR_FINFO_* flags.  Generally, it is not recommended to use this
70      * flag.
71      */
72     public static final int APR_FOPEN_LARGEFILE      = 0x04000;
73 
74     /** Set the file position */
75     public static final int APR_SET = 0;
76     /** Current */
77     public static final int APR_CUR = 1;
78     /** Go to end of file */
79     public static final int APR_END = 2;
80 
81     /* flags for apr_file_attrs_set */
82 
83     /** File is read-only */
84     public static final int APR_FILE_ATTR_READONLY   = 0x01;
85     /** File is executable */
86     public static final int APR_FILE_ATTR_EXECUTABLE = 0x02;
87     /** File is hidden */
88     public static final int APR_FILE_ATTR_HIDDEN     = 0x04;
89 
90 
91     /* File lock types/flags */
92 
93     /** Shared lock. More than one process or thread can hold a shared lock
94      * at any given time. Essentially, this is a "read lock", preventing
95      * writers from establishing an exclusive lock.
96      */
97     public static final int APR_FLOCK_SHARED    = 1;
98 
99     /** Exclusive lock. Only one process may hold an exclusive lock at any
100      * given time. This is analogous to a "write lock".
101      */
102     public static final int APR_FLOCK_EXCLUSIVE = 2;
103     /** mask to extract lock type */
104     public static final int APR_FLOCK_TYPEMASK  = 0x000F;
105     /** do not block while acquiring the file lock */
106     public static final int APR_FLOCK_NONBLOCK  = 0x0010;
107 
108     /* apr_filetype_e values for the filetype member of the
109      * apr_file_info_t structure
110      * <br><b>Warning :</b>: Not all of the filetypes below can be determined.
111      * For example, a given platform might not correctly report
112      * a socket descriptor as APR_SOCK if that type isn't
113      * well-identified on that platform.  In such cases where
114      * a filetype exists but cannot be described by the recognized
115      * flags below, the filetype will be APR_UNKFILE.  If the
116      * filetype member is not determined, the type will be APR_NOFILE.
117      */
118 
119     /** no file type determined */
120     public static final int APR_NOFILE  = 0;
121     /** a regular file */
122     public static final int APR_REG     = 1;
123     /** a directory */
124     public static final int APR_DIR     = 2;
125     /** a character device */
126     public static final int APR_CHR     = 3;
127     /** a block device */
128     public static final int APR_BLK     = 4;
129     /** a FIFO / pipe */
130     public static final int APR_PIPE    = 5;
131     /** a symbolic link */
132     public static final int APR_LNK     = 6;
133     /** a [unix domain] socket */
134     public static final int APR_SOCK    = 7;
135     /** a file of some other unknown type */
136     public static final int APR_UNKFILE = 127;
137 
138 
139     /*
140      * apr_file_permissions File Permissions flags
141      */
142 
143     public static final int APR_FPROT_USETID     = 0x8000; /** Set user id */
144     public static final int APR_FPROT_UREAD      = 0x0400; /** Read by user */
145     public static final int APR_FPROT_UWRITE     = 0x0200; /** Write by user */
146     public static final int APR_FPROT_UEXECUTE   = 0x0100; /** Execute by user */
147 
148     public static final int APR_FPROT_GSETID     = 0x4000; /** Set group id */
149     public static final int APR_FPROT_GREAD      = 0x0040; /** Read by group */
150     public static final int APR_FPROT_GWRITE     = 0x0020; /** Write by group */
151     public static final int APR_FPROT_GEXECUTE   = 0x0010; /** Execute by group */
152 
153     public static final int APR_FPROT_WSTICKY    = 0x2000; /** Sticky bit */
154     public static final int APR_FPROT_WREAD      = 0x0004; /** Read by others */
155     public static final int APR_FPROT_WWRITE     = 0x0002; /** Write by others */
156     public static final int APR_FPROT_WEXECUTE   = 0x0001; /** Execute by others */
157     public static final int APR_FPROT_OS_DEFAULT = 0x0FFF; /** use OS's default permissions */
158 
159 
160     public static final int APR_FINFO_LINK   = 0x00000001; /** Stat the link not the file itself if it is a link */
161     public static final int APR_FINFO_MTIME  = 0x00000010; /** Modification Time */
162     public static final int APR_FINFO_CTIME  = 0x00000020; /** Creation or inode-changed time */
163     public static final int APR_FINFO_ATIME  = 0x00000040; /** Access Time */
164     public static final int APR_FINFO_SIZE   = 0x00000100; /** Size of the file */
165     public static final int APR_FINFO_CSIZE  = 0x00000200; /** Storage size consumed by the file */
166     public static final int APR_FINFO_DEV    = 0x00001000; /** Device */
167     public static final int APR_FINFO_INODE  = 0x00002000; /** Inode */
168     public static final int APR_FINFO_NLINK  = 0x00004000; /** Number of links */
169     public static final int APR_FINFO_TYPE   = 0x00008000; /** Type */
170     public static final int APR_FINFO_USER   = 0x00010000; /** User */
171     public static final int APR_FINFO_GROUP  = 0x00020000; /** Group */
172     public static final int APR_FINFO_UPROT  = 0x00100000; /** User protection bits */
173     public static final int APR_FINFO_GPROT  = 0x00200000; /** Group protection bits */
174     public static final int APR_FINFO_WPROT  = 0x00400000; /** World protection bits */
175     public static final int APR_FINFO_ICASE  = 0x01000000; /** if dev is case insensitive */
176     public static final int APR_FINFO_NAME   = 0x02000000; /** -&gt;name in proper case */
177 
178     public static final int APR_FINFO_MIN    = 0x00008170; /** type, mtime, ctime, atime, size */
179     public static final int APR_FINFO_IDENT  = 0x00003000; /** dev and inode */
180     public static final int APR_FINFO_OWNER  = 0x00030000; /** user and group */
181     public static final int APR_FINFO_PROT   = 0x00700000; /**  all protections */
182     public static final int APR_FINFO_NORM   = 0x0073b170; /**  an atomic unix apr_stat() */
183     public static final int APR_FINFO_DIRENT = 0x02000000; /**  an atomic unix apr_dir_read() */
184 
185 
186 
187     /**
188      * Open the specified file.
189      * @param fname The full path to the file (using / on all systems)
190      * @param flag Or'ed value of:
191      * <PRE>
192      * APR_FOPEN_READ              open for reading
193      * APR_FOPEN_WRITE             open for writing
194      * APR_FOPEN_CREATE            create the file if not there
195      * APR_FOPEN_APPEND            file ptr is set to end prior to all writes
196      * APR_FOPEN_TRUNCATE          set length to zero if file exists
197      * APR_FOPEN_BINARY            not a text file (This flag is ignored on
198      *                             UNIX because it has no meaning)
199      * APR_FOPEN_BUFFERED          buffer the data.  Default is non-buffered
200      * APR_FOPEN_EXCL              return error if APR_CREATE and file exists
201      * APR_FOPEN_DELONCLOSE        delete the file after closing.
202      * APR_FOPEN_XTHREAD           Platform dependent tag to open the file
203      *                             for use across multiple threads
204      * APR_FOPEN_SHARELOCK         Platform dependent support for higher
205      *                             level locked read/write access to support
206      *                             writes across process/machines
207      * APR_FOPEN_NOCLEANUP         Do not register a cleanup with the pool
208      *                             passed in on the <EM>pool</EM> argument (see below).
209      *                             The apr_os_file_t handle in apr_file_t will not
210      *                             be closed when the pool is destroyed.
211      * APR_FOPEN_SENDFILE_ENABLED  Open with appropriate platform semantics
212      *                             for sendfile operations.  Advisory only,
213      *                             apr_socket_sendfile does not check this flag.
214      * </PRE>
215      * @param perm Access permissions for file.
216      * @param pool The pool to use.
217      * If perm is APR_OS_DEFAULT and the file is being created,
218      * appropriate default permissions will be used.
219      * @return The opened file descriptor.
220      * @throws Error An error occurred
221      */
open(String fname, int flag, int perm, long pool)222     public static native long open(String fname, int flag, int perm, long pool)
223         throws Error;
224 
225     /**
226      * Close the specified file.
227      * @param file The file descriptor to close.
228      * @return the operation status
229      */
close(long file)230     public static native int close(long file);
231 
232     /**
233      * Flush the file's buffer.
234      * @param thefile The file descriptor to flush
235      * @return the operation status
236      */
flush(long thefile)237     public static native int flush(long thefile);
238 
239     /**
240      * Open a temporary file
241      * @param templ The template to use when creating a temp file.
242      * @param flags The flags to open the file with. If this is zero,
243      *              the file is opened with
244      *              APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE
245      * @param pool The pool to allocate the file out of.
246      * @return The apr file to use as a temporary file.
247      *
248      * This function  generates  a unique temporary file name from template.
249      * The last six characters of template must be XXXXXX and these are replaced
250      * with a string that makes the filename unique. Since it will  be  modified,
251      * template must not be a string constant, but should be declared as a character
252      * array.
253      * @throws Error An error occurred
254      */
mktemp(String templ, int flags, long pool)255     public static native long mktemp(String templ, int flags, long pool)
256         throws Error;
257 
258     /**
259      * Delete the specified file.
260      * @param path The full path to the file (using / on all systems)
261      * @param pool The pool to use.
262      * If the file is open, it won't be removed until all
263      * instances are closed.
264      * @return the operation status
265      */
remove(String path, long pool)266     public static native int remove(String path, long pool);
267 
268     /**
269      * Rename the specified file.
270      * <br><b>Warning :</b> If a file exists at the new location, then it will be
271      * overwritten.  Moving files or directories across devices may not be
272      * possible.
273      * @param fromPath The full path to the original file (using / on all systems)
274      * @param toPath The full path to the new file (using / on all systems)
275      * @param pool The pool to use.
276      * @return the operation status
277      */
rename(String fromPath, String toPath, long pool)278     public static native int rename(String fromPath, String toPath, long pool);
279 
280     /**
281      * Copy the specified file to another file.
282      * The new file does not need to exist, it will be created if required.
283      * <br><b>Warning :</b> If the new file already exists, its contents will be overwritten.
284      * @param fromPath The full path to the original file (using / on all systems)
285      * @param toPath The full path to the new file (using / on all systems)
286      * @param perms Access permissions for the new file if it is created.
287      *     In place of the usual or'd combination of file permissions, the
288      *     value APR_FILE_SOURCE_PERMS may be given, in which case the source
289      *     file's permissions are copied.
290      * @param pool The pool to use.
291      * @return the operation status
292      */
copy(String fromPath, String toPath, int perms, long pool)293     public static native int copy(String fromPath, String toPath, int perms, long pool);
294 
295     /**
296      * Append the specified file to another file.
297      * The new file does not need to exist, it will be created if required.
298      * @param fromPath The full path to the source file (use / on all systems)
299      * @param toPath The full path to the destination file (use / on all systems)
300      * @param perms Access permissions for the destination file if it is created.
301      *     In place of the usual or'd combination of file permissions, the
302      *     value APR_FILE_SOURCE_PERMS may be given, in which case the source
303      *     file's permissions are copied.
304      * @param pool The pool to use.
305      * @return the operation status
306      */
append(String fromPath, String toPath, int perms, long pool)307     public static native int append(String fromPath, String toPath, int perms, long pool);
308 
309     /**
310      * Write the string into the specified file.
311      * @param str The string to write. Must be NUL terminated!
312      * @param thefile The file descriptor to write to
313      * @return the operation status
314      */
puts(byte [] str, long thefile)315     public static native int puts(byte [] str, long thefile);
316 
317     /**
318      * Move the read/write file offset to a specified byte within a file.
319      * @param thefile The file descriptor
320      * @param where How to move the pointer, one of:
321      * <PRE>
322      * APR_SET  --  set the offset to offset
323      * APR_CUR  --  add the offset to the current position
324      * APR_END  --  add the offset to the current file size
325      * </PRE>
326      * @param offset The offset to move the pointer to.
327      * @return Offset the pointer was actually moved to.
328      * @throws Error If an error occurs reading the file
329      */
seek(long thefile, int where, long offset)330     public static native long seek(long thefile, int where, long offset)
331         throws Error;
332 
333     /**
334      * Write a character into the specified file.
335      * @param ch The character to write.
336      * @param thefile The file descriptor to write to
337      * @return the operation status
338      */
putc(byte ch, long thefile)339     public static native int putc(byte ch, long thefile);
340 
341     /**
342      * Put a character back onto a specified stream.
343      * @param ch The character to write.
344      * @param thefile The file descriptor to write to
345      * @return the operation status
346      */
ungetc(byte ch, long thefile)347     public static native int ungetc(byte ch, long thefile);
348 
349     /**
350      * Write data to the specified file.
351      *
352      * Write will write up to the specified number of
353      * bytes, but never more.  If the OS cannot write that many bytes, it
354      * will write as many as it can.  The third argument is modified to
355      * reflect the * number of bytes written.
356      *
357      * It is possible for both bytes to be written and an error to
358      * be returned.  APR_EINTR is never returned.
359      * @param thefile The file descriptor to write to.
360      * @param buf The buffer which contains the data.
361      * @param offset Start offset in buf
362      * @param nbytes The number of bytes to write
363      * @return The number of bytes written.
364      */
write(long thefile, byte[] buf, int offset, int nbytes)365     public static native int write(long thefile, byte[] buf, int offset, int nbytes);
366 
367     /**
368      * Write data to the specified file.
369      *
370      * Write will write up to the specified number of
371      * bytes, but never more.  If the OS cannot write that many bytes, it
372      * will write as many as it can.  The third argument is modified to
373      * reflect the * number of bytes written.
374      *
375      * It is possible for both bytes to be written and an error to
376      * be returned.  APR_EINTR is never returned.
377      * @param thefile The file descriptor to write to.
378      * @param buf The direct Byte buffer which contains the data.
379      * @param offset Start offset in buf
380      * @param nbytes The number of bytes to write
381      * @return The number of bytes written.
382      */
writeb(long thefile, ByteBuffer buf, int offset, int nbytes)383     public static native int writeb(long thefile, ByteBuffer buf, int offset, int nbytes);
384 
385     /**
386      * Write data to the specified file, ensuring that all of the data is
387      * written before returning.
388      *
389      * Write will write up to the specified number of
390      * bytes, but never more.  If the OS cannot write that many bytes, the
391      * process/thread will block until they can be written. Exceptional
392      * error such as "out of space" or "pipe closed" will terminate with
393      * an error.
394      *
395      * It is possible for both bytes to be written and an error to
396      * be returned.  And if *bytes_written is less than nbytes, an
397      * accompanying error is _always_ returned.
398      *
399      * APR_EINTR is never returned.
400      * @param thefile The file descriptor to write to.
401      * @param buf The buffer which contains the data.
402      * @param offset Start offset in buf
403      * @param nbytes The number of bytes to write
404      * @return The number of bytes written.
405      */
writeFull(long thefile, byte[] buf, int offset, int nbytes)406     public static native int writeFull(long thefile, byte[] buf, int offset, int nbytes);
407 
408     /**
409      * Write data to the specified file, ensuring that all of the data is
410      * written before returning.
411      *
412      * Write will write up to the specified number of
413      * bytes, but never more.  If the OS cannot write that many bytes, the
414      * process/thread will block until they can be written. Exceptional
415      * error such as "out of space" or "pipe closed" will terminate with
416      * an error.
417      *
418      * It is possible for both bytes to be written and an error to
419      * be returned.  And if *bytes_written is less than nbytes, an
420      * accompanying error is _always_ returned.
421      *
422      * APR_EINTR is never returned.
423      * @param thefile The file descriptor to write to.
424      * @param buf The direct ByteBuffer which contains the data.
425      * @param offset Start offset in buf
426      * @param nbytes The number of bytes to write.
427      * @return The number of bytes written.
428      */
writeFullb(long thefile, ByteBuffer buf, int offset, int nbytes)429     public static native int writeFullb(long thefile, ByteBuffer buf, int offset, int nbytes);
430 
431     /**
432      * Write data from array of byte arrays to the specified file.
433      *
434      * It is possible for both bytes to be written and an error to
435      * be returned.  APR_EINTR is never returned.
436      *
437      * apr_file_writev is available even if the underlying
438      * operating system doesn't provide writev().
439      * @param thefile The file descriptor to write to.
440      * @param vec The array from which to get the data to write to the file.
441      * @return The number of bytes written.
442      */
writev(long thefile, byte[][] vec)443     public static native int writev(long thefile, byte[][] vec);
444 
445     /**
446      * Write data from array of byte arrays to the specified file,
447      * ensuring that all of the data is written before returning.
448      *
449      * writevFull is available even if the underlying
450      * operating system doesn't provide writev().
451      * @param thefile The file descriptor to write to.
452      * @param vec The array from which to get the data to write to the file.
453      * @return The number of bytes written.
454      */
writevFull(long thefile, byte[][] vec)455     public static native int writevFull(long thefile, byte[][] vec);
456 
457     /**
458      * Read data from the specified file.
459      *
460      * apr_file_read will read up to the specified number of
461      * bytes, but never more.  If there isn't enough data to fill that
462      * number of bytes, all of the available data is read.  The third
463      * argument is modified to reflect the number of bytes read.  If a
464      * char was put back into the stream via ungetc, it will be the first
465      * character returned.
466      *
467      * It is not possible for both bytes to be read and an APR_EOF
468      * or other error to be returned.  APR_EINTR is never returned.
469      * @param thefile The file descriptor to read from.
470      * @param buf The buffer to store the data to.
471      * @param offset Start offset in buf
472      * @param nbytes The number of bytes to read
473      * @return the number of bytes read.
474      */
read(long thefile, byte[] buf, int offset, int nbytes)475     public static native int read(long thefile, byte[] buf,  int offset, int nbytes);
476 
477     /**
478      * Read data from the specified file.
479      *
480      * apr_file_read will read up to the specified number of
481      * bytes, but never more.  If there isn't enough data to fill that
482      * number of bytes, all of the available data is read.  The third
483      * argument is modified to reflect the number of bytes read.  If a
484      * char was put back into the stream via ungetc, it will be the first
485      * character returned.
486      *
487      * It is not possible for both bytes to be read and an APR_EOF
488      * or other error to be returned.  APR_EINTR is never returned.
489      * @param thefile The file descriptor to read from.
490      * @param buf The direct Byte buffer to store the data to.
491      * @param offset Start offset in buf
492      * @param nbytes The number of bytes to read.
493      * @return the number of bytes read.
494      */
readb(long thefile, ByteBuffer buf, int offset, int nbytes)495     public static native int readb(long thefile, ByteBuffer buf,  int offset, int nbytes);
496 
497     /**
498      * Read data from the specified file, ensuring that the buffer is filled
499      * before returning.
500      *
501      * Read will read up to the specified number of
502      * bytes, but never more.  If there isn't enough data to fill that
503      * number of bytes, then the process/thread will block until it is
504      * available or EOF is reached.  If a char was put back into the
505      * stream via ungetc, it will be the first character returned.
506      *
507      * It is possible for both bytes to be read and an error to be
508      * returned.  And if *bytes_read is less than nbytes, an accompanying
509      * error is _always_ returned.
510      *
511      * APR_EINTR is never returned.
512      * @param thefile The file descriptor to read from.
513      * @param buf The buffer to store the data to.
514      * @param offset Start offset in buf
515      * @param nbytes The number of bytes to read
516      * @return the number of bytes read.
517      */
readFull(long thefile, byte[] buf, int offset, int nbytes)518     public static native int readFull(long thefile, byte[] buf,  int offset, int nbytes);
519 
520     /**
521      * Read data from the specified file, ensuring that the buffer is filled
522      * before returning.
523      *
524      * Read will read up to the specified number of
525      * bytes, but never more.  If there isn't enough data to fill that
526      * number of bytes, then the process/thread will block until it is
527      * available or EOF is reached.  If a char was put back into the
528      * stream via ungetc, it will be the first character returned.
529      *
530      * It is possible for both bytes to be read and an error to be
531      * returned.  And if *bytes_read is less than nbytes, an accompanying
532      * error is _always_ returned.
533      *
534      * APR_EINTR is never returned.
535      * @param thefile The file descriptor to read from.
536      * @param buf The direct ByteBuffer to store the data to.
537      * @param offset Start offset in buf
538      * @param nbytes The number of bytes to read.
539      * @return the number of bytes read.
540      */
readFullb(long thefile, ByteBuffer buf, int offset, int nbytes)541     public static native int readFullb(long thefile, ByteBuffer buf,  int offset, int nbytes);
542 
543     /**
544      * Read a string from the specified file.
545      * The buffer will be NUL-terminated if any characters are stored.
546      * @param buf The buffer to store the string in.
547      * @param offset Start offset in buf
548      * @param thefile The file descriptor to read from
549      * @return the number of bytes read.
550      */
gets(byte[] buf, int offset, long thefile)551     public static native int gets(byte[] buf,  int offset, long thefile);
552 
553 
554     /**
555      * Read a character from the specified file.
556      * @param thefile The file descriptor to read from
557      * @return The read character
558      * @throws Error If an error occurs reading the file
559      */
getc(long thefile)560     public static native int getc(long thefile)
561         throws Error;
562 
563     /**
564      * Are we at the end of the file
565      * @param fptr The apr file we are testing.
566      * @return Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise.
567      */
eof(long fptr)568     public static native int eof(long fptr);
569 
570     /**
571      * Return the file name of the current file.
572      * @param thefile The currently open file.
573      * @return the name
574      */
nameGet(long thefile)575     public static native String nameGet(long thefile);
576 
577     /**
578      * Set the specified file's permission bits.
579      * <br><b>Warning :</b> Some platforms may not be able to apply all of the
580      * available permission bits; APR_INCOMPLETE will be returned if some
581      * permissions are specified which could not be set.
582      * <br><b>Warning :</b> Platforms which do not implement this feature will return
583      * APR_ENOTIMPL.
584      * @param fname The file (name) to apply the permissions to.
585      * @param perms The permission bits to apply to the file.
586      * @return the operation status
587      */
permsSet(String fname, int perms)588     public static native int permsSet(String fname, int perms);
589 
590     /**
591      * Set attributes of the specified file.
592      * This function should be used in preference to explicit manipulation
593      *      of the file permissions, because the operations to provide these
594      *      attributes are platform specific and may involve more than simply
595      *      setting permission bits.
596      * <br><b>Warning :</b> Platforms which do not implement this feature will return
597      *      APR_ENOTIMPL.
598      * @param fname The full path to the file (using / on all systems)
599      * @param attributes Or'd combination of
600      * <PRE>
601      *            APR_FILE_ATTR_READONLY   - make the file readonly
602      *            APR_FILE_ATTR_EXECUTABLE - make the file executable
603      *            APR_FILE_ATTR_HIDDEN     - make the file hidden
604      * </PRE>
605      * @param mask Mask of valid bits in attributes.
606      * @param pool the pool to use.
607      * @return the operation status
608      */
attrsSet(String fname, int attributes, int mask, long pool)609     public static native int  attrsSet(String fname, int attributes, int mask, long pool);
610 
611     /**
612      * Set the mtime of the specified file.
613      * <br><b>Warning :</b> Platforms which do not implement this feature will return
614      *      APR_ENOTIMPL.
615      * @param fname The full path to the file (using / on all systems)
616      * @param mtime The mtime to apply to the file in microseconds
617      * @param pool The pool to use.
618      * @return the operation status
619      */
mtimeSet(String fname, long mtime, long pool)620     public static native int  mtimeSet(String fname, long mtime, long pool);
621 
622     /**
623      * Establish a lock on the specified, open file. The lock may be advisory
624      * or mandatory, at the discretion of the platform. The lock applies to
625      * the file as a whole, rather than a specific range. Locks are established
626      * on a per-thread/process basis; a second lock by the same thread will not
627      * block.
628      * @param thefile The file to lock.
629      * @param type The type of lock to establish on the file.
630      * @return the operation status
631      */
lock(long thefile, int type)632     public static native int lock(long thefile, int type);
633 
634     /**
635      * Remove any outstanding locks on the file.
636      * @param thefile The file to unlock.
637      * @return the operation status
638      */
unlock(long thefile)639     public static native int unlock(long thefile);
640 
641     /**
642      * Retrieve the flags that were passed into apr_file_open()
643      * when the file was opened.
644      * @param file The file to retrieve flags.
645      * @return the flags
646      */
flagsGet(long file)647     public static native int flagsGet(long file);
648 
649     /**
650      * Truncate the file's length to the specified offset
651      * @param fp The file to truncate
652      * @param offset The offset to truncate to.
653      * @return the operation status
654      */
trunc(long fp, long offset)655     public static native int trunc(long fp, long offset);
656 
657     /**
658      * Create an anonymous pipe.
659      * @param io io[0] The file descriptors to use as input to the pipe.
660      *           io[1] The file descriptor to use as output from the pipe.
661      * @param pool The pool to operate on.
662      * @return the operation status
663      */
pipeCreate(long [] io, long pool)664     public static native int pipeCreate(long [] io, long pool);
665 
666     /**
667      * Get the timeout value for a pipe or manipulate the blocking state.
668      * @param thepipe The pipe we are getting a timeout for.
669      * @return The current timeout value in microseconds.
670      * @throws Error If an error occurs
671      */
pipeTimeoutGet(long thepipe)672     public static native long pipeTimeoutGet(long thepipe)
673         throws Error;
674 
675     /**
676      * Set the timeout value for a pipe or manipulate the blocking state.
677      * @param thepipe The pipe we are setting a timeout on.
678      * @param timeout The timeout value in microseconds.  Values &lt; 0 mean
679      *        wait forever, 0 means do not wait at all.
680      * @return the operation status
681      */
pipeTimeoutSet(long thepipe, long timeout)682     public static native int pipeTimeoutSet(long thepipe, long timeout);
683 
684     /**
685      * Duplicate the specified file descriptor.
686      * @param newFile The file to duplicate.
687      * newFile must point to a valid apr_file_t, or point to NULL.
688      * @param oldFile The file to duplicate.
689      * @param pool The pool to use for the new file.
690      * @return Duplicated file structure.
691      * @throws Error If an error occurs reading the file descriptor
692      */
dup(long newFile, long oldFile, long pool)693     public static native long dup(long newFile, long oldFile, long pool)
694         throws Error;
695 
696     /**
697      * Duplicate the specified file descriptor and close the original.
698      * @param newFile The old file that is to be closed and reused.
699      * newFile MUST point at a valid apr_file_t. It cannot be NULL.
700      * @param oldFile The file to duplicate.
701      * @param pool The pool to use for the new file.
702      * @return the operation status
703      */
dup2(long newFile, long oldFile, long pool)704     public static native int dup2(long newFile, long oldFile, long pool);
705 
706     /**
707      * Get the specified file's stats.  The file is specified by filename,
708      * instead of using a pre-opened file.
709      * @param finfo Where to store the information about the file, which is
710      * never touched if the call fails.
711      * @param fname The name of the file to stat.
712      * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
713      * @param pool the pool to use to allocate the new file.
714      * @return the operation status
715      */
stat(FileInfo finfo, String fname, int wanted, long pool)716     public static native int stat(FileInfo finfo, String fname, int wanted, long pool);
717 
718     /**
719      * Get the specified file's stats.  The file is specified by filename,
720      * instead of using a pre-opened file.
721      * @param fname The name of the file to stat.
722      * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
723      * @param pool the pool to use to allocate the new file.
724      * @return FileInfo object.
725      */
getStat(String fname, int wanted, long pool)726     public static native FileInfo getStat(String fname, int wanted, long pool);
727 
728     /**
729      * Get the specified file's stats.
730      * @param finfo Where to store the information about the file.
731      * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
732      * @param thefile The file to get information about.
733      * @return the operation status
734      */
infoGet(FileInfo finfo, int wanted, long thefile)735     public static native int infoGet(FileInfo finfo, int wanted, long thefile);
736 
737 
738     /**
739      * Get the specified file's stats.
740      * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
741      * @param thefile The file to get information about.
742      * @return FileInfo object.
743      */
getInfo(int wanted, long thefile)744     public static native FileInfo getInfo(int wanted, long thefile);
745 
746 }
747