Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby32/include/ruby
File: util.h
#ifndef RUBY_UTIL_H /*-*-C++-*-vi:se ft=cpp:*/
[0] Fix | Delete
#define RUBY_UTIL_H 1
[1] Fix | Delete
/**
[2] Fix | Delete
* @file
[3] Fix | Delete
* @author $Author$
[4] Fix | Delete
* @date Thu Mar 9 11:55:53 JST 1995
[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
* @warning DO NOT ADD RANDOM GARBAGES IN THIS FILE! Contents of this file
[11] Fix | Delete
* reside here for historical reasons. Find a right place for your
[12] Fix | Delete
* API!
[13] Fix | Delete
*/
[14] Fix | Delete
#include "ruby/internal/config.h"
[15] Fix | Delete
[16] Fix | Delete
#ifdef STDC_HEADERS
[17] Fix | Delete
# include <stddef.h> /* size_t */
[18] Fix | Delete
#endif
[19] Fix | Delete
[20] Fix | Delete
#ifdef HAVE_SYS_TYPES_H
[21] Fix | Delete
# include <sys/types.h> /* ssize_t */
[22] Fix | Delete
#endif
[23] Fix | Delete
[24] Fix | Delete
#include "ruby/internal/attr/noalias.h"
[25] Fix | Delete
#include "ruby/internal/attr/nodiscard.h"
[26] Fix | Delete
#include "ruby/internal/attr/nonnull.h"
[27] Fix | Delete
#include "ruby/internal/attr/restrict.h"
[28] Fix | Delete
#include "ruby/internal/attr/returns_nonnull.h"
[29] Fix | Delete
#include "ruby/internal/dllexport.h"
[30] Fix | Delete
#include "ruby/defines.h"
[31] Fix | Delete
[32] Fix | Delete
RBIMPL_SYMBOL_EXPORT_BEGIN()
[33] Fix | Delete
[34] Fix | Delete
/** an approximation of ceil(n * log10(2)), up to 65536 at least */
[35] Fix | Delete
#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Character to number mapping like `'a'` -> `10`, `'b'` -> `11` etc. For
[39] Fix | Delete
* punctuation etc., the value is -1. "36" terminology comes from the fact
[40] Fix | Delete
* that this is the table behind `str.to_i(36)`.
[41] Fix | Delete
*/
[42] Fix | Delete
RUBY_EXTERN const signed char ruby_digit36_to_number_table[];
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Characters that Ruby accepts as hexadecimal digits. This is `/\h/` expanded
[46] Fix | Delete
* into an array.
[47] Fix | Delete
*/
[48] Fix | Delete
RUBY_EXTERN const char ruby_hexdigits[];
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Scans the passed string, assuming the string is a textual representation of
[52] Fix | Delete
* an integer. Stops when encountering something non-digit for the passed
[53] Fix | Delete
* base.
[54] Fix | Delete
*
[55] Fix | Delete
* @note This does not understand minus sign.
[56] Fix | Delete
* @note This does not understand e.g. `0x` prefix.
[57] Fix | Delete
* @note It is a failure to pass `0` to `base`, unlike ruby_strtoul().
[58] Fix | Delete
* @param[in] str Target string of digits to interpret.
[59] Fix | Delete
* @param[in] len Number of bytes of `str`, or -1 to detect `NUL`.
[60] Fix | Delete
* @param[in] base Base, `2` to `36` inclusive.
[61] Fix | Delete
* @param[out] retlen Return value buffer.
[62] Fix | Delete
* @param[out] overflow Return value buffer.
[63] Fix | Delete
* @return Interpreted numeric representation of `str`.
[64] Fix | Delete
* @post `retlen` is the number of bytes scanned so far.
[65] Fix | Delete
* @post `overflow` is set to true if the string represents something
[66] Fix | Delete
* bigger than `ULONG_MAX`. Something meaningful still returns;
[67] Fix | Delete
* which is the designed belabour of C's unsigned arithmetic.
[68] Fix | Delete
*/
[69] Fix | Delete
unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
[70] Fix | Delete
[71] Fix | Delete
/** @old{ruby_scan_oct} */
[72] Fix | Delete
#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
[73] Fix | Delete
[74] Fix | Delete
RBIMPL_ATTR_NOALIAS()
[75] Fix | Delete
RBIMPL_ATTR_NONNULL(())
[76] Fix | Delete
/**
[77] Fix | Delete
* Interprets the passed string as an octal unsigned integer. Stops when
[78] Fix | Delete
* encounters something not understood.
[79] Fix | Delete
*
[80] Fix | Delete
* @param[in] str C string to scan.
[81] Fix | Delete
* @param[in] len Length of `str`.
[82] Fix | Delete
* @param[out] consumed Return value buffer.
[83] Fix | Delete
* @return Parsed integer.
[84] Fix | Delete
* @post `ret` is the number of characters read.
[85] Fix | Delete
*
[86] Fix | Delete
* @internal
[87] Fix | Delete
*
[88] Fix | Delete
* No consideration is made for integer overflows. As the return value is
[89] Fix | Delete
* unsigned this function has fully defined behaviour, but you cannot know if
[90] Fix | Delete
* there was an integer wrap-around or not.
[91] Fix | Delete
*/
[92] Fix | Delete
unsigned long ruby_scan_oct(const char *str, size_t len, size_t *consumed);
[93] Fix | Delete
[94] Fix | Delete
/** @old{ruby_scan_hex} */
[95] Fix | Delete
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
[96] Fix | Delete
[97] Fix | Delete
RBIMPL_ATTR_NONNULL(())
[98] Fix | Delete
/**
[99] Fix | Delete
* Interprets the passed string a hexadecimal unsigned integer. Stops when
[100] Fix | Delete
* encounters something not understood.
[101] Fix | Delete
*
[102] Fix | Delete
* @param[in] str C string to scan.
[103] Fix | Delete
* @param[in] len Length of `str`.
[104] Fix | Delete
* @param[out] ret Return value buffer.
[105] Fix | Delete
* @return Parsed integer.
[106] Fix | Delete
* @post `ret` is the number of characters read.
[107] Fix | Delete
*
[108] Fix | Delete
* @internal
[109] Fix | Delete
*
[110] Fix | Delete
* No consideration is made for integer overflows. As the return value is
[111] Fix | Delete
* unsigned this function has fully defined behaviour, but you cannot know if
[112] Fix | Delete
* there was an integer wrap-around or not.
[113] Fix | Delete
*/
[114] Fix | Delete
unsigned long ruby_scan_hex(const char *str, size_t len, size_t *ret);
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Reentrant implementation of quick sort. If your system provides something
[118] Fix | Delete
* (like C11 qsort_s), this is a thin wrapper of that routine. Otherwise
[119] Fix | Delete
* resorts to our own version.
[120] Fix | Delete
*/
[121] Fix | Delete
#ifdef HAVE_GNU_QSORT_R
[122] Fix | Delete
# define ruby_qsort qsort_r
[123] Fix | Delete
#else
[124] Fix | Delete
void ruby_qsort(void *, const size_t, const size_t,
[125] Fix | Delete
int (*)(const void *, const void *, void *), void *);
[126] Fix | Delete
#endif
[127] Fix | Delete
[128] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[129] Fix | Delete
/**
[130] Fix | Delete
* Sets an environment variable. In case of POSIX this is a wrapper of
[131] Fix | Delete
* `setenv(3)`. But there are systems which lack one. We try hard emulating.
[132] Fix | Delete
*
[133] Fix | Delete
* @param[in] key An environment variable.
[134] Fix | Delete
* @param[in] val A value to be associated with `key`, or 0.
[135] Fix | Delete
* @exception rb_eSystemCallError `setenv(3)` failed for some reason.
[136] Fix | Delete
* @post Environment variable `key` is created if necessary. Its value
[137] Fix | Delete
* is updated to be `val`.
[138] Fix | Delete
*/
[139] Fix | Delete
void ruby_setenv(const char *key, const char *val);
[140] Fix | Delete
[141] Fix | Delete
RBIMPL_ATTR_NONNULL(())
[142] Fix | Delete
/**
[143] Fix | Delete
* Deletes the passed environment variable, if any.
[144] Fix | Delete
*
[145] Fix | Delete
* @param[in] key An environment variable.
[146] Fix | Delete
* @exception rb_eSystemCallError `unsetenv(3)` failed for some reason.
[147] Fix | Delete
* @post Environment variable `key` does not exist.
[148] Fix | Delete
*/
[149] Fix | Delete
void ruby_unsetenv(const char *key);
[150] Fix | Delete
[151] Fix | Delete
RBIMPL_ATTR_NODISCARD()
[152] Fix | Delete
RBIMPL_ATTR_RESTRICT()
[153] Fix | Delete
RBIMPL_ATTR_RETURNS_NONNULL()
[154] Fix | Delete
RBIMPL_ATTR_NONNULL(())
[155] Fix | Delete
/**
[156] Fix | Delete
* This is our own version of `strdup(3)` that uses ruby_xmalloc() instead of
[157] Fix | Delete
* system malloc (benefits our GC).
[158] Fix | Delete
*
[159] Fix | Delete
* @param[in] str Target C string to duplicate.
[160] Fix | Delete
* @return An allocated C string holding the identical contents.
[161] Fix | Delete
* @note Return value must be discarded using ruby_xfree().
[162] Fix | Delete
*/
[163] Fix | Delete
char *ruby_strdup(const char *str);
[164] Fix | Delete
[165] Fix | Delete
#undef strdup
[166] Fix | Delete
/**
[167] Fix | Delete
* @alias{ruby_strdup}
[168] Fix | Delete
*
[169] Fix | Delete
* @internal
[170] Fix | Delete
*
[171] Fix | Delete
* @shyouhei doesn't think it is a wise idea. ruby_strdup()'s return value
[172] Fix | Delete
* must be passed to ruby_xfree(), but this macro makes it almost impossible.
[173] Fix | Delete
*/
[174] Fix | Delete
#define strdup(s) ruby_strdup(s)
[175] Fix | Delete
[176] Fix | Delete
RBIMPL_ATTR_NODISCARD()
[177] Fix | Delete
RBIMPL_ATTR_RESTRICT()
[178] Fix | Delete
RBIMPL_ATTR_RETURNS_NONNULL()
[179] Fix | Delete
/**
[180] Fix | Delete
* This is our own version of `getcwd(3)` that uses ruby_xmalloc() instead of
[181] Fix | Delete
* system malloc (benefits our GC).
[182] Fix | Delete
*
[183] Fix | Delete
* @return An allocated C string holding the process working directory.
[184] Fix | Delete
* @note Return value must be discarded using ruby_xfree().
[185] Fix | Delete
*/
[186] Fix | Delete
char *ruby_getcwd(void);
[187] Fix | Delete
[188] Fix | Delete
RBIMPL_ATTR_NONNULL((1))
[189] Fix | Delete
/**
[190] Fix | Delete
* Our own locale-insensitive version of `strtod(3)`. The conversion is done
[191] Fix | Delete
* as if the current locale is set to the "C" locale, no matter actual runtime
[192] Fix | Delete
* locale settings.
[193] Fix | Delete
*
[194] Fix | Delete
* @param[in] str Decimal or hexadecimal representation of a floating
[195] Fix | Delete
* point number.
[196] Fix | Delete
* @param[out] endptr NULL, or an arbitrary pointer (overwritten on return).
[197] Fix | Delete
* @return Converted number.
[198] Fix | Delete
* @post If `endptr` is not NULL, it is updated to point the first such
[199] Fix | Delete
* byte where conversion failed.
[200] Fix | Delete
* @note This function sets `errno` on failure.
[201] Fix | Delete
* - `ERANGE`: Converted integer is out of range of `double`.
[202] Fix | Delete
* @see William D. Clinger, "How to Read Floating Point Numbers
[203] Fix | Delete
* Accurately" in Proc. ACM SIGPLAN '90, pp. 92-101.
[204] Fix | Delete
* https://doi.org/10.1145/93542.93557
[205] Fix | Delete
*/
[206] Fix | Delete
double ruby_strtod(const char *str, char **endptr);
[207] Fix | Delete
[208] Fix | Delete
#undef strtod
[209] Fix | Delete
/** @alias{ruby_strtod} */
[210] Fix | Delete
#define strtod(s,e) ruby_strtod((s),(e))
[211] Fix | Delete
[212] Fix | Delete
RBIMPL_ATTR_NONNULL((2))
[213] Fix | Delete
/**
[214] Fix | Delete
* Scans the passed string, with calling the callback function every time it
[215] Fix | Delete
* encounters a "word". A word here is a series of characters separated by
[216] Fix | Delete
* either a space (of IEEE 1003.1 section 7.3.1.1), or a `','`.
[217] Fix | Delete
*
[218] Fix | Delete
* @param[in] str Target string to split into each words.
[219] Fix | Delete
* @param[in] func Callback function.
[220] Fix | Delete
* @param[in,out] argv Passed as-is to `func`.
[221] Fix | Delete
*/
[222] Fix | Delete
void ruby_each_words(const char *str, void (*func)(const char *word, int len, void *argv), void *argv);
[223] Fix | Delete
[224] Fix | Delete
RBIMPL_SYMBOL_EXPORT_END()
[225] Fix | Delete
[226] Fix | Delete
#endif /* RUBY_UTIL_H */
[227] Fix | Delete
[228] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function