Ruby  3.1.4p223 (2023-03-30 revision HEAD)
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 #if HAVE_SYS_TYPES_H
23 # include <sys/types.h> /* ssize_t */
24 #endif
25 
32 #include "ruby/defines.h"
33 
35 
36 
37 #define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
38 
44 RUBY_EXTERN const signed char ruby_digit36_to_number_table[];
45 
50 RUBY_EXTERN const char ruby_hexdigits[];
51 
71 unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
72 
74 #define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
75 
94 unsigned long ruby_scan_oct(const char *str, size_t len, size_t *consumed);
95 
97 #define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
98 
116 unsigned long ruby_scan_hex(const char *str, size_t len, size_t *ret);
117 
123 #ifdef HAVE_GNU_QSORT_R
124 # define ruby_qsort qsort_r
125 #else
126 void ruby_qsort(void *, const size_t, const size_t,
127  int (*)(const void *, const void *, void *), void *);
128 #endif
129 
141 void ruby_setenv(const char *key, const char *val);
142 
151 void ruby_unsetenv(const char *key);
152 
165 char *ruby_strdup(const char *str);
166 
167 #undef strdup
176 #define strdup(s) ruby_strdup(s)
177 
188 char *ruby_getcwd(void);
189 
208 double ruby_strtod(const char *str, char **endptr);
209 
210 #undef strtod
212 #define strtod(s,e) ruby_strtod((s),(e))
213 
224 void ruby_each_words(const char *str, void (*func)(const char *word, int len, void *argv), void *argv);
225 
227 
228 #endif /* RUBY_UTIL_H */
Tweaking visibility of C variables/functions.
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition: dllexport.h:47
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:106
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:97
void ruby_setenv(const char *key, const char *val)
Sets an environment variable.
Definition: hash.c:5134
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
unsigned long ruby_scan_hex(const char *str, size_t len, size_t *ret)
Interprets the passed string a hexadecimal unsigned integer.
Definition: util.c:56
const signed char ruby_digit36_to_number_table[]
Character to number mapping like ‘'a’->10,'b'->11` etc.
Definition: util.c:76
void ruby_unsetenv(const char *key)
Deletes the passed environment variable, if any.
Definition: hash.c:5316
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".
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:548
double ruby_strtod(const char *str, char **endptr)
Our own locale-insensitive version of strtod(3).
void ruby_qsort(void *, const size_t, const size_t, int(*)(const void *, const void *, void *), void *)
Reentrant implementation of quick sort.
const char ruby_hexdigits[]
Characters that Ruby accepts as hexadecimal digits.
Definition: util.c:34
unsigned long ruby_scan_oct(const char *str, size_t len, size_t *consumed)
Interprets the passed string as an octal unsigned integer.
Definition: util.c:38
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.
Definition: util.c:98
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:62
Defines RBIMPL_ATTR_NODISCARD.
#define RBIMPL_ATTR_NODISCARD()
Wraps (or simulates) [[nodiscard]].
Definition: nodiscard.h:37
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Defines RBIMPL_ATTR_RESTRICT.
#define RBIMPL_ATTR_RESTRICT()
Wraps (or simulates) __declspec(restrict)
Definition: restrict.h:35
Defines RBIMPL_ATTR_RETURNS_NONNULL.
#define RBIMPL_ATTR_RETURNS_NONNULL()
Wraps (or simulates) __attribute__((returns_nonnull))