|
Ruby 3.5.0dev (2025-10-25 revision cb302881629f997f403e705425f69e5f6b0741ac)
|
#include "ruby/internal/config.h"#include "ruby/internal/attr/noalias.h"#include "ruby/internal/attr/nodiscard.h"#include "ruby/internal/attr/nonnull.h"#include "ruby/internal/attr/restrict.h"#include "ruby/internal/attr/returns_nonnull.h"#include "ruby/internal/dllexport.h"#include "ruby/defines.h"

Go to the source code of this file.
Macros | |
| #define | DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999) |
| an approximation of ceil(n * log10(2)), up to 1,048,576 (1<<20) without overflow within 32-bit calculation | |
| #define | DECIMAL_SIZE_OF_BYTES(n) DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT) |
| an approximation of decimal representation size for n-bytes | |
| #define | DECIMAL_SIZE_OF(expr) DECIMAL_SIZE_OF_BYTES(sizeof(expr)) |
| An approximation of decimal representation size. | |
| #define | scan_oct(s, l, e) ((int)ruby_scan_oct((s),(l),(e))) |
| Old name of ruby_scan_oct. | |
| #define | scan_hex(s, l, e) ((int)ruby_scan_hex((s),(l),(e))) |
| Old name of ruby_scan_hex. | |
| #define | strdup(s) ruby_strdup(s) |
| Just another name of ruby_strdup. | |
| #define | strtod(s, e) ruby_strtod((s),(e)) |
| Just another name of ruby_strtod. | |
Functions | |
| unsigned long | ruby_scan_digits (const char *str, ssize_t len, int base, size_t *retlen, int *overflow) |
| Scans the passed string, assuming the string is a textual representation of an integer. | |
| unsigned long | ruby_scan_oct (const char *str, size_t len, size_t *consumed) |
| Interprets the passed string as an octal unsigned integer. | |
| unsigned long | ruby_scan_hex (const char *str, size_t len, size_t *ret) |
| Interprets the passed string a hexadecimal unsigned integer. | |
| void | ruby_qsort (void *, const size_t, const size_t, int(*)(const void *, const void *, void *), void *) |
| Reentrant implementation of quick sort. | |
| void | ruby_setenv (const char *key, const char *val) |
| Sets an environment variable. | |
| void | ruby_unsetenv (const char *key) |
| Deletes the passed environment variable, if any. | |
| char * | ruby_strdup (const char *str) |
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC). | |
| char * | ruby_getcwd (void) |
This is our own version of getcwd(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC). | |
| double | ruby_strtod (const char *str, char **endptr) |
Our own locale-insensitive version of strtod(3). | |
| void | ruby_each_words (const char *str, void(*func)(const char *word, int len, void *argv), void *argv) |
| Scans the passed string, with calling the callback function every time it encounters a "word". | |
Variables | |
| const signed char | ruby_digit36_to_number_table [] |
Character to number mapping like ‘'a’->10,'b'->11etc. | |
| const char | ruby_hexdigits [] |
| Characters that Ruby accepts as hexadecimal digits. | |
Definition in file util.h.
| #define DECIMAL_SIZE_OF | ( | expr | ) | DECIMAL_SIZE_OF_BYTES(sizeof(expr)) |
| #define DECIMAL_SIZE_OF_BITS | ( | n | ) | (((n) * 3010 + 9998) / 9999) |
| #define DECIMAL_SIZE_OF_BYTES | ( | n | ) | DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT) |
| #define strdup | ( | s | ) | ruby_strdup(s) |
Just another name of ruby_strdup.
| #define strtod | ( | s, | |
| e | |||
| ) | ruby_strtod((s),(e)) |
Just another name of ruby_strtod.
| void ruby_each_words | ( | const char * | str, |
| void(*)(const char *word, int len, void *argv) | func, | ||
| void * | argv | ||
| ) |
Scans the passed string, with calling the callback function every time it encounters a "word".
A word here is a series of characters separated by either a space (of IEEE 1003.1 section 7.3.1.1), or a ‘’,'`.
| [in] | str | Target string to split into each words. |
| [in] | func | Callback function. |
| [in,out] | argv | Passed as-is to func. |
| char * ruby_getcwd | ( | void | ) |
This is our own version of getcwd(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC).
Definition at line 581 of file util.c.
Referenced by ruby_getcwd().
| void ruby_qsort | ( | void * | , |
| const size_t | , | ||
| const size_t | , | ||
| int(*)(const void *, const void *, void *) | , | ||
| void * | |||
| ) |
Reentrant implementation of quick sort.
If your system provides something (like C11 qsort_s), this is a thin wrapper of that routine. Otherwise resorts to our own version.
| unsigned long ruby_scan_digits | ( | const char * | str, |
| ssize_t | len, | ||
| int | base, | ||
| size_t * | retlen, | ||
| int * | overflow | ||
| ) |
Scans the passed string, assuming the string is a textual representation of an integer.
Stops when encountering something non-digit for the passed base.
0x prefix. 0 to base, unlike ruby_strtoul(). | [in] | str | Target string of digits to interpret. |
| [in] | len | Number of bytes of str, or -1 to detect NUL. |
| [in] | base | Base, 2 to 36 inclusive. |
| [out] | retlen | Return value buffer. |
| [out] | overflow | Return value buffer. |
str. retlen is the number of bytes scanned so far. overflow is set to true if the string represents something bigger than ULONG_MAX. Something meaningful still returns; which is the designed belabour of C's unsigned arithmetic. | unsigned long ruby_scan_hex | ( | const char * | str, |
| size_t | len, | ||
| size_t * | ret | ||
| ) |
Interprets the passed string a hexadecimal unsigned integer.
Stops when encounters something not understood.
| [in] | str | C string to scan. |
| [in] | len | Length of str. |
| [out] | ret | Return value buffer. |
ret is the number of characters read. | unsigned long ruby_scan_oct | ( | const char * | str, |
| size_t | len, | ||
| size_t * | consumed | ||
| ) |
Interprets the passed string as an octal unsigned integer.
Stops when encounters something not understood.
| [in] | str | C string to scan. |
| [in] | len | Length of str. |
| [out] | consumed | Return value buffer. |
ret is the number of characters read. | void ruby_setenv | ( | const char * | key, |
| const char * | val | ||
| ) |
Sets an environment variable.
In case of POSIX this is a wrapper of setenv(3). But there are systems which lack one. We try hard emulating.
| [in] | key | An environment variable. |
| [in] | val | A value to be associated with key, or 0. |
| rb_eSystemCallError | `setenv(3)` failed for some reason. |
key is created if necessary. Its value is updated to be val. | char * ruby_strdup | ( | const char * | str | ) |
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our GC).
| [in] | str | Target C string to duplicate. |
Definition at line 515 of file util.c.
Referenced by ruby_setenv(), and ruby_strdup().
| double ruby_strtod | ( | const char * | str, |
| char ** | endptr | ||
| ) |
Our own locale-insensitive version of strtod(3).
The conversion is done as if the current locale is set to the "C" locale, no matter actual runtime locale settings.
| [in] | str | Decimal or hexadecimal representation of a floating point number. |
| [out] | endptr | NULL, or an arbitrary pointer (overwritten on return). |
endptr is not NULL, it is updated to point the first such byte where conversion failed. errno on failure.ERANGE: Converted integer is out of range of double. | void ruby_unsetenv | ( | const char * | key | ) |
|
extern |
Character to number mapping like ‘'a’->10,'b'->11etc.
For punctuation etc., the value is -1. "36" terminology comes from the fact that this is the table behindstr.to_i(36)`.
Definition at line 60 of file util.c.
Referenced by ruby_scan_digits().