Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Functions | Variables
util.c File Reference
`#include "internal.h"`
`#include <ctype.h>`
`#include <stdio.h>`
`#include <errno.h>`
`#include <math.h>`
`#include <float.h>`
`#include "ruby/util.h"`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include "missing/dtoa.c"`

Go to the source code of this file.

## Data Structures
struct | stack_node

## Macros
#define | hexdigit ruby_hexdigits
#define | S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define | mmtype long
#define | mmcount (16 / SIZEOF_LONG)
#define | A ((mmtype*)a)
#define | B ((mmtype*)b)
#define | C ((mmtype*)c)
#define | D ((mmtype*)d)
#define | mmstep (sizeof(mmtype) * mmcount)
#define | mmprepare(base, size)
#define | mmarg mmkind, size, high, low
#define | mmargdecl int mmkind, size_t size, size_t high, size_t low
#define | mmswap(a, b) mmswap_((a),(b),mmarg)
#define | mmrot3(a, b, c) mmrot3_((a),(b),(c),mmarg)
#define | PUSH(ll, rr) do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */
#define | POP(ll, rr) do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */
#define | med3(a, b, c)
#define | PATH_MAX 8192
#define | strtod ruby_strtod
#define | dtoa ruby_dtoa
#define | hdtoa ruby_hdtoa

## Typedefs
typedef int() | cmpfunc_t(const void *, const void *, void *)

## Functions
unsigned long | ruby_scan_oct (const char *start, size_t len, size_t *retlen)
unsigned long | ruby_scan_hex (const char *start, size_t len, size_t *retlen)
| NO_SANITIZE ("unsigned-integer-overflow", extern unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow))
unsigned long | ruby_scan_digits (const char *str, ssize_t len, int base, size_t *retlen, int *overflow)
unsigned long | ruby_strtoul (const char *str, char **endptr, int base)
void | ruby_qsort (void *base, const size_t nel, const size_t size, cmpfunc_t *cmp, void *d)
char * | ruby_strdup (const char *str)
char * | ruby_getcwd (void)
void | ruby_each_words (const char *str, void(*func)(const char *, int, void *), void *arg)

## Variables
const char | ruby_hexdigits [] = "0123456789abcdef0123456789ABCDEF"
const signed char | ruby_digit36_to_number_table []

## Macro Definition Documentation

## ◆ A

#define A ((mmtype*)a)

Definition at line 263 of file util.c.

## ◆ B

#define B ((mmtype*)b)

Definition at line 264 of file util.c.

## ◆ C

#define C ((mmtype*)c)

Definition at line 265 of file util.c.

## ◆ D

#define D ((mmtype*)d)

Definition at line 266 of file util.c.

## ◆ dtoa

#define dtoa ruby_dtoa

Definition at line 604 of file util.c.

## ◆ hdtoa

#define hdtoa ruby_hdtoa

Definition at line 606 of file util.c.

## ◆ hexdigit

#define hexdigit ruby_hexdigits

Definition at line 31 of file util.c.

## ◆ med3

#define med3 | ( |  | a,
|  |  | b,
|  |  | c
| ) |  |

Value:
((*cmp)((a),(b),d)<0 ? \
((*cmp)((b),(c),d)<0 ? (b) : ((*cmp)((a),(c),d)<0 ? (c) : (a))) : \
((*cmp)((b),(c),d)>0 ? (b) : ((*cmp)((a),(c),d)<0 ? (a) : (c))))

Definition at line 370 of file util.c.

## ◆ mmarg

#define mmarg mmkind, size, high, low

Definition at line 278 of file util.c.

## ◆ mmargdecl

#define mmargdecl int mmkind, size_t size, size_t high, size_t low

Definition at line 279 of file util.c.

## ◆ mmcount

#define mmcount (16 / SIZEOF_LONG)

Definition at line 262 of file util.c.

## ◆ mmprepare

#define mmprepare | ( |  | base,
|  |  | size
| ) |  |

Value:
do {\
if (((VALUE)(base) % sizeof(mmtype)) == 0 && ((size) % sizeof(mmtype)) == 0) \
if ((size) >= mmstep) mmkind = 1;\
else mmkind = 0;\
else mmkind = -1;\
high = ((size) / mmstep) * mmstep;\
low = ((size) % mmstep);\
} while (0)\

Definition at line 269 of file util.c.

## ◆ mmrot3

#define mmrot3 | ( |  | a,
|  |  | b,
|  |  | c
| ) |  | mmrot3_((a),(b),(c),mmarg)

Definition at line 355 of file util.c.

## ◆ mmstep

#define mmstep (sizeof(mmtype) * mmcount)

Definition at line 268 of file util.c.

## ◆ mmswap

#define mmswap | ( |  | a,
|  |  | b
| ) |  | mmswap_((a),(b),mmarg)

Definition at line 317 of file util.c.

## ◆ mmtype

#define mmtype long

Definition at line 261 of file util.c.

## ◆ PATH_MAX

#define PATH_MAX 8192

## ◆ POP

#define POP | ( |  | ll,
|  |  | rr
| ) |  | do { --top; (ll) = top->LL; (rr) = top->RR; } while (0) /* Pop L,l,R,r */

Definition at line 368 of file util.c.

## ◆ PUSH

#define PUSH | ( |  | ll,
|  |  | rr
| ) |  | do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */

Definition at line 367 of file util.c.

## ◆ S_ISDIR

#define S_ISDIR | ( |  | m | ) | (((m) & S_IFMT) == S_IFDIR)

Definition at line 208 of file util.c.

## ◆ strtod

#define strtod ruby_strtod

Definition at line 602 of file util.c.

## Typedef Documentation

## ◆ cmpfunc_t

typedef int() cmpfunc_t(const void *, const void *, void *)

Definition at line 211 of file util.c.

## Function Documentation

## ◆ NO_SANITIZE()

NO_SANITIZE | ( | "unsigned-integer-overflow" | ,
|  | extern unsigned long | ruby_scan_digitsconst char *str, ssize_t len, int base, size_t *retlen, int *overflow
| ) |  |

## ◆ ruby_each_words()

void ruby_each_words | ( | const char * | str,
|  | void(*)(const char *, int, void *) | func,
|  | void * | arg
| ) |  |

Definition at line 585 of file util.c.

References arg, int, ISSPACE, len, and str.

Referenced by ruby_set_debug_option().

## ◆ ruby_getcwd()

char* ruby_getcwd | ( | void |  | ) |

Definition at line 539 of file util.c.

References buf, DATA_PTR, Data_Wrap_Struct, ERANGE, errno, free, getcwd(), getwd(), NULL, PATH_MAX, RB_GC_GUARD, rb_sys_fail(), rb_syserr_fail(), RUBY_DEFAULT_FREE, ruby_strdup(), size, xfree, xmalloc, and xrealloc.

Referenced by rb_dir_getwd_ospath().

## ◆ ruby_qsort()

void ruby_qsort | ( | void * | base,
|  | const size_t | nel,
|  | const size_t | size,
|  | cmpfunc_t * | cmp,
|  | void * | d
| ) |  |

Definition at line 375 of file util.c.

## ◆ ruby_scan_digits()

unsigned long ruby_scan_digits | ( | const char * | str,
|  | ssize_t | len,
|  | int | base,
|  | size_t * | retlen,
|  | int * | overflow
| ) |  |

Definition at line 97 of file util.c.

References char, len, long, ruby_digit36_to_number_table, and str.

Referenced by ruby_strtoul().

## ◆ ruby_scan_hex()

unsigned long ruby_scan_hex | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 52 of file util.c.

References hexdigit, i, int, len, and strchr().

## ◆ ruby_scan_oct()

unsigned long ruby_scan_oct | ( | const char * | start,
|  | size_t | len,
|  | size_t * | retlen
| ) |  |

Definition at line 34 of file util.c.

References i, int, and len.

## ◆ ruby_strdup()

char* ruby_strdup | ( | const char * | str | ) |

Definition at line 527 of file util.c.

References len, memcpy(), str, strlen(), and xmalloc.

Referenced by compat_init_setproctitle(), and ruby_getcwd().

## Variable Documentation

## ◆ ruby_digit36_to_number_table

const signed char ruby_digit36_to_number_table[]

Initial value:
= {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
}

Definition at line 75 of file util.c.

Referenced by ruby_scan_digits().

## ◆ ruby_hexdigits

const char ruby_hexdigits[] = "0123456789abcdef0123456789ABCDEF"

Definition at line 30 of file util.c.

VALUE
unsigned long VALUE
Definition: ruby.h:102
mmstep
#define mmstep
Definition: util.c:268
mmtype
#define mmtype
Definition: util.c:261
size
int size
Definition: encoding.c:58