/* * call-seq: * #write_unblocked(string) -> integer * * Writes the given string to <em>ios</em> using * the write(2) system call. It assumes that O_NONBLOCK * is already set for the underlying file descriptor. * * Over ~100,000 calls it is about 0.043 seconds faster. * * It returns the number of bytes written. */ static VALUE rb_yaram_mbox_write_unblocked(VALUE self, VALUE io, VALUE str) { rb_io_t *fptr; long n; rb_secure(4); if (TYPE(str) != T_STRING) str = rb_obj_as_string(str); io = rb_io_get_write_io(io); GetOpenFile(io, fptr); rb_io_check_writable(fptr); if (io_fflush(fptr) < 0) rb_sys_fail(0); n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str)); if (n == -1) { if (errno == EWOULDBLOCK || errno == EAGAIN) rb_mod_sys_fail(rb_mWaitWritable, "write would block"); rb_sys_fail_path(fptr->pathv); } return LONG2FIX(n); }
/* * call-seq: * io.getpass(prompt=nil) -> string * * Reads and returns a line without echo back. * Prints +prompt+ unless it is +nil+. * * You must require 'io/console' to use this method. */ static VALUE console_getpass(int argc, VALUE *argv, VALUE io) { VALUE str, wio; rb_check_arity(argc, 0, 1); wio = rb_io_get_write_io(io); if (wio == io && io == rb_stdin) wio = rb_stderr; prompt(argc, argv, wio); str = rb_ensure(getpass_call, io, puts_call, wio); return str_chomp(str); }