Ruby: include/ruby/io.h File Reference

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

Data Structures | Macros | Typedefs | Enumerations | Functions
io.h File Reference
`#include "ruby/internal/config.h"`
`#include <stdio.h>`
`#include "ruby/encoding.h"`
`#include <errno.h>`
`#include "ruby/internal/dllexport.h"`

Go to the source code of this file.

## Data Structures
struct | rb_io_t
struct | rb_io_t::rb_io_enc_t

## Macros
#define | RB_WAITFD_IN 0x001
#define | RB_WAITFD_PRI 0x002
#define | RB_WAITFD_OUT 0x004
#define | HAVE_RB_IO_T 1
#define | FMODE_READABLE 0x00000001
#define | FMODE_WRITABLE 0x00000002
#define | FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
#define | FMODE_BINMODE 0x00000004
#define | FMODE_SYNC 0x00000008
#define | FMODE_TTY 0x00000010
#define | FMODE_DUPLEX 0x00000020
#define | FMODE_APPEND 0x00000040
#define | FMODE_CREATE 0x00000080
#define | FMODE_EXCL 0x00000400
#define | FMODE_TRUNC 0x00000800
#define | FMODE_TEXTMODE 0x00001000
#define | FMODE_SETENC_BY_BOM 0x00100000
#define | RB_IO_POINTER(obj, fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
#define | GetOpenFile RB_IO_POINTER
#define | RB_IO_OPEN(obj, fp)
#define | MakeOpenFile RB_IO_OPEN
#define | rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]
#define | rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]

## Typedefs
typedef struct rb_io_buffer_t | rb_io_buffer_t
typedef struct rb_io_t | rb_io_t
typedef struct rb_io_enc_t | rb_io_enc_t

## Enumerations
enum | rb_io_event_t { RUBY_IO_READABLE = RB_WAITFD_IN , RUBY_IO_WRITABLE = RB_WAITFD_OUT , RUBY_IO_PRIORITY = RB_WAITFD_PRI }

## Functions
| PACKED_STRUCT_UNALIGNED (struct rb_io_buffer_t { char *ptr;int off;int len;int capa;})
rb_io_t * | rb_io_make_open_file (VALUE obj)
FILE * | rb_io_stdio_file (rb_io_t *fptr)
FILE * | rb_fdopen (int, const char *)
int | rb_io_modestr_fmode (const char *modestr)
int | rb_io_modestr_oflags (const char *modestr)
int | rb_io_oflags_fmode (int oflags)
void | rb_io_check_writable (rb_io_t *)
void | rb_io_check_readable (rb_io_t *)
void | rb_io_check_char_readable (rb_io_t *fptr)
void | rb_io_check_byte_readable (rb_io_t *fptr)
int | rb_io_fptr_finalize (rb_io_t *)
void | rb_io_synchronized (rb_io_t *)
void | rb_io_check_initialized (rb_io_t *)
void | rb_io_check_closed (rb_io_t *)
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_set_nonblock (rb_io_t *fptr)
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, rb_io_enc_t *convconfig_p)
ssize_t | rb_io_bufwrite (VALUE io, const void *buf, size_t size)
int | rb_io_wait_readable (int fd)
int | rb_io_wait_writable (int fd)
int | rb_wait_for_single_fd (int fd, int events, struct timeval *tv)
VALUE | rb_io_wait (VALUE io, VALUE events, VALUE timeout)
VALUE | rb_io_taint_check (VALUE)
void | rb_eof_error (void)
void | rb_io_read_check (rb_io_t *)
int | rb_io_read_pending (rb_io_t *)
VALUE | rb_stat_new (const struct stat *)

## Detailed Description

Author
  $Author$

Date
  Fri Nov 12 16:47:09 JST 1993

Copyright
  Copyright (C) 1993-2007 Yukihiro Matsumoto
  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.

Definition in file io.h.

## Macro Definition Documentation

## ◆ FMODE_APPEND

#define FMODE_APPEND 0x00000040

Definition at line 112 of file io.h.

## ◆ FMODE_BINMODE

#define FMODE_BINMODE 0x00000004

Definition at line 108 of file io.h.

## ◆ FMODE_CREATE

#define FMODE_CREATE 0x00000080

Definition at line 113 of file io.h.

## ◆ FMODE_DUPLEX

#define FMODE_DUPLEX 0x00000020

Definition at line 111 of file io.h.

## ◆ FMODE_EXCL

#define FMODE_EXCL 0x00000400

Definition at line 115 of file io.h.

## ◆ FMODE_READABLE

#define FMODE_READABLE 0x00000001

Definition at line 105 of file io.h.

## ◆ FMODE_READWRITE

#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)

Definition at line 107 of file io.h.

## ◆ FMODE_SETENC_BY_BOM

#define FMODE_SETENC_BY_BOM 0x00100000

Definition at line 119 of file io.h.

## ◆ FMODE_SYNC

#define FMODE_SYNC 0x00000008

Definition at line 109 of file io.h.

## ◆ FMODE_TEXTMODE

#define FMODE_TEXTMODE 0x00001000

Definition at line 117 of file io.h.

## ◆ FMODE_TRUNC

#define FMODE_TRUNC 0x00000800

Definition at line 116 of file io.h.

## ◆ FMODE_TTY

#define FMODE_TTY 0x00000010

Definition at line 110 of file io.h.

## ◆ FMODE_WRITABLE

#define FMODE_WRITABLE 0x00000002

Definition at line 106 of file io.h.

## ◆ GetOpenFile

#define GetOpenFile RB_IO_POINTER

Definition at line 125 of file io.h.

## ◆ HAVE_RB_IO_T

#define HAVE_RB_IO_T 1

Definition at line 103 of file io.h.

## ◆ MakeOpenFile

#define MakeOpenFile RB_IO_OPEN

Definition at line 130 of file io.h.

## ◆ rb_io_mode_flags

#define rb_io_mode_flags | ( |  | modestr | ) | [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]

Definition at line 164 of file io.h.

## ◆ rb_io_modenum_flags

#define rb_io_modenum_flags | ( |  | oflags | ) | [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]

Definition at line 165 of file io.h.

## ◆ RB_IO_OPEN

#define RB_IO_OPEN | ( |  | obj,
|  |  | fp
| ) |  |

Value:
do {\
(fp) = rb_io_make_open_file(obj);\
} while (0)
rb_io_make_open_file
rb_io_t * rb_io_make_open_file(VALUE obj)
Definition: io.c:8278

Definition at line 127 of file io.h.

## ◆ RB_IO_POINTER

#define RB_IO_POINTER | ( |  | obj,
|  |  | fp
| ) |  | rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)

Definition at line 124 of file io.h.

## ◆ RB_WAITFD_IN

#define RB_WAITFD_IN 0x001

Definition at line 39 of file io.h.

## ◆ RB_WAITFD_OUT

#define RB_WAITFD_OUT 0x004

Definition at line 41 of file io.h.

## ◆ RB_WAITFD_PRI

#define RB_WAITFD_PRI 0x002

Definition at line 40 of file io.h.

## Typedef Documentation

## ◆ rb_io_buffer_t

typedef struct rb_io_buffer_t rb_io_buffer_t

Definition at line 59 of file io.h.

## ◆ rb_io_enc_t

typedef struct rb_io_enc_t rb_io_enc_t

Definition at line 101 of file io.h.

## ◆ rb_io_t

typedef struct rb_io_t rb_io_t

## Enumeration Type Documentation

## ◆ rb_io_event_t

enum rb_io_event_t

Enumerator
RUBY_IO_READABLE |
RUBY_IO_WRITABLE |
RUBY_IO_PRIORITY |

Definition at line 44 of file io.h.

## Function Documentation

## ◆ PACKED_STRUCT_UNALIGNED()

PACKED_STRUCT_UNALIGNED | ( | struct rb_io_buffer_t { char *ptr;int off;int len;int capa;} |  | ) |

References len, and ptr.

## ◆ rb_eof_error()

void rb_eof_error | ( | void |  | ) |

Definition at line 754 of file io.c.

References rb_eEOFError, and rb_raise().

## ◆ rb_fdopen()

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

Definition at line 6183 of file io.c.

References fdopen, NULL, rb_gc(), rb_gc_for_fd(), rb_syserr_fail(), and rb_warn().

Referenced by rb_io_stdio_file().

## ◆ rb_io_bufwrite()

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

Definition at line 1698 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 947 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 928 of file io.c.

References FMODE_READABLE, GetOpenFile, rb_io_t::mode, rb_eIOError, rb_io_check_closed(), rb_raise(), rb_sys_fail_on_write, rb_io_t::tied_io_for_writing, 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 775 of file io.c.

References rb_io_t::fd, and rb_io_check_initialized().

Referenced by rb_io_check_char_readable(), rb_io_check_writable(), rb_io_wait(), rsock_s_recvfrom(), and rsock_s_recvfrom_nonblock().

## ◆ rb_io_check_initialized()

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

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

References 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 956 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 980 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_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 5862 of file io.c.

References NIL_P, NULL, PRIsVALUE, Qnil, Qundef, rb_check_string_type(), rb_enc_from_encoding(), rb_enc_from_index(), rb_enc_get(), rb_hash_lookup2(), rb_to_encoding(), rb_to_encoding_index(), rb_warn(), ruby_verbose, and StringValueCStr.

Referenced by rb_io_extract_modeenc().

## ◆ rb_io_extract_modeenc()

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

Definition at line 5989 of file io.c.

References DEFAULT_TEXTMODE, ECONV_DEFAULT_NEWLINE_DECORATOR, ECONV_UNIVERSAL_NEWLINE_DECORATOR, fmode, FMODE_BINMODE, FMODE_READABLE, FMODE_WRITABLE, INT2NUM, MODE_BTMODE, NIL_P, NULL, NUM2INT, O_BINARY, Qnil, rb_ascii8bit_encoding(), rb_check_to_integer(), rb_eArgError, rb_econv_prepare_options(), rb_enc_get(), rb_hash_aref(), rb_io_extract_encoding_option(), rb_io_modestr_fmode(), rb_io_oflags_fmode(), rb_raise(), rb_to_int(), SafeStringValue, SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2, strchr(), and StringValueCStr.

## ◆ rb_io_fptr_finalize()

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

Definition at line 4862 of file io.c.

References finish_writeconv_arg::fptr, and rb_io_fptr_finalize_internal().

## ◆ rb_io_get_io()

VALUE rb_io_get_io | ( | VALUE | io | ) |

Definition at line 790 of file io.c.

## ◆ rb_io_get_write_io()

VALUE rb_io_get_write_io | ( | VALUE | io | ) |

Definition at line 802 of file io.c.

References rb_io_t::tied_io_for_writing.

## ◆ rb_io_make_open_file()

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

Definition at line 8278 of file io.c.

References rb_io_close(), rb_io_fptr_finalize, RFILE, rb_io_t::self, and T_FILE.

## ◆ rb_io_modestr_fmode()

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

Definition at line 5580 of file io.c.

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

Referenced by rb_io_extract_modeenc(), and rb_io_modestr_oflags().

## ◆ rb_io_modestr_oflags()

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

Definition at line 5713 of file io.c.

References rb_io_modestr_fmode().

## ◆ rb_io_oflags_fmode()

int rb_io_oflags_fmode | ( | int | oflags | ) |

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

Referenced by rb_io_extract_modeenc(), and rb_io_fdopen().

## ◆ rb_io_read_check()

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

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

References READ_CHAR_PENDING, and READ_DATA_PENDING.

Referenced by rsock_s_recvfrom(), and rsock_s_recvfrom_nonblock().

## ◆ rb_io_set_nonblock()

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

Definition at line 2942 of file io.c.

References rb_io_t::fd, rb_io_t::pathv, and rb_sys_fail_path.

Referenced by rsock_s_accept_nonblock(), and rsock_s_recvfrom_nonblock().

## ◆ rb_io_set_write_io()

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

Definition at line 813 of file io.c.

References GetWriteIO, Qnil, RTEST, and rb_io_t::tied_io_for_writing.

## ◆ rb_io_stdio_file()

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

Definition at line 8229 of file io.c.

References rb_io_t::fd, rb_io_t::mode, rb_fdopen(), and rb_io_t::stdio_file.

## ◆ rb_io_synchronized()

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

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

References rb_check_frozen.

## ◆ rb_io_wait()

VALUE rb_io_wait | ( | VALUE | io,
|  | VALUE | events,
|  | VALUE | timeout
| ) |  |

Definition at line 1265 of file io.c.

References rb_io_t::fd, NULL, Qfalse, Qnil, RB_INT2NUM, rb_io_check_closed(), RB_IO_POINTER, RB_NUM2INT, rb_scheduler_current(), rb_scheduler_io_wait(), rb_sys_fail(), rb_thread_wait_for_single_fd(), and rb_time_interval().

## ◆ rb_io_wait_readable()

int rb_io_wait_readable | ( | int | fd | ) |

Definition at line 1307 of file io.c.

References EWOULDBLOCK, f, FALSE, Qnil, rb_scheduler_current(), rb_scheduler_io_wait_readable(), rb_thread_check_ints(), rb_thread_wait_fd(), RTEST, and TRUE.

Referenced by rsock_s_accept(), and rsock_s_recvfrom().

## ◆ rb_io_wait_writable()

int rb_io_wait_writable | ( | int | fd | ) |

Definition at line 1341 of file io.c.

References EWOULDBLOCK, f, FALSE, Qnil, rb_scheduler_current(), rb_scheduler_io_wait_writable(), rb_thread_check_ints(), rb_thread_fd_writable(), RTEST, and TRUE.

Referenced by rsock_bsock_send().

## ◆ rb_stat_new()

VALUE rb_stat_new | ( | const struct stat * | st | ) |

Definition at line 547 of file file.c.

References rb_cStat.

## ◆ rb_wait_for_single_fd()

int rb_wait_for_single_fd | ( | int | fd,
|  | int | events,
|  | struct timeval * | tv
| ) |  |

Definition at line 1384 of file io.c.

References Qnil, RB_INT2NUM, rb_scheduler_current(), rb_scheduler_io_wait(), rb_scheduler_timeout(), rb_thread_wait_for_single_fd(), and RTEST.