protected IRubyObject case_aware_op_aset( ThreadContext context, IRubyObject key, final IRubyObject value, boolean caseSensitive) { if (!key.respondsTo("to_str")) { throw getRuntime().newTypeError("can't convert " + key.getMetaClass() + " into String"); } if (!value.respondsTo("to_str") && !value.isNil()) { throw getRuntime().newTypeError("can't convert " + value.getMetaClass() + " into String"); } if (!caseSensitive) { key = getCorrectKey(key, context); } if (value.isNil()) { return super.delete(context, key, org.jruby.runtime.Block.NULL_BLOCK); } IRubyObject keyAsStr = normalizeEnvString(Helpers.invoke(context, key, "to_str")); IRubyObject valueAsStr = value.isNil() ? context.nil : normalizeEnvString(Helpers.invoke(context, value, "to_str")); if (updateRealENV) { POSIX posix = context.runtime.getPosix(); String keyAsJava = keyAsStr.asJavaString(); // libc (un)setenv is not reentrant, so we need to synchronize across the entire JVM // (JRUBY-5933) if (valueAsStr == context.nil) { synchronized (Object.class) { posix.unsetenv(keyAsJava); } } else { synchronized (Object.class) { posix.setenv(keyAsJava, valueAsStr.asJavaString(), 1); } } } return super.op_aset(context, keyAsStr, valueAsStr); }
public static boolean hasNonTTYInput() { POSIX posix = POSIXFactory.getPOSIX(); return !posix.isatty(FileDescriptor.in); }