Ruby: rubystub.c Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

rubystub.c
1#include "internal.h"
2#include "internal/missing.h"
3#if defined HAVE_DLADDR
4#include <dlfcn.h>
5#endif
6#if defined HAVE_SYS_PARAM_H
7#include <sys/param.h>
8#endif
9static void* stub_options(int argc, char **argv);
10#define ruby_options stub_options
11#include <main.c>
12#undef ruby_options
13
14void *
15stub_options(int argc, char **argv)
16{
17 char xflag[] = "-x";
18 char *xargv[4] = {NULL, xflag};
19 char *cmd = argv[0];
20 void *ret;
21
22#if defined __CYGWIN__ || defined _WIN32
23 /* GetCommandLineW should contain the accessible path,
24 * use argv[0] as is */
25#elif defined __linux__
26 {
27 char selfexe[MAXPATHLEN];
28 ssize_t len = readlink("/proc/self/exe", selfexe, sizeof(selfexe));
29 if (len < 0) {
30 perror("readlink(\"/proc/self/exe\")");
31 return NULL;
32 }
33 selfexe[len] = '\0';
34 cmd = selfexe;
35 }
36#elif defined HAVE_DLADDR
37 {
38 Dl_info dli;
39 if (!dladdr(stub_options, &dli)) {
40 perror("dladdr");
41 return NULL;
42 }
43 cmd = (char *)dli.dli_fname;
44 }
45#endif
46
47#ifndef HAVE_SETPROCTITLE
48 /* argc and argv must be the original */
49 ruby_init_setproctitle(argc, argv);
50#endif
51
52 /* set script with -x option */
53 /* xargv[0] is NULL not to re-initialize setproctitle again */
54 xargv[2] = cmd;
55 ret = ruby_options(3, xargv);
56
57 /* set all arguments to ARGV */
58 ruby_set_argv(argc - 1, argv + 1);
59
60 return ret;
61}
ruby_set_argv
void ruby_set_argv(int argc, char **argv)
Sets argv that ruby understands.
Definition ruby.c:3216
len
int len
Length of the buffer.
Definition io.h:8