syscall-rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd1c2e32bd9e6b0c9f7b0304dc52e44cd11c925bf6084bfa8967a35e2221e250
4
+ data.tar.gz: c9f43ef9dfa25493374c9898d58e8bd37ef7a2cfad403fa712dfbfc1339bff7e
5
+ SHA512:
6
+ metadata.gz: 2d0ca6ba1d56b801e8591db4ab96e079347ed120ea9442a368d610e978ece77205da3a979d43665b15208c32953626884cdc470960b503c96cefa54cee37fab3
7
+ data.tar.gz: 2673cc7a983dd3008ff14b86f4bda6b91b9fa341ea6d5493f9e49e6dabfc6d082fe3d88502232c0681e9fc2f3d242cab1e6d7c1475afaed0e7bd065d8ca65408
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("syscall")
@@ -0,0 +1,135 @@
1
+ #include <ruby.h>
2
+ #include <unistd.h>
3
+ #include <fcntl.h>
4
+ #include <sys/syscall.h>
5
+
6
+ static VALUE rb_syscall_write(VALUE self, VALUE fd, VALUE str)
7
+ {
8
+ long ret = syscall(
9
+ SYS_write,
10
+ NUM2LONG(fd),
11
+ RSTRING_PTR(str),
12
+ RSTRING_LEN(str)
13
+ );
14
+
15
+ return LONG2NUM(ret);
16
+ }
17
+
18
+ static VALUE rb_syscall_read(VALUE self, VALUE fd, VALUE size)
19
+ {
20
+ long len = NUM2LONG(size);
21
+
22
+ VALUE str = rb_str_new(NULL, len);
23
+
24
+ long ret = syscall(
25
+ SYS_read,
26
+ NUM2LONG(fd),
27
+ RSTRING_PTR(str),
28
+ len
29
+ );
30
+
31
+ if (ret < 0)
32
+ return Qnil;
33
+
34
+ rb_str_set_len(str, ret);
35
+
36
+ return str;
37
+ }
38
+
39
+ static VALUE rb_syscall_openat(int argc, VALUE *argv, VALUE self)
40
+ {
41
+ VALUE path;
42
+ VALUE flags;
43
+ VALUE mode;
44
+
45
+ rb_scan_args(argc, argv, "21",
46
+ &path,
47
+ &flags,
48
+ &mode);
49
+
50
+ if (NIL_P(mode))
51
+ mode = INT2NUM(0644);
52
+
53
+ long fd = syscall(
54
+ SYS_openat,
55
+ AT_FDCWD,
56
+ StringValueCStr(path),
57
+ NUM2LONG(flags),
58
+ NUM2LONG(mode)
59
+ );
60
+
61
+ return LONG2NUM(fd);
62
+ }
63
+
64
+ static VALUE rb_syscall_close(VALUE self, VALUE fd)
65
+ {
66
+ long ret = syscall(
67
+ SYS_close,
68
+ NUM2LONG(fd)
69
+ );
70
+
71
+ return LONG2NUM(ret);
72
+ }
73
+
74
+ void Init_syscall(void)
75
+ {
76
+ VALUE mSyscall = rb_define_module("Syscall");
77
+
78
+ rb_define_const(
79
+ mSyscall,
80
+ "O_RDONLY",
81
+ INT2NUM(O_RDONLY)
82
+ );
83
+
84
+ rb_define_const(
85
+ mSyscall,
86
+ "O_WRONLY",
87
+ INT2NUM(O_WRONLY)
88
+ );
89
+
90
+ rb_define_const(
91
+ mSyscall,
92
+ "O_RDWR",
93
+ INT2NUM(O_RDWR)
94
+ );
95
+
96
+ rb_define_const(
97
+ mSyscall,
98
+ "O_CREAT",
99
+ INT2NUM(O_CREAT)
100
+ );
101
+
102
+ rb_define_const(
103
+ mSyscall,
104
+ "O_TRUNC",
105
+ INT2NUM(O_TRUNC)
106
+ );
107
+
108
+ rb_define_singleton_method(
109
+ mSyscall,
110
+ "write",
111
+ rb_syscall_write,
112
+ 2
113
+ );
114
+
115
+ rb_define_singleton_method(
116
+ mSyscall,
117
+ "read",
118
+ rb_syscall_read,
119
+ 2
120
+ );
121
+
122
+ rb_define_singleton_method(
123
+ mSyscall,
124
+ "openat",
125
+ rb_syscall_openat,
126
+ -1
127
+ );
128
+
129
+ rb_define_singleton_method(
130
+ mSyscall,
131
+ "close",
132
+ rb_syscall_close,
133
+ 1
134
+ );
135
+ }
data/lib/syscall-rb.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative "syscall"
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syscall-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomoya Araki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-06-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Direct Linux syscall access from Ruby
14
+ email:
15
+ executables: []
16
+ extensions:
17
+ - ext/syscall/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ext/syscall/extconf.rb
21
+ - ext/syscall/syscall.c
22
+ - lib/syscall-rb.rb
23
+ homepage:
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.5.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Linux syscall wrapper for Ruby
45
+ test_files: []