public FileStat fstat(int fd) { FileStat stat = allocateStat(); if (fstat(fd, stat) < 0) handler.error(Errno.valueOf(errno()), "fstat", "" + fd); return stat; }
public RLimit getrlimit(int resource) { RLimit rlim = new DefaultNativeRLimit(getRuntime()); if (getrlimit(resource, rlim) < 0) handler.error(Errno.valueOf(errno()), "rlim"); return rlim; }
public int lchmod(String filename, int mode) { try { return libc().lchmod(filename, mode); } catch (UnsatisfiedLinkError ule) { return unimplementedInt(); } }
public FileStat stat(String path) { FileStat stat = allocateStat(); if (stat(path, stat) < 0) handler.error(Errno.valueOf(errno()), "stat", path); return stat; }
public FileStat lstat(String path) { FileStat stat = allocateStat(); if (lstat(path, stat) < 0) handler.error(Errno.valueOf(errno()), "lstat", path); return stat; }
private Pointer nativeFileActions(Collection<? extends SpawnFileAction> fileActions) { Pointer nativeFileActions = Memory.allocateDirect(getRuntime(), 128); ((UnixLibC) libc()).posix_spawn_file_actions_init(nativeFileActions); for (SpawnFileAction action : fileActions) { action.act(this, nativeFileActions); } return nativeFileActions; }
public long posix_spawnp(String path, Collection<? extends SpawnFileAction> fileActions, Collection<? extends SpawnAttribute> spawnAttributes, CharSequence[] argv, CharSequence[] envp) { // AbstractNumberReference<? extends Number> pid = getRuntime().findType(TypeAlias.pid_t).size() == 4 // ? new IntByReference(-1) : new LongLongByReference(-1); NumberByReference pid = new NumberByReference(TypeAlias.pid_t); Pointer nativeFileActions = fileActions != null && !fileActions.isEmpty() ? nativeFileActions(fileActions) : null; Pointer nativeSpawnAttributes = spawnAttributes != null && !spawnAttributes.isEmpty() ? nativeSpawnAttributes(spawnAttributes) : null; long result; try { result = ((UnixLibC) libc()).posix_spawnp(pid, path, nativeFileActions, nativeSpawnAttributes, argv, envp); } finally { if (nativeFileActions != null) ((UnixLibC) libc()).posix_spawn_file_actions_destroy(nativeFileActions); if (nativeSpawnAttributes != null) ((UnixLibC) libc()).posix_spawnattr_destroy(nativeSpawnAttributes); } if (result != 0) return -1; // result will be errno, but we can't indicate error because we return pid return pid.longValue(); }
public long posix_spawnp(String path, Collection<? extends SpawnFileAction> fileActions, CharSequence[] argv, CharSequence[] envp) { AbstractNumberReference<? extends Number> pid = Library.getRuntime(libc()).findType(TypeAlias.pid_t).size() == 4 ? new IntByReference(-1) : new LongLongByReference(-1); Pointer nativeFileActions = nativeFileActions(fileActions); try { if (((UnixLibC) libc()).posix_spawnp(pid, path, nativeFileActions, null, argv, envp) < 0) { Errno e = Errno.valueOf(errno()); handler.error(e, "posix_spawnp", e.description()); } } finally { ((UnixLibC) libc()).posix_spawn_file_actions_destroy(nativeFileActions); } return pid.longValue(); }
protected int unimplementedInt() { handler().unimplementedError(MethodName.getCallerMethodName()); return -1; }
public long posix_spawnp(String path, Collection<? extends SpawnFileAction> fileActions, CharSequence[] argv, CharSequence[] envp) { return posix_spawnp(path, fileActions, null, argv, envp); }
public int errno() { return LastError.getLastError(getRuntime()); }
public String getcwd() { byte[] cwd = new byte[1024]; long result = libc().getcwd(cwd, 1024); if (result == -1) return null; int len = 0; for (; len < 1024; len++) if (cwd[len] == 0) break; return new String(cwd, 0, len); }
private int old_fstat(int fd, FileStat stat) { try { return super.fstat(fd, stat); } catch (UnsatisfiedLinkError ex2) { handler.unimplementedError("fstat"); return -1; } }
private final int old_lstat(String path, FileStat stat) { try { return super.lstat(path, stat); } catch (UnsatisfiedLinkError ex) { handler.unimplementedError("lstat"); return -1; } }
private final int old_stat(String path, FileStat stat) { try { return super.stat(path, stat); } catch (UnsatisfiedLinkError ex) { handler.unimplementedError("stat"); return -1; } }
private Pointer nativeSpawnAttributes(Collection<? extends SpawnAttribute> spawnAttributes) { Pointer nativeSpawnAttributes = allocatePosixSpawnattr(); ((UnixLibC) libc()).posix_spawnattr_init(nativeSpawnAttributes); for (SpawnAttribute action : spawnAttributes) { action.set(this, nativeSpawnAttributes); } return nativeSpawnAttributes; }
private Pointer nativeFileActions(Collection<? extends SpawnFileAction> fileActions) { Pointer nativeFileActions = allocatePosixSpawnFileActions(); ((UnixLibC) libc()).posix_spawn_file_actions_init(nativeFileActions); for (SpawnFileAction action : fileActions) { action.act(this, nativeFileActions); } return nativeFileActions; }
public long sysconf(Sysconf name) { switch (name) { case _SC_CLK_TCK: return JavaTimes.HZ; default: errno(Errno.EOPNOTSUPP.intValue()); return -1; } }
public int setrlimit(int resource, long rlimCur, long rlimMax) { RLimit rlim = new DefaultNativeRLimit(getRuntime()); rlim.init(rlimCur, rlimMax); return libc().setrlimit(resource, rlim); }