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