Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
io.c File Reference
`#include "ruby/encoding.h"`
`#include "ruby/io.h"`
`#include "ruby/thread.h"`
`#include "internal.h"`
`#include "dln.h"`
`#include "encindex.h"`
`#include "id.h"`
`#include <ctype.h>`
`#include <errno.h>`
`#include "ruby_atomic.h"`
`#include "ccan/list/list.h"`
`#include "vm_core.h"`
`#include "builtin.h"`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include "ruby/util.h"`
`#include "io.rbinc"`

Go to the source code of this file.

## Data Structures
struct | argf
struct | io_internal_read_struct
struct | io_internal_write_struct
struct | binwrite_arg
struct | write_arg
struct | bufread_arg
struct | getline_arg
struct | finish_writeconv_arg
struct | sysopen_struct
struct | pipe_list
struct | rb_f_p_arg
struct | select_args
struct | io_encoding_set_args
struct | foreach_arg
struct | seek_arg
struct | copy_stream_struct
struct | argf_call_arg

## Macros
#define | USE_POLL 0
#define | free(x) xfree(x)
#define | off_t long
#define | NOFILE 64
#define | O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
#define | PIPE_BUF 512 /* is this ok? */
#define | EWOULDBLOCK EAGAIN
#define | IO_RBUF_CAPA_MIN 8192
#define | IO_CBUF_CAPA_MIN (128*1024)
#define | IO_RBUF_CAPA_FOR(fptr) (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)
#define | IO_WBUF_CAPA_MIN 8192
#define | RUBY_PIPE_NONBLOCK_DEFAULT (0)
#define | argf_of(obj) (*(struct argf *)DATA_PTR(obj))
#define | ARGF argf_of(argf)
#define | GetWriteIO(io) rb_io_get_write_io(io)
#define | READ_DATA_PENDING(fptr) ((fptr)->rbuf.len)
#define | READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf.len)
#define | READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf.ptr+(fptr)->rbuf.off)
#define | READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
#define | READ_CHAR_PENDING(fptr) ((fptr)->cbuf.len)
#define | READ_CHAR_PENDING_COUNT(fptr) ((fptr)->cbuf.len)
#define | READ_CHAR_PENDING_PTR(fptr) ((fptr)->cbuf.ptr+(fptr)->cbuf.off)
#define | WAIT_FD_IN_WIN32(fptr)
#define | READ_CHECK(fptr)
#define | NEED_NEWLINE_DECORATOR_ON_READ(fptr) ((fptr)->mode & FMODE_TEXTMODE)
#define | NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) ((fptr)->mode & FMODE_TEXTMODE)
#define | DEFAULT_TEXTMODE 0
#define | NEED_READCONV(fptr) ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
#define | NEED_WRITECONV(fptr)
#define | SET_BINARY_MODE(fptr) (void)(fptr)
#define | NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr) (void)(fptr)
#define | SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags) ((void)(enc2), (void)(ecflags))
#define | SET_BINARY_MODE_WITH_SEEK_CUR(fptr) (void)(fptr)
#define | shutdown(a, b) 0
#define | is_socket(fd, path) 0
#define | io_seek(fptr, ofs, whence) (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))
#define | io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
#define | SEEK_SET 0
#define | SEEK_CUR 1
#define | SEEK_END 2
#define | S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define | do_write_retry(code) ret = code
#define | MODE_BTMODE(a, b, c)
#define | MODE_BTXMODE(a, b, c, d, e, f)
#define | fmode (fptr->mode)
#define | rb_io_fsync rb_f_notimplement
#define | rb_io_sync rb_f_notimplement
#define | rb_io_fdatasync rb_io_fsync
#define | MORE_CHAR_SUSPENDED Qtrue
#define | MORE_CHAR_FINISHED Qnil
#define | MAX_REALLOC_GAP 4096
#define | no_exception_p(opts) !rb_opts_exception_p((opts), TRUE)
#define | rb_io_close_on_exec_p rb_f_notimplement
#define | rb_io_set_close_on_exec rb_f_notimplement
#define | FMODE_PREP (1<<16)
#define | IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
#define | PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
#define | rb_io_fptr_finalize(fptr) rb_io_fptr_finalize_internal(fptr)
#define | KEEPGVL FALSE
#define | SHUT_RD 0
#define | SHUT_WR 1
#define | rb_io_pread rb_f_notimplement
#define | rb_io_pwrite rb_f_notimplement
#define | MODE_BINARY(a, b) (a)
#define | next_argv() argf_next_argv(argf)
#define | ARGF_GENERIC_INPUT_P() (ARGF.current_file == rb_stdin && !RB_TYPE_P(ARGF.current_file, T_FILE))
#define | ARGF_FORWARD(argc, argv)
#define | NEXT_ARGF_FORWARD(argc, argv)
#define | NUM2IOCTLREQ(num) ((int)NUM2LONG(num))
#define | DEFULT_IOCTL_NARG_LEN (256)
#define | rb_io_ioctl rb_f_notimplement
#define | rb_io_fcntl rb_f_notimplement
#define | rb_f_syscall rb_f_notimplement
#define | IOWAIT_SYSCALL "select"
#define | FOREACH_ARGF() while (next_argv())
#define | rb_intern(str) rb_intern_const(str)

## Typedefs
typedef struct rb_io_enc_t | convconfig_t
typedef int | ioctl_req_t

## Enumerations
enum | { bom_prefix_len = (int)sizeof(bom_prefix) - 1 }
enum | { utf_prefix_len = (int)sizeof(utf_prefix) - 1 }

## Functions
void | rb_update_max_fd (int fd)
void | rb_maygvl_fd_fix_cloexec (int fd)
void | rb_fd_fix_cloexec (int fd)
int | rb_cloexec_open (const char *pathname, int flags, mode_t mode)
int | rb_cloexec_dup (int oldfd)
int | rb_cloexec_dup2 (int oldfd, int newfd)
int | rb_cloexec_pipe (int fildes[2])
int | rb_cloexec_fcntl_dupfd (int fd, int minfd)
void | rb_eof_error (void)
VALUE | rb_io_taint_check (VALUE io)
void | rb_io_check_initialized (rb_io_t *fptr)
void | rb_io_check_closed (rb_io_t *fptr)
VALUE | rb_io_get_io (VALUE io)
VALUE | rb_io_check_io (VALUE io)
VALUE | rb_io_get_write_io (VALUE io)
VALUE | rb_io_set_write_io (VALUE io, VALUE w)
void | rb_io_check_char_readable (rb_io_t *fptr)
void | rb_io_check_byte_readable (rb_io_t *fptr)
void | rb_io_check_readable (rb_io_t *fptr)
void | rb_io_check_writable (rb_io_t *fptr)
int | rb_io_read_pending (rb_io_t *fptr)
void | rb_io_read_check (rb_io_t *fptr)
int | rb_gc_for_fd (int err)
int | rb_io_wait_readable (int f)
int | rb_io_wait_writable (int f)
ssize_t | rb_io_bufwrite (VALUE io, const void *buf, size_t size)
VALUE | rb_io_write (VALUE io, VALUE str)
VALUE | rb_io_addstr (VALUE io, VALUE str)
VALUE | rb_io_flush_raw (VALUE io, int sync)
VALUE | rb_io_flush (VALUE io)
VALUE | rb_io_eof (VALUE io)
void | rb_io_set_nonblock (rb_io_t *fptr)
VALUE | rb_io_gets (VALUE io)
VALUE | rb_io_gets_internal (VALUE io)
VALUE | rb_io_getbyte (VALUE io)
VALUE | rb_io_ungetbyte (VALUE io, VALUE b)
VALUE | rb_io_ungetc (VALUE io, VALUE c)
void | rb_io_fptr_finalize_internal (void *ptr)
int | rb_io_fptr_finalize (rb_io_t *fptr)
RUBY_FUNC_EXPORTED size_t | rb_io_memsize (const rb_io_t *fptr)
int | rb_notify_fd_close (int fd, struct list_head *)
VALUE | rb_io_close (VALUE io)
VALUE | rb_io_binmode (VALUE io)
VALUE | rb_io_ascii8bit_binmode (VALUE io)
int | rb_io_modestr_fmode (const char *modestr)
int | rb_io_oflags_fmode (int oflags)
int | rb_io_modestr_oflags (const char *modestr)
int | rb_io_extract_encoding_option (VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
void | rb_io_extract_modeenc (VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, convconfig_t *convconfig_p)
FILE * | rb_fdopen (int fd, const char *modestr)
VALUE | rb_file_open_str (VALUE fname, const char *modestr)
VALUE | rb_file_open (const char *fname, const char *modestr)
void | rb_io_synchronized (rb_io_t *fptr)
void | rb_io_unbuffered (rb_io_t *fptr)
int | rb_pipe (int *pipes)
char * | rb_execarg_commandline (const struct rb_execarg *eargp, VALUE *prog)
VALUE | rb_io_printf (int argc, const VALUE *argv, VALUE out)
VALUE | rb_io_print (int argc, const VALUE *argv, VALUE out)
int | rb_str_end_with_asciichar (VALUE str, int c)
VALUE | rb_io_puts (int argc, const VALUE *argv, VALUE out)
void | rb_p (VALUE obj)
void | rb_write_error2 (const char *mesg, long len)
void | rb_write_error (const char *mesg)
void | rb_write_error_str (VALUE mesg)
int | rb_stderr_tty_p (void)
VALUE | rb_io_fdopen (int fd, int oflags, const char *path)
FILE * | rb_io_stdio_file (rb_io_t *fptr)
rb_io_t * | rb_io_make_open_file (VALUE obj)
VALUE | rb_gets (void)
void | rb_stdio_set_default_encoding (void)
void | ruby_set_inplace_mode (const char *suffix)
VALUE | rb_get_argv (void)
void | rb_readwrite_sys_fail (enum rb_io_wait_readwrite writable, const char *mesg)
void | rb_readwrite_syserr_fail (enum rb_io_wait_readwrite writable, int n, const char *mesg)
void | Init_IO (void)
void | Init_IO_nonblock (void)

## Variables
VALUE | rb_cIO
VALUE | rb_eEOFError
VALUE | rb_eIOError
VALUE | rb_mWaitReadable
VALUE | rb_mWaitWritable
VALUE | rb_stdin
VALUE | rb_stdout
VALUE | rb_stderr
VALUE | rb_output_fs
VALUE | rb_rs
VALUE | rb_output_rs
VALUE | rb_default_rs

## Macro Definition Documentation

## ◆ ARGF

#define ARGF argf_of(argf)

Definition at line 462 of file io.c.

## ◆ ARGF_FORWARD

#define ARGF_FORWARD | ( |  | argc,
|  |  | argv
| ) |  |

Value:
do {\
if (ARGF_GENERIC_INPUT_P())\
return argf_forward((argc), (argv), argf);\
} while (0)

Definition at line 8584 of file io.c.

## ◆ ARGF_GENERIC_INPUT_P

#define ARGF_GENERIC_INPUT_P | ( |  | ) | (ARGF.current_file == rb_stdin && !RB_TYPE_P(ARGF.current_file, T_FILE))

Definition at line 8582 of file io.c.

## ◆ argf_of

#define argf_of | ( |  | obj | ) | (*(struct argf *)DATA_PTR(obj))

Definition at line 461 of file io.c.

## ◆ DEFAULT_TEXTMODE

#define DEFAULT_TEXTMODE 0

Definition at line 653 of file io.c.

## ◆ DEFULT_IOCTL_NARG_LEN

#define DEFULT_IOCTL_NARG_LEN (256)

Definition at line 9608 of file io.c.

## ◆ do_write_retry

#define do_write_retry | ( |  | code | ) | ret = code

Definition at line 1039 of file io.c.

## ◆ EWOULDBLOCK

#define EWOULDBLOCK EAGAIN

Definition at line 141 of file io.c.

## ◆ fmode

#define fmode (fptr->mode)

## ◆ FMODE_PREP

#define FMODE_PREP (1<<16)

Definition at line 4482 of file io.c.

## ◆ FOREACH_ARGF

#define FOREACH_ARGF | ( |  | ) | while (next_argv())

Definition at line 12389 of file io.c.

## ◆ free

#define free | ( |  | x | ) | xfree(x)

Definition at line 47 of file io.c.

## ◆ GetWriteIO

#define GetWriteIO | ( |  | io | ) | rb_io_get_write_io(io)

Definition at line 464 of file io.c.

## ◆ IO_CBUF_CAPA_MIN

#define IO_CBUF_CAPA_MIN (128*1024)

Definition at line 150 of file io.c.

## ◆ IO_RBUF_CAPA_FOR

#define IO_RBUF_CAPA_FOR | ( |  | fptr | ) | (NEED_READCONV(fptr) ? IO_CBUF_CAPA_MIN : IO_RBUF_CAPA_MIN)

Definition at line 151 of file io.c.

## ◆ IO_RBUF_CAPA_MIN

#define IO_RBUF_CAPA_MIN 8192

Definition at line 149 of file io.c.

## ◆ io_seek

#define io_seek | ( |  | fptr,
|  |  | ofs,
|  |  | whence
| ) |  | (errno = 0, lseek(flush_before_seek(fptr)->fd, (ofs), (whence)))

Definition at line 861 of file io.c.

## ◆ io_tell

#define io_tell | ( |  | fptr | ) | lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)

Definition at line 862 of file io.c.

## ◆ IO_WBUF_CAPA_MIN

#define IO_WBUF_CAPA_MIN 8192

Definition at line 152 of file io.c.

## ◆ IOWAIT_SYSCALL

#define IOWAIT_SYSCALL "select"

Definition at line 10825 of file io.c.

## ◆ IS_PREP_STDIO

#define IS_PREP_STDIO | ( |  | f | ) | ((f)->mode & FMODE_PREP)

Definition at line 4483 of file io.c.

## ◆ is_socket

#define is_socket | ( |  | fd,
|  |  | path
| ) |  | 0

Definition at line 673 of file io.c.

## ◆ KEEPGVL

#define KEEPGVL FALSE

Definition at line 4775 of file io.c.

## ◆ MAX_REALLOC_GAP

#define MAX_REALLOC_GAP 4096

Definition at line 2694 of file io.c.

## ◆ MODE_BINARY

#define MODE_BINARY | ( |  | a,
|  |  | b
| ) |  | (a)

## ◆ MODE_BTMODE

#define MODE_BTMODE | ( |  | a,
|  |  | b,
|  |  | c
| ) |  |

Value:
((fmode & FMODE_BINMODE) ? (b) : \
(fmode & FMODE_TEXTMODE) ? (c) : (a))

Definition at line 1459 of file io.c.

## ◆ MODE_BTXMODE

#define MODE_BTXMODE | ( |  | a,
|  |  | b,
|  |  | c,
|  |  | d,
|  |  | e,
|  |  | f
| ) |  |

Value:
((fmode & FMODE_EXCL) ? \
MODE_BTMODE(d, e, f) : \
MODE_BTMODE(a, b, c))

Definition at line 1462 of file io.c.

## ◆ MORE_CHAR_FINISHED

#define MORE_CHAR_FINISHED Qnil

Definition at line 2560 of file io.c.

## ◆ MORE_CHAR_SUSPENDED

#define MORE_CHAR_SUSPENDED Qtrue

Definition at line 2559 of file io.c.

## ◆ NEED_NEWLINE_DECORATOR_ON_READ

#define NEED_NEWLINE_DECORATOR_ON_READ | ( |  | fptr | ) | ((fptr)->mode & FMODE_TEXTMODE)

Definition at line 506 of file io.c.

## ◆ NEED_NEWLINE_DECORATOR_ON_READ_CHECK

#define NEED_NEWLINE_DECORATOR_ON_READ_CHECK | ( |  | fptr | ) | (void)(fptr)

Definition at line 661 of file io.c.

## ◆ NEED_NEWLINE_DECORATOR_ON_WRITE

#define NEED_NEWLINE_DECORATOR_ON_WRITE | ( |  | fptr | ) | ((fptr)->mode & FMODE_TEXTMODE)

Definition at line 507 of file io.c.

## ◆ NEED_READCONV

#define NEED_READCONV | ( |  | fptr | ) | ((fptr)->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))

Definition at line 654 of file io.c.

## ◆ NEED_WRITECONV

#define NEED_WRITECONV | ( |  | fptr | ) |

Value:
( \
((fptr)->encs.enc != NULL && (fptr)->encs.enc != rb_ascii8bit_encoding()) || \
NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || \
((fptr)->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK)) || \
0)

Definition at line 655 of file io.c.

## ◆ NEXT_ARGF_FORWARD

#define NEXT_ARGF_FORWARD | ( |  | argc,
|  |  | argv
| ) |  |

Value:
do {\
if (!next_argv()) return Qnil;\
ARGF_FORWARD((argc), (argv));\
} while (0)

Definition at line 8588 of file io.c.

## ◆ next_argv

#define next_argv | ( |  | ) | argf_next_argv(argf)

Definition at line 8581 of file io.c.

## ◆ no_exception_p

#define no_exception_p | ( |  | opts | ) | !rb_opts_exception_p((opts), TRUE)

Definition at line 2803 of file io.c.

## ◆ NOFILE

#define NOFILE 64

Definition at line 97 of file io.c.

## ◆ NUM2IOCTLREQ

#define NUM2IOCTLREQ | ( |  | num | ) | ((int)NUM2LONG(num))

Definition at line 9574 of file io.c.

## ◆ O_ACCMODE

#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)

Definition at line 125 of file io.c.

## ◆ off_t

#define off_t long

Definition at line 83 of file io.c.

## ◆ PIPE_BUF

#define PIPE_BUF 512 /* is this ok? */

Definition at line 136 of file io.c.

## ◆ PREP_STDIO_NAME

#define PREP_STDIO_NAME | ( |  | f | ) | (RSTRING_PTR((f)->pathv))

Definition at line 4484 of file io.c.

## ◆ rb_f_syscall

#define rb_f_syscall rb_f_notimplement

Definition at line 10107 of file io.c.

## ◆ rb_intern

#define rb_intern | ( |  | str | ) | rb_intern_const(str)

## ◆ rb_io_close_on_exec_p

#define rb_io_close_on_exec_p rb_f_notimplement

Definition at line 4421 of file io.c.

## ◆ rb_io_fcntl

#define rb_io_fcntl rb_f_notimplement

Definition at line 9977 of file io.c.

## ◆ rb_io_fdatasync

#define rb_io_fdatasync rb_io_fsync

Definition at line 2304 of file io.c.

## ◆ rb_io_fptr_finalize

#define rb_io_fptr_finalize | ( |  | fptr | ) | rb_io_fptr_finalize_internal(fptr)

Definition at line 4757 of file io.c.

## ◆ rb_io_fsync

#define rb_io_fsync rb_f_notimplement

Definition at line 2252 of file io.c.

## ◆ rb_io_ioctl

#define rb_io_ioctl rb_f_notimplement

Definition at line 9883 of file io.c.

## ◆ rb_io_pread

#define rb_io_pread rb_f_notimplement

Definition at line 5270 of file io.c.

## ◆ rb_io_pwrite

#define rb_io_pwrite rb_f_notimplement

Definition at line 5330 of file io.c.

## ◆ rb_io_set_close_on_exec

#define rb_io_set_close_on_exec rb_f_notimplement

Definition at line 4479 of file io.c.

## ◆ rb_io_sync

#define rb_io_sync rb_f_notimplement

Definition at line 2253 of file io.c.

## ◆ READ_CHAR_PENDING

#define READ_CHAR_PENDING | ( |  | fptr | ) | ((fptr)->cbuf.len)

Definition at line 471 of file io.c.

## ◆ READ_CHAR_PENDING_COUNT

#define READ_CHAR_PENDING_COUNT | ( |  | fptr | ) | ((fptr)->cbuf.len)

Definition at line 472 of file io.c.

## ◆ READ_CHAR_PENDING_PTR

#define READ_CHAR_PENDING_PTR | ( |  | fptr | ) | ((fptr)->cbuf.ptr+(fptr)->cbuf.off)

Definition at line 473 of file io.c.

## ◆ READ_CHECK

#define READ_CHECK | ( |  | fptr | ) |

Value:
do {\
if (!READ_DATA_PENDING(fptr)) {\
WAIT_FD_IN_WIN32(fptr);\
rb_io_check_closed(fptr);\
}\
} while(0)

Definition at line 482 of file io.c.

## ◆ READ_DATA_BUFFERED

#define READ_DATA_BUFFERED | ( |  | fptr | ) | READ_DATA_PENDING(fptr)

Definition at line 469 of file io.c.

## ◆ READ_DATA_PENDING

#define READ_DATA_PENDING | ( |  | fptr | ) | ((fptr)->rbuf.len)

Definition at line 466 of file io.c.

## ◆ READ_DATA_PENDING_COUNT

#define READ_DATA_PENDING_COUNT | ( |  | fptr | ) | ((fptr)->rbuf.len)

Definition at line 467 of file io.c.

## ◆ READ_DATA_PENDING_PTR

#define READ_DATA_PENDING_PTR | ( |  | fptr | ) | ((fptr)->rbuf.ptr+(fptr)->rbuf.off)

Definition at line 468 of file io.c.

## ◆ RUBY_PIPE_NONBLOCK_DEFAULT

#define RUBY_PIPE_NONBLOCK_DEFAULT (0)

Definition at line 168 of file io.c.

## ◆ S_ISREG

#define S_ISREG | ( |  | m | ) | (((m) & S_IFMT) == S_IFREG)

Definition at line 992 of file io.c.

## ◆ SEEK_CUR

#define SEEK_CUR 1

Definition at line 866 of file io.c.

## ◆ SEEK_END

#define SEEK_END 2

Definition at line 867 of file io.c.

## ◆ SEEK_SET

#define SEEK_SET 0

Definition at line 865 of file io.c.

## ◆ SET_BINARY_MODE

#define SET_BINARY_MODE | ( |  | fptr | ) | (void)(fptr)

Definition at line 660 of file io.c.

## ◆ SET_BINARY_MODE_WITH_SEEK_CUR

#define SET_BINARY_MODE_WITH_SEEK_CUR | ( |  | fptr | ) | (void)(fptr)

Definition at line 663 of file io.c.

## ◆ SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2

#define SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2 | ( |  | enc2,
|  |  | ecflags
| ) |  | ((void)(enc2), (void)(ecflags))

Definition at line 662 of file io.c.

## ◆ SHUT_RD

#define SHUT_RD 0

## ◆ SHUT_WR

#define SHUT_WR 1

## ◆ shutdown

#define shutdown | ( |  | a,
|  |  | b
| ) |  | 0

Definition at line 667 of file io.c.

## ◆ USE_POLL

#define USE_POLL 0

Definition at line 37 of file io.c.

## ◆ WAIT_FD_IN_WIN32

#define WAIT_FD_IN_WIN32 | ( |  | fptr | ) |

Definition at line 479 of file io.c.

## Typedef Documentation

## ◆ convconfig_t

typedef struct rb_io_enc_t convconfig_t

Definition at line 5812 of file io.c.

## ◆ ioctl_req_t

typedef int ioctl_req_t

Definition at line 9573 of file io.c.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
bom_prefix_len |

Definition at line 5455 of file io.c.

## ◆ anonymous enum

anonymous enum

Enumerator
utf_prefix_len |

Definition at line 5456 of file io.c.

## Function Documentation

## ◆ Init_IO()

void Init_IO | ( | void |  | ) |

Definition at line 13140 of file io.c.

References NULL, O_BINARY, rb_define_class(), rb_eEOFError, rb_eIOError, and rb_eStandardError.

## ◆ Init_IO_nonblock()

void Init_IO_nonblock | ( | void |  | ) |

Definition at line 13510 of file io.c.

## ◆ rb_cloexec_dup()

int rb_cloexec_dup | ( | int | oldfd | ) |

Definition at line 318 of file io.c.

References rb_cloexec_fcntl_dupfd().

## ◆ rb_cloexec_dup2()

int rb_cloexec_dup2 | ( | int | oldfd,
|  | int | newfd
| ) |  |

Definition at line 325 of file io.c.

References dup2(), dup3(), ENOSYS, errno, O_CLOEXEC, and rb_maygvl_fd_fix_cloexec().

## ◆ rb_cloexec_fcntl_dupfd()

int rb_cloexec_fcntl_dupfd | ( | int | fd,
|  | int | minfd
| ) |  |

Definition at line 419 of file io.c.

References close(), dup(), EINVAL, errno, F_DUPFD, F_DUPFD_CLOEXEC, fcntl(), rb_cloexec_fcntl_dupfd(), and rb_maygvl_fd_fix_cloexec().

Referenced by rb_cloexec_dup(), and rb_cloexec_fcntl_dupfd().

## ◆ rb_cloexec_open()

int rb_cloexec_open | ( | const char * | pathname,
|  | int | flags,
|  | mode_t | mode
| ) |  |

Definition at line 292 of file io.c.

References O_CLOEXEC, and rb_maygvl_fd_fix_cloexec().

Referenced by rb_file_load_ok().

## ◆ rb_cloexec_pipe()

int rb_cloexec_pipe | ( | int | fildes[2] | ) |

Definition at line 378 of file io.c.

References close(), ENFILE, ENOSYS, errno, O_CLOEXEC, pipe(), pipe2(), rb_maygvl_fd_fix_cloexec(), and RUBY_PIPE_NONBLOCK_DEFAULT.

Referenced by rb_pipe().

## ◆ rb_eof_error()

void rb_eof_error | ( | void |  | ) |

Definition at line 697 of file io.c.

References rb_eEOFError, and rb_raise().

## ◆ rb_execarg_commandline()

char* rb_execarg_commandline | ( | const struct rb_execarg * | eargp,
|  | VALUE * | prog
| ) |  |

Definition at line 4317 of file process.c.

References argc, argv, ARGVSTR2ARGV, buf, rb_execarg::cmd, i, rb_execarg::invoke, str, and rb_execarg::use_shell.

## ◆ rb_fd_fix_cloexec()

void rb_fd_fix_cloexec | ( | int | fd | ) |

Definition at line 268 of file io.c.

References rb_maygvl_fd_fix_cloexec(), and rb_update_max_fd().

## ◆ rb_fdopen()

FILE* rb_fdopen | ( | int | fd,
|  | const char * | modestr
| ) |  |

Definition at line 6053 of file io.c.

References _IOFBF, EINVAL, EMFILE, errno, fdopen(), NULL, rb_gc(), rb_gc_for_fd(), rb_syserr_fail(), rb_warn(), and setvbuf().

## ◆ rb_file_open()

VALUE rb_file_open | ( | const char * | fname,
|  | const char * | modestr
| ) |  |

Definition at line 6259 of file io.c.

## ◆ rb_file_open_str()

VALUE rb_file_open_str | ( | VALUE | fname,
|  | const char * | modestr
| ) |  |

Definition at line 6252 of file io.c.

References FilePathValue, and sysopen_struct::fname.

## ◆ rb_gc_for_fd()

int rb_gc_for_fd | ( | int | err | ) |

Definition at line 953 of file io.c.

References EMFILE, ENFILE, ENOMEM, err, and rb_gc().

Referenced by rb_fdopen(), and rb_pipe().

## ◆ rb_get_argv()

VALUE rb_get_argv | ( | void |  | ) |

Definition at line 12889 of file io.c.

References ARGF.

## ◆ rb_gets()

VALUE rb_gets | ( | void |  | ) |

Definition at line 8902 of file io.c.

References rb_default_rs, and rb_rs.

## ◆ rb_io_addstr()

VALUE rb_io_addstr | ( | VALUE | io,
|  | VALUE | str
| ) |  |

Definition at line 1843 of file io.c.

References rb_io_write(), and str.

## ◆ rb_io_ascii8bit_binmode()

VALUE rb_io_ascii8bit_binmode | ( | VALUE | io | ) |

Definition at line 5380 of file io.c.

References GetOpenFile.

Referenced by rsock_init_sock().

## ◆ rb_io_binmode()

VALUE rb_io_binmode | ( | VALUE | io | ) |

Definition at line 5334 of file io.c.

References ECONV_NEWLINE_DECORATOR_MASK, rb_io_t::fd, FMODE_BINMODE, FMODE_TEXTMODE, GetOpenFile, rb_io_t::mode, O_BINARY, rb_econv_binmode(), rb_io_t::readconv, SET_BINARY_MODE_WITH_SEEK_CUR, rb_io_t::writeconv, and rb_io_t::writeconv_pre_ecflags.

## ◆ rb_io_bufwrite()

ssize_t rb_io_bufwrite | ( | VALUE | io,
|  | const void * | buf,
|  | size_t | size
| ) |  |

Definition at line 1549 of file io.c.

References binwrite_arg::fptr, GetOpenFile, and rb_io_check_writable().

## ◆ rb_io_check_byte_readable()

void rb_io_check_byte_readable | ( | rb_io_t * | fptr | ) |

Definition at line 890 of file io.c.

References rb_eIOError, rb_io_check_char_readable(), rb_raise(), and READ_CHAR_PENDING.

Referenced by rb_io_check_readable(), rb_io_getbyte(), and rb_io_ungetbyte().

## ◆ rb_io_check_char_readable()

void rb_io_check_char_readable | ( | rb_io_t * | fptr | ) |

Definition at line 871 of file io.c.

References FMODE_READABLE, rb_io_t::mode, rb_eIOError, rb_io_check_closed(), rb_raise(), and rb_io_t::wbuf.

Referenced by rb_io_check_byte_readable(), rb_io_eof(), and rb_io_ungetc().

## ◆ rb_io_check_closed()

void rb_io_check_closed | ( | rb_io_t * | fptr | ) |

Definition at line 718 of file io.c.

References rb_io_check_initialized().

Referenced by rb_io_check_char_readable(), and rb_io_check_writable().

## ◆ rb_io_check_initialized()

void rb_io_check_initialized | ( | rb_io_t * | fptr | ) |

Definition at line 710 of file io.c.

References rb_eIOError, and rb_raise().

Referenced by rb_io_check_closed(), and rb_io_synchronized().

## ◆ rb_io_check_io()

VALUE rb_io_check_io | ( | VALUE | io | ) |

Definition at line 739 of file io.c.

References idTo_io, rb_check_convert_type_with_id(), and T_FILE.

## ◆ rb_io_check_readable()

void rb_io_check_readable | ( | rb_io_t * | fptr | ) |

Definition at line 899 of file io.c.

References rb_io_check_byte_readable().

## ◆ rb_io_check_writable()

void rb_io_check_writable | ( | rb_io_t * | fptr | ) |

Definition at line 923 of file io.c.

References FMODE_WRITABLE, rb_io_t::mode, rb_eIOError, rb_io_check_closed(), rb_raise(), and rb_io_t::rbuf.

Referenced by rb_io_bufwrite().

## ◆ rb_io_close()

VALUE rb_io_close | ( | VALUE | io | ) |

Definition at line 4820 of file io.c.

Referenced by rb_io_make_open_file().

## ◆ rb_io_eof()

VALUE rb_io_eof | ( | VALUE | io | ) |

Definition at line 2149 of file io.c.

References rb_io_t::fd, GetOpenFile, NEED_NEWLINE_DECORATOR_ON_READ, NEED_READCONV, Qfalse, Qtrue, rb_io_check_char_readable(), READ_CHAR_PENDING, READ_CHECK, and READ_DATA_PENDING.

## ◆ rb_io_extract_encoding_option()

int rb_io_extract_encoding_option | ( | VALUE | opt,
|  | rb_encoding ** | enc_p,
|  | rb_encoding ** | enc2_p,
|  | int * | fmode_p
| ) |  |

Definition at line 5744 of file io.c.

References NIL_P, NULL, Qnil, Qundef, rb_encoding, rb_hash_lookup2(), and v.

## ◆ rb_io_extract_modeenc()

void rb_io_extract_modeenc | ( | VALUE * | vmode_p,
|  | VALUE * | vperm_p,
|  | VALUE | opthash,
|  | int * | oflags_p,
|  | int * | fmode_p,
|  | convconfig_t * | convconfig_p
| ) |  |

Definition at line 5871 of file io.c.

References fmode, and rb_encoding.

## ◆ rb_io_fdopen()

VALUE rb_io_fdopen | ( | int | fd,
|  | int | oflags,
|  | const char * | path
| ) |  |

Definition at line 8004 of file io.c.

References klass, path, rb_cFile, rb_cIO, and strcmp().

## ◆ rb_io_flush()

VALUE rb_io_flush | ( | VALUE | io | ) |

Definition at line 1903 of file io.c.

References rb_io_flush_raw().

Referenced by rb_io_getbyte().

## ◆ rb_io_flush_raw()

VALUE rb_io_flush_raw | ( | VALUE | io,
|  | int | sync
| ) |  |

Definition at line 1864 of file io.c.

References rb_funcall, RB_TYPE_P, and T_FILE.

Referenced by rb_io_flush().

## ◆ rb_io_fptr_finalize()

int rb_io_fptr_finalize | ( | rb_io_t * | fptr | ) |

Definition at line 4747 of file io.c.

References finish_writeconv_arg::fptr, and rb_io_fptr_finalize_internal().

## ◆ rb_io_fptr_finalize_internal()

void rb_io_fptr_finalize_internal | ( | void * | ptr | ) |

Definition at line 4730 of file io.c.

References rb_io_t::fd, finish_writeconv_arg::fptr, rb_io_t::pathv, ptr, and Qnil.

Referenced by rb_io_fptr_finalize().

## ◆ rb_io_get_io()

VALUE rb_io_get_io | ( | VALUE | io | ) |

Definition at line 733 of file io.c.

References idTo_io, rb_convert_type_with_id(), and T_FILE.

## ◆ rb_io_get_write_io()

VALUE rb_io_get_write_io | ( | VALUE | io | ) |

Definition at line 745 of file io.c.

## ◆ rb_io_getbyte()

VALUE rb_io_getbyte | ( | VALUE | io | ) |

Definition at line 4215 of file io.c.

References rb_io_t::fd, FMODE_TTY, GetOpenFile, getline_arg::io, rb_io_t::mode, rb_io_check_byte_readable(), rb_io_flush(), rb_stdout, RB_TYPE_P, READ_CHECK, and T_FILE.

## ◆ rb_io_gets()

VALUE rb_io_gets | ( | VALUE | io | ) |

Definition at line 3573 of file io.c.

## ◆ rb_io_gets_internal()

VALUE rb_io_gets_internal | ( | VALUE | io | ) |

Definition at line 3579 of file io.c.

References GetOpenFile, and getline_arg::io.

## ◆ rb_io_make_open_file()

rb_io_t* rb_io_make_open_file | ( | VALUE | obj | ) |

Definition at line 8080 of file io.c.

References Check_Type, obj, rb_io_close(), rb_io_fptr_finalize, RFILE, and T_FILE.

## ◆ rb_io_memsize()

RUBY_FUNC_EXPORTED size_t rb_io_memsize | ( | const rb_io_t * | fptr | ) |

Definition at line 4760 of file io.c.

References rb_io_t::cbuf, finish_writeconv_arg::fptr, rb_econv_memsize(), rb_io_t::rbuf, rb_io_t::readconv, size, rb_io_t::wbuf, and rb_io_t::writeconv.

## ◆ rb_io_modestr_fmode()

int rb_io_modestr_fmode | ( | const char * | modestr | ) |

Definition at line 5465 of file io.c.

References error, fmode, FMODE_APPEND, FMODE_BINMODE, FMODE_CREATE, FMODE_EXCL, FMODE_READABLE, FMODE_READWRITE, FMODE_TEXTMODE, FMODE_TRUNC, FMODE_WRITABLE, NULL, rb_eArgError, rb_raise(), and strchr().

## ◆ rb_io_modestr_oflags()

int rb_io_modestr_oflags | ( | const char * | modestr | ) |

Definition at line 5595 of file io.c.

## ◆ rb_io_oflags_fmode()

int rb_io_oflags_fmode | ( | int | oflags | ) |

Definition at line 5519 of file io.c.

References fmode, FMODE_APPEND, FMODE_BINMODE, FMODE_CREATE, FMODE_EXCL, FMODE_READABLE, FMODE_READWRITE, FMODE_TRUNC, FMODE_WRITABLE, O_ACCMODE, and O_BINARY.

## ◆ rb_io_print()

VALUE rb_io_print | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | out
| ) |  |

Definition at line 7576 of file io.c.

References argc, argv, i, NIL_P, Qnil, rb_io_write(), rb_lastline_get(), rb_output_fs, and rb_output_rs.

## ◆ rb_io_printf()

VALUE rb_io_printf | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | out
| ) |  |

Definition at line 7505 of file io.c.

References argc, argv, Qnil, rb_f_sprintf(), and rb_io_write().

## ◆ rb_io_puts()

VALUE rb_io_puts | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | out
| ) |  |

Definition at line 7747 of file io.c.

References argc, argv, i, n, Qnil, rb_default_rs, rb_exec_recursive(), rb_io_write(), RB_TYPE_P, and T_STRING.

Referenced by rb_f_abort().

## ◆ rb_io_read_check()

void rb_io_read_check | ( | rb_io_t * | fptr | ) |

Definition at line 944 of file io.c.

References rb_io_t::fd, rb_thread_wait_fd(), and READ_DATA_PENDING.

## ◆ rb_io_read_pending()

int rb_io_read_pending | ( | rb_io_t * | fptr | ) |

Definition at line 935 of file io.c.

References READ_CHAR_PENDING, and READ_DATA_PENDING.

## ◆ rb_io_set_nonblock()

void rb_io_set_nonblock | ( | rb_io_t * | fptr | ) |

Definition at line 2782 of file io.c.

Referenced by rsock_s_accept_nonblock().

## ◆ rb_io_set_write_io()

VALUE rb_io_set_write_io | ( | VALUE | io,
|  | VALUE | w
| ) |  |

Definition at line 756 of file io.c.

## ◆ rb_io_stdio_file()

FILE* rb_io_stdio_file | ( | rb_io_t * | fptr | ) |

Definition at line 8032 of file io.c.

References rb_io_t::stdio_file.

## ◆ rb_io_synchronized()

void rb_io_synchronized | ( | rb_io_t * | fptr | ) |

Definition at line 6356 of file io.c.

References FMODE_SYNC, rb_io_t::mode, and rb_io_check_initialized().

Referenced by rb_io_unbuffered(), and rsock_init_sock().

## ◆ rb_io_taint_check()

VALUE rb_io_taint_check | ( | VALUE | io | ) |

Definition at line 703 of file io.c.

References rb_check_frozen.

## ◆ rb_io_unbuffered()

void rb_io_unbuffered | ( | rb_io_t * | fptr | ) |

Definition at line 6363 of file io.c.

References rb_io_synchronized().

## ◆ rb_io_ungetbyte()

VALUE rb_io_ungetbyte | ( | VALUE | io,
|  | VALUE | b
| ) |  |

Definition at line 4276 of file io.c.

References GetOpenFile, INT2FIX, getline_arg::io, NUM2INT, Qnil, rb_int_modulo(), rb_io_check_byte_readable(), rb_str_new, SafeStringValue, T_BIGNUM, T_FIXNUM, T_NIL, TYPE, and v.

## ◆ rb_io_ungetc()

VALUE rb_io_ungetc | ( | VALUE | io,
|  | VALUE | c
| ) |  |

Definition at line 4315 of file io.c.

References FIX2UINT, FIXNUM_P, GetOpenFile, getline_arg::io, len, NIL_P, Qnil, rb_enc_uint_chr(), and rb_io_check_char_readable().

## ◆ rb_io_wait_readable()

int rb_io_wait_readable | ( | int | f | ) |

Definition at line 1204 of file io.c.

## ◆ rb_io_wait_writable()

int rb_io_wait_writable | ( | int | f | ) |

Definition at line 1228 of file io.c.

Referenced by rsock_bsock_send().

## ◆ rb_io_write()

VALUE rb_io_write | ( | VALUE | io,
|  | VALUE | str
| ) |  |

Definition at line 1804 of file io.c.

References rb_funcallv.

Referenced by rb_io_addstr(), rb_io_print(), rb_io_printf(), rb_io_puts(), and rb_parser_printf().

## ◆ rb_maygvl_fd_fix_cloexec()

void rb_maygvl_fd_fix_cloexec | ( | int | fd | ) |

Definition at line 245 of file io.c.

References errno, F_GETFD, F_SETFD, fcntl(), FD_CLOEXEC, rb_bug(), and strerror().

Referenced by rb_cloexec_dup2(), rb_cloexec_fcntl_dupfd(), rb_cloexec_open(), rb_cloexec_pipe(), and rb_fd_fix_cloexec().

## ◆ rb_notify_fd_close()

int rb_notify_fd_close | ( | int | fd,
|  | struct list_head * |
| ) |  |

Definition at line 2364 of file thread.c.

References err, waiting_fd::fd, GET_THREAD, list_add, list_del, list_empty, list_for_each_safe, rb_threadptr_interrupt(), rb_threadptr_pending_interrupt_enque(), ruby_error_stream_closed, rb_vm_struct::special_exceptions, waiting_fd::th, rb_thread_struct::vm, rb_vm_struct::waiting_fds, and waiting_fd::wfd_node.

## ◆ rb_pipe()

int rb_pipe | ( | int * | pipes | ) |

Definition at line 6369 of file io.c.

References errno, rb_cloexec_pipe(), rb_gc_for_fd(), and rb_update_max_fd().

## ◆ rb_readwrite_sys_fail()

void rb_readwrite_sys_fail | ( | enum rb_io_wait_readwrite | writable,
|  | const char * | mesg
| ) |  |

Definition at line 12923 of file io.c.

## ◆ rb_readwrite_syserr_fail()

void rb_readwrite_syserr_fail | ( | enum rb_io_wait_readwrite | writable,
|  | int | n,
|  | const char * | mesg
| ) |  |

Definition at line 12929 of file io.c.

## ◆ rb_stderr_tty_p()

int rb_stderr_tty_p | ( | void |  | ) |

Definition at line 7958 of file io.c.

Referenced by rb_error_write().

## ◆ rb_stdio_set_default_encoding()

void rb_stdio_set_default_encoding | ( | void |  | ) |

Definition at line 11758 of file io.c.

References Qnil.

## ◆ rb_update_max_fd()

void rb_update_max_fd | ( | int | fd | ) |

Definition at line 218 of file io.c.

Referenced by rb_fd_fix_cloexec(), rb_file_load_ok(), rb_pipe(), and rsock_init_sock().

## ◆ rb_write_error()

void rb_write_error | ( | const char * | mesg | ) |

Definition at line 7930 of file io.c.

References rb_write_error2(), and strlen().

## ◆ rb_write_error2()

void rb_write_error2 | ( | const char * | mesg,
|  | long | len
| ) |  |

Definition at line 7911 of file io.c.

Referenced by rb_write_error().

## ◆ rb_write_error_str()

void rb_write_error_str | ( | VALUE | mesg | ) |

Definition at line 7936 of file io.c.

## ◆ ruby_set_inplace_mode()

void ruby_set_inplace_mode | ( | const char * | suffix | ) |

Definition at line 12857 of file io.c.

References ARGF, Qfalse, Qnil, and rb_fstring_cstr.

## Variable Documentation

## ◆ rb_default_rs

VALUE rb_default_rs

Definition at line 190 of file io.c.

Referenced by rb_gets(), rb_io_puts(), and rb_p().

## ◆ rb_output_fs

VALUE rb_output_fs

Definition at line 187 of file io.c.

Referenced by rb_io_print().

## ◆ rb_output_rs

VALUE rb_output_rs

Definition at line 189 of file io.c.

Referenced by rb_io_print().

## ◆ rb_rs

VALUE rb_rs

Definition at line 188 of file io.c.

Referenced by rb_gets().

## ◆ rb_stderr

VALUE rb_stderr

Definition at line 184 of file io.c.

## ◆ rb_stdout

VALUE rb_stdout

Definition at line 184 of file io.c.

Referenced by rb_io_getbyte(), and rb_p().

ECONV_DECORATOR_MASK
#define ECONV_DECORATOR_MASK
Definition: encoding.h:398
next_argv
#define next_argv()
Definition: io.c:8581
ARGF_GENERIC_INPUT_P
#define ARGF_GENERIC_INPUT_P()
Definition: io.c:8582
NULL
#define NULL
Definition: _sdbm.c:101
FMODE_BINMODE
#define FMODE_BINMODE
Definition: io.h:111
rb_ascii8bit_encoding
rb_encoding * rb_ascii8bit_encoding(void)
Definition: encoding.c:1316
ECONV_STATEFUL_DECORATOR_MASK
#define ECONV_STATEFUL_DECORATOR_MASK
Definition: encoding.h:407
FMODE_TEXTMODE
#define FMODE_TEXTMODE
Definition: io.h:120
fmode
#define fmode
argf
Definition: io.c:206
FMODE_EXCL
#define FMODE_EXCL
Definition: io.h:118
READ_DATA_PENDING
#define READ_DATA_PENDING(fptr)
Definition: io.c:466
argv
char ** argv
Definition: ruby.c:223
f
#define f
ARGF_FORWARD
#define ARGF_FORWARD(argc, argv)
Definition: io.c:8584
argc
int argc
Definition: ruby.c:222
NEED_NEWLINE_DECORATOR_ON_WRITE
#define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr)
Definition: io.c:507
Qnil
#define Qnil
Definition: ruby.h:469
MODE_BTMODE
#define MODE_BTMODE(a, b, c)
Definition: io.c:1459