本文整理了Java中jnr.constants.platform.Errno
类的一些代码示例,展示了Errno
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Errno
类的具体详情如下:
包路径:jnr.constants.platform.Errno
类名称:Errno
暂无
代码示例来源:origin: jenkinsci/jenkins
@Override public void error(Errno error, String methodName, String extraData) {
throw new PosixException("native error calling " + methodName + ": " + error.description() + " " + extraData, convert(error));
}
private org.jruby.ext.posix.POSIX.ERRORS convert(Errno error) {
代码示例来源:origin: jenkinsci/jenkins
private org.jruby.ext.posix.POSIX.ERRORS convert(Errno error) {
try {
return org.jruby.ext.posix.POSIX.ERRORS.valueOf(error.name());
} catch (IllegalArgumentException x) {
return org.jruby.ext.posix.POSIX.ERRORS.EIO; // PosixException.message has real error anyway
}
}
}, true);
代码示例来源:origin: org.jruby/jruby-core
long procSpawnSh(Ruby runtime, String str, ExecArg eargp) {
long status;
String shell = dlnFindExeR(runtime, "sh", eargp.path_env);
// System.out.println("before: " + shell + ", fa=" + eargp.fileActions + ", a=" + eargp.attributes + ", argv=" + Arrays.asList("sh", "-c", str));
status = runtime.getPosix().posix_spawnp(
shell != null ? shell : "/bin/sh",
eargp.fileActions,
eargp.attributes,
Arrays.asList("sh", "-c", str),
eargp.envp_str == null ? Collections.EMPTY_LIST : Arrays.asList(eargp.envp_str));
if (status == -1) errno = Errno.valueOf(runtime.getPosix().errno());
return status;
}
代码示例来源:origin: org.jruby/jruby-complete
/**
* Helper for handling common POSIX situations where a negative return value
* from a function call indicates an error, and errno must be consulted to
* determine how exactly the function failed.
* @param runtime Ruby runtime
* @param result return value of a POSIX call
*/
public static void checkErrno(Ruby runtime, int result) {
if (result < 0) {
// FIXME: The error message is a bit off.
// e.g., No such process - No such process (Errno::ESRCH)
// Note the repetition of 'No such process'.
Errno errno = Errno.valueOf(runtime.getPosix().errno());
String name = errno.name();
String msg = errno.toString();
RubyClass errnoClass = runtime.getErrno().getClass(name);
if (errnoClass != null) {
throw RaiseException.from(runtime, errnoClass, msg);
}
}
}
代码示例来源:origin: org.jruby/jruby-complete
stat_loc[0] = 0;
int result = runtime.getPosix().waitpid((int)finalPid, stat_loc, 0);
if (result == -1) {
Errno errno = Errno.valueOf(runtime.getPosix().errno());
switch (errno) {
case EINTR:
runtime.getCurrentContext().pollThreadEvents();
continue retry;
case ECHILD:
return -1;
default:
throw new RuntimeException("unexpected waitpid errno: " + Errno.valueOf(runtime.getPosix().errno()));
代码示例来源:origin: org.jruby/jruby-complete
/**
* Create module Errno's Variables. We have this method since Errno does not have its
* own java class.
*/
private void initErrno() {
if (profile.allowModule("Errno")) {
errnoModule = defineModule("Errno");
try {
// define EAGAIN now, so that future EWOULDBLOCK will alias to it
// see MRI's error.c and its explicit ordering of Errno definitions.
createSysErr(Errno.EAGAIN.intValue(), Errno.EAGAIN.name());
for (Errno e : Errno.values()) {
Constant c = (Constant) e;
if (Character.isUpperCase(c.name().charAt(0))) {
createSysErr(c.intValue(), c.name());
}
}
// map ENOSYS to NotImplementedError
errnos.put(Errno.ENOSYS.intValue(), notImplementedError);
} catch (Exception e) {
// dump the trace and continue
// this is currently only here for Android, which seems to have
// bugs in its enumeration logic
// http://code.google.com/p/android/issues/detail?id=2812
LOG.error(e);
}
}
}
代码示例来源:origin: org.jruby/jruby-complete
private static long transfer(ThreadContext context, ReadableByteChannel from, FileChannel to, long length, long position) throws IOException {
// handle large files on 32-bit JVMs
long chunkSize = 128 * 1024 * 1024;
long transferred = 0;
long bytes;
long startPosition = to.position();
if (position != -1) {
if (from instanceof NativeSelectableChannel) {
int ret = context.runtime.getPosix().lseek(((NativeSelectableChannel)from).getFD(), position, PosixShim.SEEK_SET);
if (ret == -1) {
throw context.runtime.newErrnoFromErrno(Errno.valueOf(context.runtime.getPosix().errno()), from.toString());
}
}
}
if (length > 0) {
while ((bytes = to.transferFrom(from, startPosition+transferred, Math.min(chunkSize, length))) > 0) {
transferred += bytes;
length -= bytes;
}
} else {
while ((bytes = to.transferFrom(from, startPosition+transferred, chunkSize)) > 0) {
transferred += bytes;
}
}
// transforFrom does not change position of target
to.position(startPosition + transferred);
return transferred;
}
代码示例来源:origin: org.jruby/jruby-complete
public RaiseException newErrnoFromInt(int errno) {
Errno errnoObj = Errno.valueOf(errno);
if (errnoObj == null) {
return newSystemCallError("Unknown Error (" + errno + ")");
}
String message = errnoObj.description();
return newErrnoFromInt(errno, message);
}
代码示例来源:origin: org.jruby/jruby-complete
POSIX posix = runtime.getPosix();
if (posix.isNative() && !Platform.IS_WINDOWS) {
IRubyObject oldExc = context.runtime.getGlobalVariables().get("$!"); // Save $!
try {
RubyFile.unlink(context, this);
if (errno != Errno.ENOENT.intValue() && errno != Errno.EACCES.intValue()) {
throw re;
context.runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
代码示例来源:origin: org.jruby/jruby-complete
public long size(ChannelFD fd) {
if (fd.chNative != null) { // native fd, use fstat
FileStat stat = posix.allocateStat();
int ret = posix.fstat(fd.chNative.getFD(), stat);
if (ret == -1) {
errno = Errno.valueOf(posix.errno());
return -1;
}
return stat.st_size();
} else if (fd.chSeek != null) { // if it is seekable, get size directly
try {
return fd.chSeek.size();
} catch (IOException ioe) {
errno = Helpers.errnoFromException(ioe);
return -1;
}
} else {
// otherwise just return -1 (should be rare, since size is only defined on File
errno = Errno.EINVAL;
return -1;
}
}
代码示例来源:origin: com.github.serceman/jnr-fuse
/**
* Address family not supported by protocol
*/
public static int EAFNOSUPPORT() {
return Errno.EAFNOSUPPORT.intValue();
}
代码示例来源:origin: org.jruby/jruby-complete
public int setCloexec(int fd, boolean cloexec) {
int ret = posix.fcntl(fd, Fcntl.F_GETFD);
if (ret == -1) {
errno = Errno.valueOf(posix.errno());
return -1;
}
if (
(cloexec && (ret & FcntlLibrary.FD_CLOEXEC) == FcntlLibrary.FD_CLOEXEC)
|| (!cloexec && (ret & FcntlLibrary.FD_CLOEXEC) == 0)) {
return 0;
}
ret = cloexec ?
ret | FcntlLibrary.FD_CLOEXEC :
ret & ~FcntlLibrary.FD_CLOEXEC;
ret = posix.fcntlInt(fd, Fcntl.F_SETFD, ret);
if (ret == -1) errno = Errno.valueOf(posix.errno());
return ret;
}
代码示例来源:origin: org.jruby/jruby-complete
public void error(Errno error, String extraData) {
throw runtime.newErrnoFromInt(error.intValue(), extraData);
}
代码示例来源:origin: org.jruby/jruby-complete
public RaiseException newErrnoFromInt(int errno, String methodName, String message) {
if (Platform.IS_WINDOWS && ("stat".equals(methodName) || "lstat".equals(methodName))) {
if (errno == 20047) return newErrnoENOENTError(message); // boo:bar UNC stat failure
if (errno == Errno.ESRCH.intValue()) return newErrnoENOENTError(message); // ESRCH on stating ""
}
return newErrnoFromInt(errno, message);
}
代码示例来源:origin: org.jruby/jruby-complete
context.setLastExitStatus(new RubyProcess.RubyStatus(runtime, runtime.getProcStatus(), 0x7f << 8, 0));
if (errno == null || errno == Errno.__UNKNOWN_CONSTANT__) {
errno = Errno.valueOf(runtime.getPosix().errno());
代码示例来源:origin: org.jruby/jruby-complete
public int ftruncate(ChannelFD fd, long pos) {
if (fd.chNative != null) {
int ret = posix.ftruncate(fd.chNative.getFD(), pos);
if (ret == -1) errno = Errno.valueOf(posix.errno());
return ret;
} else if (fd.chFile != null) {
try {
fd.chFile.truncate(pos);
} catch (IOException ioe) {
errno = Helpers.errnoFromException(ioe);
return -1;
}
} else {
errno = Errno.EINVAL;
return -1;
}
return 0;
}
代码示例来源:origin: org.jruby/jruby-complete
public int fcntlSetFD(int fd, int flags) {
int ret = posix.fcntlInt(fd, Fcntl.F_SETFD, flags);
if (ret == -1) errno = Errno.valueOf(posix.errno());
return ret;
}
代码示例来源:origin: org.jruby/jruby-complete
static ChannelFD open_func(Ruby runtime, RubyIO.Sysopen data) {
ChannelFD ret = parentRedirectOpen(runtime, data);
data.errno = Errno.valueOf(runtime.getPosix().errno());
return ret;
}
代码示例来源:origin: com.github.jnr/jnr-posix
@Override
public FileStat fstat(int fd) {
FileStat stat = allocateStat();
int ret = fstat(fd, stat);
if (ret < 0) handler.error(Errno.valueOf(errno()), "fstat", Integer.toString(fd));
return stat;
}
代码示例来源:origin: com.cloudbees.util/jnr-unixsocket-nodep
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();
}
内容来源于网络,如有侵权,请联系作者删除!