- java.lang.Object
-
- de.ibapl.jnhw.posix.Unistd
-
@Include("#include <unistd.h>") public final class Unistd extends Object
Wrapper around the<stdio.h>header. See specs at: unistd.h - standard symbolic constants and types.- Author:
- aploese
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUnistd.JnhwPrimitiveArrayCritical
-
Field Summary
Fields Modifier and Type Field Description static int_POSIX_VERSIONPOSIX: Integer value indicating version of this standard (C-language binding) to which the implementation conforms.static booleanHAVE_UNISTD_Hstatic intSEEK_CURPOSIX:seek relative to current position.static IntDefineSEEK_DATALinux,Apple: Adjust the file offset to the next location in the file greater than or equal to offset containing data.static intSEEK_ENDPOSIX: Seek relative to end-of-file.static IntDefineSEEK_HOLEPOSIX: Adjust the file offset to the next hole in the file greater than or equal to offset.static intSEEK_SETPOSIX: Seek relative to start-of-file.static intSTDERR_FILENOPOSIX: File number of stderr; 2.static intSTDIN_FILENOPOSIX: File number of stdin; 0.static intSTDOUT_FILENOPOSIX: File number of stdout; 1.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(int fildes)POSIX: close - close a file descriptor.static voidfsync(int fildes)static intgetegid()static intgeteuid()static intgetgid()POSIX: getgid - get the real group ID.static intgetpgrp()static intgetpid()POSIX: getpid - get the process ID.static intgetppid()static intgetuid()POSIX: getuid - get a real user ID.static booleanjnhwIsSingeByteRead(short nread)static bytejnhwSingeByteReadToByte(short nread)static intjnhwSingeByteReadToInt(short nread)static intlseek(int fildes, int offset, int whence)static longlseek(int fildes, long offset, int whence)static longlseek64(int fildes, long offset, int whence)Linux: Available if _LARGEFILE64_SOURCE is defined.static voidpipe(IntRef read_fd, IntRef write_fd)static shortread(int fildes)POSIX: pread, read - read from a file.static intread(int fildes, byte[] buf)POSIX: pread, read - read from a file.static intread(int fildes, byte[] buf, int off, int nbyte)POSIX: pread, read - read from a file.static intread(int fildes, OpaqueMemory32 mem)POSIX: pread, read - read from a file.static intread(int fildes, OpaqueMemory32 mem, int off, int nbyte)POSIX: pread, read - read from a file.static longread(int fildes, OpaqueMemory64 mem)POSIX: pread, read - read from a file.static longread(int fildes, OpaqueMemory64 mem, long off, long nbyte)POSIX: pread, read - read from a file.static intread(int fildes, ByteRef data)POSIX: pread, read - read from a file.static intread(int fildes, ByteBuffer buffer)POSIX: pread, read - read from a file.static voidsetegid(int gid)POSIX: setegid - set effective user ID.static voidseteuid(int uid)POSIX: seteuid - set effective user ID.static voidsetgid(int gid)POSIX: setgid - set group ID.static voidsetregid(int rgid, int egid)static voidsetreuid(int ruid, int euid)static voidsetuid(int uid)POSIX: setuid - set user ID.static voidusleep(int usleep)LINUX,APPLE,BSD: usleep - suspend execution for an interval.static intwrite(int fildes, byte data)POSIX: pwrite, write - write on a file.static intwrite(int fildes, byte[] buf)POSIX: pwrite, write - write on a file.static intwrite(int fildes, byte[] buf, int off, int nbyte)POSIX: pwrite, write - write on a file.static intwrite(int fildes, OpaqueMemory32 mem)POSIX: pwrite, write - write on a file.static intwrite(int fildes, OpaqueMemory32 mem, int off, int nbyte)POSIX: pwrite, write - write on a file.static longwrite(int fildes, OpaqueMemory64 mem)POSIX: pwrite, write - write on a file.static longwrite(int fildes, OpaqueMemory64 mem, long off, long nbyte)POSIX: pwrite, write - write on a file.static intwrite(int fildes, ByteBuffer buffer)POSIX: pwrite, write - write on a file.
-
-
-
Field Detail
-
HAVE_UNISTD_H
public static final boolean HAVE_UNISTD_H
-
SEEK_CUR
@Define public static int SEEK_CUR
POSIX:seek relative to current position. This must be the same value as {@link de.ibapl.jnhw.posix.Stdio.SEEK_CUR()}.
-
SEEK_DATA
@Define public static IntDefine SEEK_DATA
Linux,Apple: Adjust the file offset to the next location in the file greater than or equal to offset containing data.
-
SEEK_END
@Define public static int SEEK_END
POSIX: Seek relative to end-of-file. This must be the same value asde.ibapl.jnhw.posix.Stdio.SEEK_END.
-
SEEK_HOLE
@Define public static IntDefine SEEK_HOLE
POSIX: Adjust the file offset to the next hole in the file greater than or equal to offset.
-
SEEK_SET
@Define public static int SEEK_SET
POSIX: Seek relative to start-of-file. This must be the same value asde.ibapl.jnhw.posix.Stdio.SEEK_SET.
-
STDERR_FILENO
@Define public static final int STDERR_FILENO
POSIX: File number of stderr; 2.
-
STDIN_FILENO
@Define public static final int STDIN_FILENO
POSIX: File number of stdin; 0.
-
STDOUT_FILENO
@Define public static final int STDOUT_FILENO
POSIX: File number of stdout; 1.
-
_POSIX_VERSION
@Define public static int _POSIX_VERSION
POSIX: Integer value indicating version of this standard (C-language binding) to which the implementation conforms.
-
-
Method Detail
-
close
public static final void close(int fildes) throws NativeErrorExceptionPOSIX: close - close a file descriptor.- Parameters:
fildes- an open file descriptor.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
fsync
public static final void fsync(int fildes) throws NativeErrorException- Parameters:
fildes- a valid filedescriptor.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
getgid
public static final int getgid()
POSIX: getgid - get the real group ID.- Returns:
- the real group ID
-
getegid
public static final int getegid()
-
setgid
public static final void setgid(int gid) throws NativeErrorExceptionPOSIX: setgid - set group ID.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
setegid
public static final void setegid(int gid) throws NativeErrorExceptionPOSIX: setegid - set effective user ID.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
setregid
public static final void setregid(int rgid, int egid) throws NativeErrorException- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
geteuid
public static final int geteuid()
-
seteuid
public static final void seteuid(int uid) throws NativeErrorExceptionPOSIX: seteuid - set effective user ID.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
getpgrp
public static final int getpgrp()
-
getpid
public static final int getpid()
POSIX: getpid - get the process ID.
-
getppid
public static final int getppid()
-
setreuid
public static final void setreuid(int ruid, int euid) throws NativeErrorException- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
getuid
public static final int getuid()
POSIX: getuid - get a real user ID.
-
setuid
public static final void setuid(int uid) throws NativeErrorExceptionPOSIX: setuid - set user ID.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
lseek
public static final int lseek(int fildes, int offset, int whence) throws NativeErrorException- Parameters:
fildes- a valid file descriptor.offset- depending on the size of @see SizeOf.off_tintorlongmay be used.whence- one ofSEEK_SET,SEEK_CUR,SEEK_END.- Returns:
- the position depending on the size of @see SizeOf.off_t
intorlongmay be used. - Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
lseek
public static final long lseek(int fildes, long offset, int whence) throws NativeErrorException- Parameters:
fildes- a valid file descriptor.offset- depending on the size of @see SizeOf.off_tintorlongmay be used.whence- one ofSEEK_SET,SEEK_CUR,SEEK_END.- Returns:
- the position depending on the size of @see SizeOf.off_t
intorlongmay be used. - Throws:
IndexOutOfBoundsException- if offset is greater or smaller as the native off_t can hold.NativeErrorException- if the return value of the native function indicates an error.
-
lseek64
public static final long lseek64(int fildes, long offset, int whence) throws NativeErrorException, NoSuchNativeMethodExceptionLinux: Available if _LARGEFILE64_SOURCE is defined. lseek - move the read/write file offset.- Parameters:
fildes- a valid file descriptor.offset- alway 64 bit.whence- one ofSEEK_SET,SEEK_CUR,SEEK_END.- Returns:
- the position depending on the size of @see SizeOf.off_t
intorlongmay be used. - Throws:
NativeErrorException- if the return value of the native function indicates an error.NoSuchNativeMethodException- if _LARGEFILE64_SOURCE is not defined.
-
pipe
public static final void pipe(IntRef read_fd, IntRef write_fd) throws NativeErrorException
- Parameters:
read_fd- the file descriptor for readingwrite_fd- the file descriptor for writing- Throws:
NullPointerException- ifread_fdorwrite_fdisnull.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, byte[] buf) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingbuf- the byte array into which all bytes are to be transferred.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifbufis null.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, byte[] buf, int off, int nbyte) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingbuf- the byte array into which bytes are to be transferred.off- the start offset inbufto which the data is transferred.nbyte- the maximum number of bytes to read.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifbufis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, ByteBuffer buffer) throws NativeErrorExceptionPOSIX: pread, read - read from a file. Read the bytes betweenBuffer.position()andBuffer.limit()from the file. After sucessful reading, position is updated accordingly to the number of bytes read.- Parameters:
fildes- a valid file descriptor open for readingbuffer- theByteBufferinto which bytes are to be transferred between position and limit.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifbufferis null.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, OpaqueMemory32 mem, int off, int nbyte) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingmem- theOpaqueMemory32into which bytes are to be transferred.off- the start offset inmemto which the data is transferred.nbyte- the maximum number of bytes to read.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifmemis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final long read(int fildes, OpaqueMemory64 mem, long off, long nbyte) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingmem- theOpaqueMemory64into which bytes are to be transferred.off- the start offset inmemto which the data is transferred.nbyte- the maximum number of bytes to read.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifmemis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, OpaqueMemory32 mem) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingmem- theOpaqueMemory32into which all bytes are to be transferred.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifbufis null.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final long read(int fildes, OpaqueMemory64 mem) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingmem- theOpaqueMemory32into which all bytes are to be transferred.- Returns:
- The number of bytes read, possibly zero.
- Throws:
NullPointerException- ifbufis null.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final int read(int fildes, ByteRef data) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for readingdata- theByteRefinto which the single byte is to be transferred.- Returns:
- On succes 1.
- Throws:
NullPointerException- ifdatais null.NativeErrorException- if the return value of the native function indicates an error.
-
read
public static final short read(int fildes) throws NativeErrorExceptionPOSIX: pread, read - read from a file.- Parameters:
fildes- a valid file descriptor open for reading- Returns:
- the unsigned byte in the low byte and the length in the upper byte. if nothing was read the value of the lower byte is unspecific, the length must be 0.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
usleep
public static final void usleep(int usleep) throws NativeErrorExceptionLINUX,APPLE,BSD: usleep - suspend execution for an interval.- Parameters:
usleep- the micro seconds to sleep.- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final int write(int fildes, byte[] buf) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingbuf- The byte array from which all bytes are to be retrieved for writing.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final int write(int fildes, OpaqueMemory32 mem, int off, int nbyte) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingmem- The {link OpaqueMemory} from which the bytes are to be retrieved for writing.off- the start offset inmem.nbyte- the number of bytes to write.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NullPointerException- ifmemis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final long write(int fildes, OpaqueMemory64 mem, long off, long nbyte) throws NativeErrorException, NoSuchNativeMethodExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingmem- The {link OpaqueMemory} from which the bytes are to be retrieved for writing.off- the start offset inmem.nbyte- the number of bytes to write.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NullPointerException- ifmemis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.NoSuchNativeMethodException
-
write
public static final int write(int fildes, OpaqueMemory32 mem) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingmem- The {link OpaqueMemory} from which all bytes are to be retrieved for writing.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final long write(int fildes, OpaqueMemory64 mem) throws NativeErrorException, NoSuchNativeMethodExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingmem- The {link OpaqueMemory} from which all bytes are to be retrieved for writing.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.NoSuchNativeMethodException
-
write
public static final int write(int fildes, byte data) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingdata- The single byte to write.- Returns:
- on succes 1.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final int write(int fildes, byte[] buf, int off, int nbyte) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file.- Parameters:
fildes- a valid file descriptor open for writingbuf- The byte array from which the bytes are to be retrieved for writing.off- the start offset inbuf.nbyte- the number of bytes to write.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NullPointerException- ifbufis null.ArrayIndexOutOfBoundsException- ifoffornByteout of bounds.NativeErrorException- if the return value of the native function indicates an error.
-
write
public static final int write(int fildes, ByteBuffer buffer) throws NativeErrorExceptionPOSIX: pwrite, write - write on a file. Write the bytes betweenBuffer.position()andBuffer.limit()to the file. After sucessful writing, position is updated accordingly to the number of written bytes.- Parameters:
fildes- a valid file descriptor open for writingbuffer- The {link ByteBuffer} from which the bytes between position and limit are to be retrieved for writing.- Returns:
- The number of bytes written, possibly zero.
- Throws:
NativeErrorException- if the return value of the native function indicates an error.
-
jnhwIsSingeByteRead
public static boolean jnhwIsSingeByteRead(short nread)
-
jnhwSingeByteReadToByte
public static byte jnhwSingeByteReadToByte(short nread)
-
jnhwSingeByteReadToInt
public static int jnhwSingeByteReadToInt(short nread)
-
-