Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby32/include/ruby
File: io.h
#ifndef RUBY_IO_H /*-*-C++-*-vi:se ft=cpp:*/
[0] Fix | Delete
#define RUBY_IO_H 1
[1] Fix | Delete
/**
[2] Fix | Delete
* @file
[3] Fix | Delete
* @author $Author$
[4] Fix | Delete
* @date Fri Nov 12 16:47:09 JST 1993
[5] Fix | Delete
* @copyright Copyright (C) 1993-2007 Yukihiro Matsumoto
[6] Fix | Delete
* @copyright This file is a part of the programming language Ruby.
[7] Fix | Delete
* Permission is hereby granted, to either redistribute and/or
[8] Fix | Delete
* modify this file, provided that the conditions mentioned in the
[9] Fix | Delete
* file COPYING are met. Consult the file for details.
[10] Fix | Delete
*/
[11] Fix | Delete
#include "ruby/internal/config.h"
[12] Fix | Delete
[13] Fix | Delete
#include <stdio.h>
[14] Fix | Delete
#include "ruby/encoding.h"
[15] Fix | Delete
[16] Fix | Delete
#if defined(HAVE_STDIO_EXT_H)
[17] Fix | Delete
#include <stdio_ext.h>
[18] Fix | Delete
#endif
[19] Fix | Delete
[20] Fix | Delete
#include <errno.h>
[21] Fix | Delete
[22] Fix | Delete
/** @cond INTERNAL_MACRO */
[23] Fix | Delete
#if defined(HAVE_POLL)
[24] Fix | Delete
# ifdef _AIX
[25] Fix | Delete
# define reqevents events
[26] Fix | Delete
# define rtnevents revents
[27] Fix | Delete
# endif
[28] Fix | Delete
# include <poll.h>
[29] Fix | Delete
# ifdef _AIX
[30] Fix | Delete
# undef reqevents
[31] Fix | Delete
# undef rtnevents
[32] Fix | Delete
# undef events
[33] Fix | Delete
# undef revents
[34] Fix | Delete
# endif
[35] Fix | Delete
# define RB_WAITFD_IN POLLIN
[36] Fix | Delete
# if defined(POLLPRI)
[37] Fix | Delete
# define RB_WAITFD_PRI POLLPRI
[38] Fix | Delete
# else
[39] Fix | Delete
# define RB_WAITFD_PRI 0
[40] Fix | Delete
# endif
[41] Fix | Delete
# define RB_WAITFD_OUT POLLOUT
[42] Fix | Delete
#else
[43] Fix | Delete
# define RB_WAITFD_IN 0x001
[44] Fix | Delete
# define RB_WAITFD_PRI 0x002
[45] Fix | Delete
# define RB_WAITFD_OUT 0x004
[46] Fix | Delete
#endif
[47] Fix | Delete
/** @endcond */
[48] Fix | Delete
[49] Fix | Delete
#include "ruby/internal/attr/const.h"
[50] Fix | Delete
#include "ruby/internal/attr/pure.h"
[51] Fix | Delete
#include "ruby/internal/attr/noreturn.h"
[52] Fix | Delete
#include "ruby/internal/dllexport.h"
[53] Fix | Delete
#include "ruby/internal/value.h"
[54] Fix | Delete
#include "ruby/backward/2/attributes.h" /* PACKED_STRUCT_UNALIGNED */
[55] Fix | Delete
[56] Fix | Delete
// IO#wait, IO#wait_readable, IO#wait_writable, IO#wait_priority are defined by this implementation.
[57] Fix | Delete
#define RUBY_IO_WAIT_METHODS
[58] Fix | Delete
[59] Fix | Delete
// Used as the default timeout argument to `rb_io_wait` to use the `IO#timeout` value.
[60] Fix | Delete
#define RUBY_IO_TIMEOUT_DEFAULT Qnil
[61] Fix | Delete
[62] Fix | Delete
RBIMPL_SYMBOL_EXPORT_BEGIN()
[63] Fix | Delete
[64] Fix | Delete
struct stat;
[65] Fix | Delete
struct timeval;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Indicates that a timeout has occurred while performing an IO operation.
[69] Fix | Delete
*/
[70] Fix | Delete
RUBY_EXTERN VALUE rb_eIOTimeoutError;
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Type of events that an IO can wait.
[74] Fix | Delete
*
[75] Fix | Delete
* @internal
[76] Fix | Delete
*
[77] Fix | Delete
* This is visible from extension libraries because `io/wait` wants it.
[78] Fix | Delete
*/
[79] Fix | Delete
typedef enum {
[80] Fix | Delete
RUBY_IO_READABLE = RB_WAITFD_IN, /**< `IO::READABLE` */
[81] Fix | Delete
RUBY_IO_WRITABLE = RB_WAITFD_OUT, /**< `IO::WRITABLE` */
[82] Fix | Delete
RUBY_IO_PRIORITY = RB_WAITFD_PRI, /**< `IO::PRIORITY` */
[83] Fix | Delete
} rb_io_event_t;
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* IO buffers. This is an implementation detail of ::rb_io_t::wbuf and
[87] Fix | Delete
* ::rb_io_t::rbuf. People don't manipulate it directly.
[88] Fix | Delete
*/
[89] Fix | Delete
PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t {
[90] Fix | Delete
[91] Fix | Delete
/** Pointer to the underlying memory region, of at least `capa` bytes. */
[92] Fix | Delete
char *ptr; /* off + len <= capa */
[93] Fix | Delete
[94] Fix | Delete
/** Offset inside of `ptr`. */
[95] Fix | Delete
int off;
[96] Fix | Delete
[97] Fix | Delete
/** Length of the buffer. */
[98] Fix | Delete
int len;
[99] Fix | Delete
[100] Fix | Delete
/** Designed capacity of the buffer. */
[101] Fix | Delete
int capa;
[102] Fix | Delete
});
[103] Fix | Delete
[104] Fix | Delete
/** @alias{rb_io_buffer_t} */
[105] Fix | Delete
typedef struct rb_io_buffer_t rb_io_buffer_t;
[106] Fix | Delete
[107] Fix | Delete
/** Decomposed encoding flags (e.g. `"enc:enc2""`). */
[108] Fix | Delete
/*
[109] Fix | Delete
* enc enc2 read action write action
[110] Fix | Delete
* NULL NULL force_encoding(default_external) write the byte sequence of str
[111] Fix | Delete
* e1 NULL force_encoding(e1) convert str.encoding to e1
[112] Fix | Delete
* e1 e2 convert from e2 to e1 convert str.encoding to e2
[113] Fix | Delete
*/
[114] Fix | Delete
struct rb_io_enc_t {
[115] Fix | Delete
/** Internal encoding. */
[116] Fix | Delete
rb_encoding *enc;
[117] Fix | Delete
/** External encoding. */
[118] Fix | Delete
rb_encoding *enc2;
[119] Fix | Delete
/**
[120] Fix | Delete
* Flags.
[121] Fix | Delete
*
[122] Fix | Delete
* @see enum ::ruby_econv_flag_type
[123] Fix | Delete
*/
[124] Fix | Delete
int ecflags;
[125] Fix | Delete
/**
[126] Fix | Delete
* Flags as Ruby hash.
[127] Fix | Delete
*
[128] Fix | Delete
* @internal
[129] Fix | Delete
*
[130] Fix | Delete
* This is set. But used from nowhere maybe?
[131] Fix | Delete
*/
[132] Fix | Delete
VALUE ecopts;
[133] Fix | Delete
};
[134] Fix | Delete
[135] Fix | Delete
/** Ruby's IO, metadata and buffers. */
[136] Fix | Delete
typedef struct rb_io_t {
[137] Fix | Delete
[138] Fix | Delete
/** The IO's Ruby level counterpart. */
[139] Fix | Delete
VALUE self;
[140] Fix | Delete
[141] Fix | Delete
/** stdio ptr for read/write, if available. */
[142] Fix | Delete
FILE *stdio_file;
[143] Fix | Delete
[144] Fix | Delete
/** file descriptor. */
[145] Fix | Delete
int fd;
[146] Fix | Delete
[147] Fix | Delete
/** mode flags: FMODE_XXXs */
[148] Fix | Delete
int mode;
[149] Fix | Delete
[150] Fix | Delete
/** child's pid (for pipes) */
[151] Fix | Delete
rb_pid_t pid;
[152] Fix | Delete
[153] Fix | Delete
/** number of lines read */
[154] Fix | Delete
int lineno;
[155] Fix | Delete
[156] Fix | Delete
/** pathname for file */
[157] Fix | Delete
VALUE pathv;
[158] Fix | Delete
[159] Fix | Delete
/** finalize proc */
[160] Fix | Delete
void (*finalize)(struct rb_io_t*,int);
[161] Fix | Delete
[162] Fix | Delete
/** Write buffer. */
[163] Fix | Delete
rb_io_buffer_t wbuf;
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* (Byte) read buffer. Note also that there is a field called
[167] Fix | Delete
* ::rb_io_t::cbuf, which also concerns read IO.
[168] Fix | Delete
*/
[169] Fix | Delete
rb_io_buffer_t rbuf;
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Duplex IO object, if set.
[173] Fix | Delete
*
[174] Fix | Delete
* @see rb_io_set_write_io()
[175] Fix | Delete
*/
[176] Fix | Delete
VALUE tied_io_for_writing;
[177] Fix | Delete
[178] Fix | Delete
struct rb_io_enc_t encs; /**< Decomposed encoding flags. */
[179] Fix | Delete
[180] Fix | Delete
/** Encoding converter used when reading from this IO. */
[181] Fix | Delete
rb_econv_t *readconv;
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* rb_io_ungetc() destination. This buffer is read before checking
[185] Fix | Delete
* ::rb_io_t::rbuf
[186] Fix | Delete
*/
[187] Fix | Delete
rb_io_buffer_t cbuf;
[188] Fix | Delete
[189] Fix | Delete
/** Encoding converter used when writing to this IO. */
[190] Fix | Delete
rb_econv_t *writeconv;
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* This is, when set, an instance of ::rb_cString which holds the "common"
[194] Fix | Delete
* encoding. Write conversion can convert strings twice... In case
[195] Fix | Delete
* conversion from encoding X to encoding Y does not exist, Ruby finds an
[196] Fix | Delete
* encoding Z that bridges the two, so that X to Z to Y conversion happens.
[197] Fix | Delete
*/
[198] Fix | Delete
VALUE writeconv_asciicompat;
[199] Fix | Delete
[200] Fix | Delete
/** Whether ::rb_io_t::writeconv is already set up. */
[201] Fix | Delete
int writeconv_initialized;
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Value of ::rb_io_t::rb_io_enc_t::ecflags stored right before
[205] Fix | Delete
* initialising ::rb_io_t::writeconv.
[206] Fix | Delete
*/
[207] Fix | Delete
int writeconv_pre_ecflags;
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Value of ::rb_io_t::rb_io_enc_t::ecopts stored right before initialising
[211] Fix | Delete
* ::rb_io_t::writeconv.
[212] Fix | Delete
*/
[213] Fix | Delete
VALUE writeconv_pre_ecopts;
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* This is a Ruby level mutex. It avoids multiple threads to write to an
[217] Fix | Delete
* IO at once; helps for instance rb_io_puts() to ensure newlines right
[218] Fix | Delete
* next to its arguments.
[219] Fix | Delete
*
[220] Fix | Delete
* This of course doesn't help inter-process IO interleaves, though.
[221] Fix | Delete
*/
[222] Fix | Delete
VALUE write_lock;
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* The timeout associated with this IO when performing blocking operations.
[226] Fix | Delete
*/
[227] Fix | Delete
VALUE timeout;
[228] Fix | Delete
} rb_io_t;
[229] Fix | Delete
[230] Fix | Delete
/** @alias{rb_io_enc_t} */
[231] Fix | Delete
typedef struct rb_io_enc_t rb_io_enc_t;
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* @private
[235] Fix | Delete
*
[236] Fix | Delete
* @deprecated This macro once was a thing in the old days, but makes no sense
[237] Fix | Delete
* any longer today. Exists here for backwards compatibility
[238] Fix | Delete
* only. You can safely forget about it.
[239] Fix | Delete
*/
[240] Fix | Delete
#define HAVE_RB_IO_T 1
[241] Fix | Delete
[242] Fix | Delete
/**
[243] Fix | Delete
* @name Possible flags for ::rb_io_t::mode
[244] Fix | Delete
*
[245] Fix | Delete
* @{
[246] Fix | Delete
*/
[247] Fix | Delete
[248] Fix | Delete
/** The IO is opened for reading. */
[249] Fix | Delete
#define FMODE_READABLE 0x00000001
[250] Fix | Delete
[251] Fix | Delete
/** The IO is opened for writing. */
[252] Fix | Delete
#define FMODE_WRITABLE 0x00000002
[253] Fix | Delete
[254] Fix | Delete
/** The IO is opened for both read/write. */
[255] Fix | Delete
#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* The IO is in "binary mode". This is not what everything rb_io_binmode()
[259] Fix | Delete
* concerns. This low-level flag is to stop CR <-> CRLF conversions that would
[260] Fix | Delete
* happen in the underlying operating system.
[261] Fix | Delete
*
[262] Fix | Delete
* Setting this one and #FMODE_TEXTMODE at the same time is a contradiction.
[263] Fix | Delete
* Setting this one and #ECONV_NEWLINE_DECORATOR_MASK at the same time is also
[264] Fix | Delete
* a contradiction.
[265] Fix | Delete
*/
[266] Fix | Delete
#define FMODE_BINMODE 0x00000004
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* The IO is in "sync mode". All output is immediately flushed to the
[270] Fix | Delete
* underlying operating system then. Can be set via rb_io_synchronized(), but
[271] Fix | Delete
* there is no way except calling `IO#sync=` to reset.
[272] Fix | Delete
*/
[273] Fix | Delete
#define FMODE_SYNC 0x00000008
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* The IO is a TTY. What is a TTY and what isn't depends on the underlying
[277] Fix | Delete
* operating system's `isatty(3)` output. You cannot change this.
[278] Fix | Delete
*/
[279] Fix | Delete
#define FMODE_TTY 0x00000010
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Ruby eventually detects that the IO is bidirectional. For instance a TTY
[283] Fix | Delete
* has such property. There are several other things known to be duplexed.
[284] Fix | Delete
* Additionally you (extension library authors) can also implement your own
[285] Fix | Delete
* bidirectional IO subclasses. One of such example is `Socket`.
[286] Fix | Delete
*/
[287] Fix | Delete
#define FMODE_DUPLEX 0x00000020
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* The IO is opened for appending. This mode always writes at the end of the
[291] Fix | Delete
* IO. Ruby manages this flag for record but basically the logic behind this
[292] Fix | Delete
* mode is at the underlying operating system. We almost do nothing.
[293] Fix | Delete
*/
[294] Fix | Delete
#define FMODE_APPEND 0x00000040
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* The IO is opened for creating. This makes sense only when the destination
[298] Fix | Delete
* file does not exist at the time the IO object was created. This is the
[299] Fix | Delete
* default mode for writing, but you can pass `"r+"` to `IO.open` etc., to
[300] Fix | Delete
* reroute this creation.
[301] Fix | Delete
*/
[302] Fix | Delete
#define FMODE_CREATE 0x00000080
[303] Fix | Delete
/* #define FMODE_NOREVLOOKUP 0x00000100 */
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* This flag amends the effect of #FMODE_CREATE, so that if there already is a
[307] Fix | Delete
* file at the given path the operation fails. Using this you can be sure that
[308] Fix | Delete
* the file you get is a fresh new one.
[309] Fix | Delete
*/
[310] Fix | Delete
#define FMODE_EXCL 0x00000400
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* This flag amends the effect of #FMODE_CREATE, so that if there already is a
[314] Fix | Delete
* file at the given path it gets truncated.
[315] Fix | Delete
*/
[316] Fix | Delete
#define FMODE_TRUNC 0x00000800
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* The IO is in "text mode". On systems where such mode make sense, this flag
[320] Fix | Delete
* changes the way the IO handles the contents. On POSIX systems it is
[321] Fix | Delete
* basically a no-op, but with this flag set you can optionally let Ruby
[322] Fix | Delete
* manually convert newlines, unlike when in binary mode:
[323] Fix | Delete
*
[324] Fix | Delete
* ```ruby
[325] Fix | Delete
* IO.open("/p/a/t/h", "wt", crlf_newline: true) # "wb" is NG.
[326] Fix | Delete
* ```
[327] Fix | Delete
*
[328] Fix | Delete
* Setting this one and #FMODE_BINMODE at the same time is a contradiction.
[329] Fix | Delete
*/
[330] Fix | Delete
#define FMODE_TEXTMODE 0x00001000
[331] Fix | Delete
/* #define FMODE_PREP 0x00010000 */
[332] Fix | Delete
/* #define FMODE_SIGNAL_ON_EPIPE 0x00020000 */
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* This flag amends the encoding of the IO so that the BOM of the contents of
[336] Fix | Delete
* the IO takes effect.
[337] Fix | Delete
*/
[338] Fix | Delete
#define FMODE_SETENC_BY_BOM 0x00100000
[339] Fix | Delete
/* #define FMODE_UNIX 0x00200000 */
[340] Fix | Delete
/* #define FMODE_INET 0x00400000 */
[341] Fix | Delete
/* #define FMODE_INET6 0x00800000 */
[342] Fix | Delete
[343] Fix | Delete
/** @} */
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* Queries the underlying IO pointer.
[347] Fix | Delete
*
[348] Fix | Delete
* @param[in] obj An IO object.
[349] Fix | Delete
* @param[out] fp A variable of type ::rb_io_t.
[350] Fix | Delete
* @exception rb_eFrozenError `obj` is frozen.
[351] Fix | Delete
* @exception rb_eIOError `obj` is closed.
[352] Fix | Delete
* @post `fp` holds `obj`'s underlying IO.
[353] Fix | Delete
*/
[354] Fix | Delete
#define RB_IO_POINTER(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* This is an old name of #RB_IO_POINTER. Not sure if we want to deprecate
[358] Fix | Delete
* this macro. There still are tons of usages out there in the wild.
[359] Fix | Delete
*/
[360] Fix | Delete
#define GetOpenFile RB_IO_POINTER
[361] Fix | Delete
[362] Fix | Delete
/**
[363] Fix | Delete
* Fills an IO object. This makes the best sense when called from inside of an
[364] Fix | Delete
* `#initialize` method of a 3rd party extension library that inherits
[365] Fix | Delete
* ::rb_cIO.
[366] Fix | Delete
*
[367] Fix | Delete
* If the passed IO is already opened for something it first closes that and
[368] Fix | Delete
* opens a new one instead.
[369] Fix | Delete
*
[370] Fix | Delete
* @param[out] obj An IO object to fill in.
[371] Fix | Delete
* @param[out] fp A variable of type ::rb_io_t.
[372] Fix | Delete
* @exception rb_eTypeError `obj` is not ::RUBY_T_FILE.
[373] Fix | Delete
* @post `fp` holds `obj`'s underlying IO.
[374] Fix | Delete
*/
[375] Fix | Delete
#define RB_IO_OPEN(obj, fp) do {\
[376] Fix | Delete
(fp) = rb_io_make_open_file(obj);\
[377] Fix | Delete
} while (0)
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* This is an old name of #RB_IO_OPEN. Not sure if we want to deprecate this
[381] Fix | Delete
* macro. There still are usages out there in the wild.
[382] Fix | Delete
*/
[383] Fix | Delete
#define MakeOpenFile RB_IO_OPEN
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* @private
[387] Fix | Delete
*
[388] Fix | Delete
* This is an implementation detail of #RB_IO_OPEN. People don't use it
[389] Fix | Delete
* directly.
[390] Fix | Delete
*
[391] Fix | Delete
* @param[out] obj An IO object to fill in.
[392] Fix | Delete
* @exception rb_eTypeError `obj` is not ::RUBY_T_FILE.
[393] Fix | Delete
* @return `obj`'s backend IO.
[394] Fix | Delete
* @post `obj` is initialised.
[395] Fix | Delete
*/
[396] Fix | Delete
rb_io_t *rb_io_make_open_file(VALUE obj);
[397] Fix | Delete
[398] Fix | Delete
/**
[399] Fix | Delete
* Finds or creates a stdio's file structure from a Ruby's one. This can be
[400] Fix | Delete
* handy if you want to call an external API that accepts `FILE *`.
[401] Fix | Delete
*
[402] Fix | Delete
* @note Note however, that `FILE`s can have their own buffer. Mixing Ruby's
[403] Fix | Delete
* and stdio's file are basically dangerous. Use with care.
[404] Fix | Delete
*
[405] Fix | Delete
* @param[in,out] fptr Target IO.
[406] Fix | Delete
* @return A stdio's file, created if absent.
[407] Fix | Delete
* @post `fptr` has its corresponding stdio's file.
[408] Fix | Delete
*
[409] Fix | Delete
* @internal
[410] Fix | Delete
*
[411] Fix | Delete
* We had rich support for `FILE` before! In the days of 1.8.x ::rb_io_t was
[412] Fix | Delete
* like this:
[413] Fix | Delete
*
[414] Fix | Delete
* ```CXX
[415] Fix | Delete
* typedef struct rb_io_t {
[416] Fix | Delete
* FILE *f; // stdio ptr for read/write
[417] Fix | Delete
* FILE *f2; // additional ptr for rw pipes
[418] Fix | Delete
* int mode; // mode flags
[419] Fix | Delete
* int pid; // child's pid (for pipes)
[420] Fix | Delete
* int lineno; // number of lines read
[421] Fix | Delete
* char *path; // pathname for file
[422] Fix | Delete
* void (*finalize) _((struct rb_io_t*,int)); // finalize proc
[423] Fix | Delete
* } rb_io_t;
[424] Fix | Delete
*```
[425] Fix | Delete
*
[426] Fix | Delete
* But we eventually abandoned this layout. It was too difficult. We could
[427] Fix | Delete
* not have fine-grained control over the `f` field.
[428] Fix | Delete
*
[429] Fix | Delete
* - `FILE` tends to be an opaque struct. It does not interface well with
[430] Fix | Delete
* `select(2)` etc. This makes IO multiplexing quite hard. Using stdio,
[431] Fix | Delete
* there is arguably no portable way to know if `fwrite(3)` blocks.
[432] Fix | Delete
*
[433] Fix | Delete
* - Nonblocking mode, which is another core concept that enables IO
[434] Fix | Delete
* multiplexing, does not interface with stdio routines at all.
[435] Fix | Delete
*
[436] Fix | Delete
* - Detection of duplexed IO is also hard for the same reason.
[437] Fix | Delete
*
[438] Fix | Delete
* - `feof(3)` is not portable.
[439] Fix | Delete
* https://mail.python.org/pipermail/python-dev/2001-January/011390.html
[440] Fix | Delete
*
[441] Fix | Delete
* - Solaris was a thing back then. They could not have more than 256 `FILE`
[442] Fix | Delete
* structures at a time. Their file descriptors ware stored in an
[443] Fix | Delete
* `unsigned char`.
[444] Fix | Delete
*
[445] Fix | Delete
* - It is next to impossible to avoid SEGV, especially when a thread tries to
[446] Fix | Delete
* `ungetc(3)`-ing from a `FILE` which is `fread(3)`-ed by another one.
[447] Fix | Delete
*
[448] Fix | Delete
* In short, it is a bad idea to let someone else manage IO buffers, especially
[449] Fix | Delete
* someone you cannot control. This still applies to extension libraries
[450] Fix | Delete
* methinks. Ruby doesn't prevent you from shooting yourself in the foot, but
[451] Fix | Delete
* consider yourself warned here.
[452] Fix | Delete
*/
[453] Fix | Delete
FILE *rb_io_stdio_file(rb_io_t *fptr);
[454] Fix | Delete
[455] Fix | Delete
/**
[456] Fix | Delete
* Identical to rb_io_stdio_file(), except it takes file descriptors instead of
[457] Fix | Delete
* Ruby's IO. It can also be seen as a compatibility layer to wrap
[458] Fix | Delete
* `fdopen(3)`. Nowadays all supporting systems, including Windows, have
[459] Fix | Delete
* `fdopen`. Why not use them.
[460] Fix | Delete
*
[461] Fix | Delete
* @param[in] fd A file descriptor.
[462] Fix | Delete
* @param[in] modestr C string, something like `"r+"`.
[463] Fix | Delete
* @exception rb_eSystemCallError `fdopen` failed for some reason.
[464] Fix | Delete
* @return A stdio's file associated with `fd`.
[465] Fix | Delete
* @note Interpretation of `modestr` depends on the underlying operating
[466] Fix | Delete
* system. On glibc you might be able to pass e.g. `"rm"`, but
[467] Fix | Delete
* that's an extension to POSIX.
[468] Fix | Delete
*/
[469] Fix | Delete
FILE *rb_fdopen(int fd, const char *modestr);
[470] Fix | Delete
[471] Fix | Delete
/**
[472] Fix | Delete
* Maps a file mode string (that rb_file_open() takes) into a mixture of
[473] Fix | Delete
* `FMODE_` flags. This for instance returns
[474] Fix | Delete
* `FMODE_WRITABLE | FMODE_TRUNC | FMODE_CREATE | FMODE_EXCL` for `"wx"`.
[475] Fix | Delete
*
[476] Fix | Delete
* @note You cannot pass this return value to OS provided `open(2)` etc.
[477] Fix | Delete
*
[478] Fix | Delete
* @param[in] modestr File mode, in C's string.
[479] Fix | Delete
* @exception rb_eArgError `modestr` is broken.
[480] Fix | Delete
* @return A set of flags.
[481] Fix | Delete
*
[482] Fix | Delete
* @internal
[483] Fix | Delete
*
[484] Fix | Delete
* rb_io_modestr_fmode() is not a pure function because it raises.
[485] Fix | Delete
*/
[486] Fix | Delete
int rb_io_modestr_fmode(const char *modestr);
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Identical to rb_io_modestr_fmode(), except it returns a mixture of `O_`
[490] Fix | Delete
* flags. This for instance returns `O_WRONLY | O_TRUNC | O_CREAT | O_EXCL` for
[491] Fix | Delete
* `"wx"`.
[492] Fix | Delete
*
[493] Fix | Delete
* @param[in] modestr File mode, in C's string.
[494] Fix | Delete
* @exception rb_eArgError `modestr` is broken.
[495] Fix | Delete
* @return A set of flags.
[496] Fix | Delete
*
[497] Fix | Delete
* @internal
[498] Fix | Delete
*
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function