Ruby: include/ruby/internal/intern/io.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions | Variables
io.h File Reference

Public APIs related to rb_cIO. More...

`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`

Go to the source code of this file.

## Macros
#define | rb_defout rb_stdout
#define | RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)

## Functions
VALUE | rb_io_write (VALUE, VALUE)
VALUE | rb_io_gets (VALUE)
VALUE | rb_io_getbyte (VALUE)
VALUE | rb_io_ungetc (VALUE, VALUE)
VALUE | rb_io_ungetbyte (VALUE, VALUE)
VALUE | rb_io_close (VALUE)
VALUE | rb_io_flush (VALUE)
VALUE | rb_io_eof (VALUE)
VALUE | rb_io_binmode (VALUE)
VALUE | rb_io_ascii8bit_binmode (VALUE)
VALUE | rb_io_addstr (VALUE, VALUE)
VALUE | rb_io_printf (int, const VALUE *, VALUE)
VALUE | rb_io_print (int, const VALUE *, VALUE)
VALUE | rb_io_puts (int, const VALUE *, VALUE)
VALUE | rb_io_fdopen (int, int, const char *)
VALUE | rb_io_get_io (VALUE)
VALUE | rb_file_open (const char *, const char *)
VALUE | rb_file_open_str (VALUE, const char *)
VALUE | rb_gets (void)
void | rb_write_error (const char *)
void | rb_write_error2 (const char *, long)
void | rb_close_before_exec (int lowfd, int maxhint, VALUE noclose_fds)
int | rb_pipe (int *pipes)
int | rb_reserved_fd_p (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_update_max_fd (int fd)
void | rb_fd_fix_cloexec (int fd)

## Variables
VALUE | rb_fs
VALUE | rb_output_fs
VALUE | rb_rs
VALUE | rb_default_rs
VALUE | rb_output_rs

## Detailed Description

Public APIs related to rb_cIO.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file io.h.

## Macro Definition Documentation

## ◆ rb_defout

#define rb_defout rb_stdout

Definition at line 29 of file io.h.

## ◆ RB_RESERVED_FD_P

#define RB_RESERVED_FD_P | ( |  | fd | ) | rb_reserved_fd_p(fd)

Definition at line 64 of file io.h.

## Function Documentation

## ◆ rb_cloexec_dup()

int rb_cloexec_dup | ( | int | oldfd | ) |

Definition at line 346 of file io.c.

References rb_cloexec_fcntl_dupfd().

## ◆ rb_cloexec_dup2()

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

Definition at line 353 of file io.c.

References dup2(), O_CLOEXEC, and rb_maygvl_fd_fix_cloexec().

## ◆ rb_cloexec_fcntl_dupfd()

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

Definition at line 440 of file io.c.

References 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 307 of file io.c.

References EWOULDBLOCK, 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 406 of file io.c.

References O_CLOEXEC, O_NONBLOCK, and rb_maygvl_fd_fix_cloexec().

Referenced by rb_pipe().

## ◆ rb_close_before_exec()

void rb_close_before_exec | ( | int | lowfd,
|  | int | maxhint,
|  | VALUE | noclose_fds
| ) |  |

Referenced by rb_execarg_run_options().

## ◆ rb_fd_fix_cloexec()

void rb_fd_fix_cloexec | ( | int | fd | ) |

Definition at line 283 of file io.c.

References rb_maygvl_fd_fix_cloexec(), and rb_update_max_fd().

## ◆ rb_file_open()

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

Definition at line 6389 of file io.c.

References sysopen_struct::fname, rb_cFile, and rb_str_new_cstr.

## ◆ rb_file_open_str()

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

Definition at line 6382 of file io.c.

References FilePathValue, sysopen_struct::fname, and rb_cFile.

## ◆ rb_gets()

VALUE rb_gets | ( | void |  | ) |

Definition at line 9104 of file io.c.

References ARGF, next_argv, NIL_P, Qnil, rb_default_rs, rb_io_close(), rb_io_gets(), rb_lastline_set(), and rb_rs.

## ◆ rb_io_addstr()

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

Definition at line 1992 of file io.c.

References rb_io_write(), and str.

Referenced by Init_IO().

## ◆ rb_io_ascii8bit_binmode()

VALUE rb_io_ascii8bit_binmode | ( | VALUE | io | ) |

Definition at line 5495 of file io.c.

References GetOpenFile.

Referenced by rsock_init_sock().

## ◆ rb_io_binmode()

VALUE rb_io_binmode | ( | VALUE | io | ) |

Definition at line 5449 of file io.c.

References rb_io_t::fd, FMODE_BINMODE, 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_close()

VALUE rb_io_close | ( | VALUE | io | ) |

Definition at line 4935 of file io.c.

References Qnil.

Referenced by rb_gets(), and rb_io_make_open_file().

## ◆ rb_io_eof()

VALUE rb_io_eof | ( | VALUE | io | ) |

Definition at line 2298 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.

Referenced by Init_IO().

## ◆ rb_io_fdopen()

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

Definition at line 8183 of file io.c.

References rb_cFile, rb_cIO, and rb_io_oflags_fmode().

## ◆ rb_io_flush()

VALUE rb_io_flush | ( | VALUE | io | ) |

Definition at line 2052 of file io.c.

References rb_io_flush_raw().

Referenced by Init_IO(), and rb_io_getbyte().

## ◆ rb_io_get_io()

VALUE rb_io_get_io | ( | VALUE | io | ) |

Definition at line 790 of file io.c.

References rb_convert_type_with_id(), and T_FILE.

## ◆ rb_io_getbyte()

VALUE rb_io_getbyte | ( | VALUE | io | ) |

Definition at line 4331 of file io.c.

References rb_io_t::fd, FMODE_TTY, GetOpenFile, INT2FIX, getline_arg::io, rb_io_t::mode, Qnil, rb_io_check_byte_readable(), rb_io_flush(), rb_ractor_stdout(), rb_io_t::rbuf, READ_CHECK, and T_FILE.

Referenced by Init_IO().

## ◆ rb_io_gets()

VALUE rb_io_gets | ( | VALUE | io | ) |

Definition at line 3738 of file io.c.

References FALSE, getline_arg::io, and rb_default_rs.

Referenced by rb_gets().

## ◆ rb_io_print()

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

Definition at line 7720 of file io.c.

References argc, argv, NIL_P, out, Qnil, rb_category_warn, rb_io_write(), rb_lastline_get(), rb_output_fs, rb_output_rs, and RB_WARN_CATEGORY_DEPRECATED.

Referenced by Init_IO().

## ◆ rb_io_printf()

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

Definition at line 7649 of file io.c.

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

Referenced by Init_IO().

## ◆ rb_io_puts()

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

Definition at line 7895 of file io.c.

References argc, argv, out, Qnil, rb_default_rs, rb_exec_recursive(), rb_io_write(), rb_obj_as_string(), rb_str_end_with_asciichar(), RSTRING_LEN, and T_STRING.

Referenced by Init_IO(), and rb_f_abort().

## ◆ rb_io_ungetbyte()

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

Definition at line 4393 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, and TYPE.

Referenced by Init_IO().

## ◆ rb_io_ungetc()

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

Definition at line 4432 of file io.c.

References rb_io_t::cbuf, FIX2UINT, FIXNUM_P, GetOpenFile, int(), getline_arg::io, len, MEMMOVE, NEED_NEWLINE_DECORATOR_ON_READ_CHECK, NEED_READCONV, NUM2UINT, Qnil, rb_eIOError, rb_enc_uint_chr(), rb_io_check_char_readable(), rb_raise(), RSTRING_LEN, RSTRING_PTR, SafeStringValue, SET_BINARY_MODE, and T_BIGNUM.

Referenced by Init_IO().

## ◆ rb_io_write()

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

Definition at line 1953 of file io.c.

References rb_funcallv, and str.

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

## ◆ rb_pipe()

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

Definition at line 6499 of file io.c.

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

## ◆ rb_reserved_fd_p()

int rb_reserved_fd_p | ( | int | fd | ) |

Referenced by rsock_init_sock().

## ◆ rb_update_max_fd()

void rb_update_max_fd | ( | int | fd | ) |

Definition at line 233 of file io.c.

References ATOMIC_CAS, err, fcntl(), fstat, rb_bug(), and stat.

Referenced by rb_fd_fix_cloexec(), rb_file_load_ok(), rb_pipe(), rsock_init_sock(), rsock_s_accept(), rsock_s_accept_nonblock(), and rsock_socket().

## ◆ rb_write_error()

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

Definition at line 8077 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 8058 of file io.c.

References fileno, len, rb_io_write(), rb_ractor_stderr(), rb_str_new, and rb_w32_write_console().

Referenced by rb_write_error().

## Variable Documentation

## ◆ rb_default_rs

VALUE rb_default_rs
| extern

Definition at line 202 of file io.c.

Referenced by Init_IO(), rb_gets(), rb_io_gets(), rb_io_gets_internal(), and rb_io_puts().

## ◆ rb_fs

VALUE rb_fs
| extern

Definition at line 502 of file string.c.

Referenced by Init_String().

## ◆ rb_output_fs

VALUE rb_output_fs
| extern

Definition at line 199 of file io.c.

Referenced by Init_IO(), and rb_io_print().

## ◆ rb_output_rs

VALUE rb_output_rs
| extern

Definition at line 201 of file io.c.

Referenced by Init_IO(), and rb_io_print().

## ◆ rb_rs

VALUE rb_rs
| extern

Definition at line 200 of file io.c.

Referenced by Init_IO(), and rb_gets().