Ruby: include/ruby/util.h Source File

Ruby 3.4.3p32 (2025-04-14 revision d0b7e5b6a04bde21ca483d20a1546b28b401c2d4)

util.h
Go to the documentation of this file.
1#ifndef RUBY_UTIL_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_UTIL_H 1
16#include "ruby/internal/config.h"
17
18#ifdef STDC_HEADERS
19# include <stddef.h> /* size_t */
20#endif
21
22#ifdef HAVE_SYS_TYPES_H
23# include <sys/types.h> /* ssize_t */
24#endif
25
26#include "ruby/internal/attr/noalias.h"
27#include "ruby/internal/attr/nodiscard.h"
28#include "ruby/internal/attr/nonnull.h"
29#include "ruby/internal/attr/restrict.h"
30#include "ruby/internal/attr/returns_nonnull.h"
31#include "ruby/internal/dllexport.h"
32#include "ruby/defines.h"
33
34 RBIMPL_SYMBOL_EXPORT_BEGIN()
35
36
39#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
40
42#define DECIMAL_SIZE_OF_BYTES(n) DECIMAL_SIZE_OF_BITS((n) * CHAR_BIT)
43
48#define DECIMAL_SIZE_OF(expr) DECIMAL_SIZE_OF_BYTES(sizeof(expr))
49
55 RUBY_EXTERN const signed char ruby_digit36_to_number_table[];
56
61 RUBY_EXTERN const char ruby_hexdigits[];
62
82unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
83
85#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
86
87 RBIMPL_ATTR_NOALIAS()
88 RBIMPL_ATTR_NONNULL(())
105unsigned long ruby_scan_oct(const char *str, size_t len, size_t *consumed);
106
108#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
109
110 RBIMPL_ATTR_NONNULL(())
127unsigned long ruby_scan_hex(const char *str, size_t len, size_t *ret);
128
134#ifdef HAVE_GNU_QSORT_R
135# define ruby_qsort qsort_r
136#else
137 void ruby_qsort(void *, const size_t, const size_t,
138 int (*)(const void *, const void *, void *), void *);
139#endif
140
141 RBIMPL_ATTR_NONNULL((1))
152void ruby_setenv(const char *key, const char *val);
153
154 RBIMPL_ATTR_NONNULL(())
162void ruby_unsetenv(const char *key);
163
164 RBIMPL_ATTR_NODISCARD()
165 RBIMPL_ATTR_RESTRICT()
166 RBIMPL_ATTR_RETURNS_NONNULL()
167 RBIMPL_ATTR_NONNULL(())
176char *ruby_strdup(const char *str);
177
178#undef strdup
187#define strdup(s) ruby_strdup(s)
188
189 RBIMPL_ATTR_NODISCARD()
190 RBIMPL_ATTR_RESTRICT()
191 RBIMPL_ATTR_RETURNS_NONNULL()
199char *ruby_getcwd(void);
200
201 RBIMPL_ATTR_NONNULL((1))
219 double ruby_strtod(const char *str, char **endptr);
220
221#undef strtod
223#define strtod(s,e) ruby_strtod((s),(e))
224
225 RBIMPL_ATTR_NONNULL((2))
235void ruby_each_words(const char *str, void (*func)(const char *word, int len, void *argv), void *argv);
236
237 RBIMPL_SYMBOL_EXPORT_END()
238
239#endif /* RUBY_UTIL_H */
dllexport.h
Tweaking visibility of C variables/functions.
RUBY_EXTERN
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:45
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
defines.h
len
int len
Length of the buffer.
Definition io.h:8
ruby_digit36_to_number_table
const signed char ruby_digit36_to_number_table[]
Character to number mapping like ‘'a’->10,'b'->11etc.
Definition util.c:81
ruby_strdup
char * ruby_strdup(const char *str)
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our ...
Definition util.c:536
ruby_each_words
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".
Definition util.c:617
ruby_strtod
double ruby_strtod(const char *str, char **endptr)
Our own locale-insensitive version of strtod(3).
ruby_qsort
void ruby_qsort(void *, const size_t, const size_t, int(*)(const void *, const void *, void *), void *)
Reentrant implementation of quick sort.
ruby_getcwd
char * ruby_getcwd(void)
This is our own version of getcwd(3) that uses ruby_xmalloc() instead of system malloc (benefits our ...
Definition util.c:602
ruby_hexdigits
const char ruby_hexdigits[]
Characters that Ruby accepts as hexadecimal digits.
Definition util.c:39
noalias.h
Defines RBIMPL_ATTR_NOALIAS.
RBIMPL_ATTR_NOALIAS
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition noalias.h:66
nodiscard.h
Defines RBIMPL_ATTR_NODISCARD.
RBIMPL_ATTR_NODISCARD
#define RBIMPL_ATTR_NODISCARD()
Wraps (or simulates) [[nodiscard]].
Definition nodiscard.h:42
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
restrict.h
Defines RBIMPL_ATTR_RESTRICT.
RBIMPL_ATTR_RESTRICT
#define RBIMPL_ATTR_RESTRICT()
Wraps (or simulates) __declspec(restrict)
Definition restrict.h:41
returns_nonnull.h
Defines RBIMPL_ATTR_RETURNS_NONNULL.
RBIMPL_ATTR_RETURNS_NONNULL
#define RBIMPL_ATTR_RETURNS_NONNULL()
Wraps (or simulates) __attribute__((returns_nonnull))
Definition returns_nonnull.h:34