fcntl 0.0.1
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 +7 -0
- data/ext/fcntl/extconf.rb +3 -0
- data/ext/fcntl/fcntl.c +245 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c90426baf7ba8dea1e0968fc14f7eb74f642ff3e
|
4
|
+
data.tar.gz: 1a8bf68899db15705b7d83292833071e6574da5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02372a99019748e79ac2a87a4794ff417e2bde65043719d71c46d23a83edc2ee2926aed10628d0184110c161c75c36e14f859faa29f355c380decbabd87033a5
|
7
|
+
data.tar.gz: ef629dcfd112776032662b854ba8b0c308f2fb0e00b9828ce74b0bff942ce2e825c1171c9c5029ed50169aefb4c0ad26d9f9e07fe813b256330042f5b3db0d9a
|
data/ext/fcntl/fcntl.c
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
/************************************************
|
2
|
+
|
3
|
+
fcntl.c -
|
4
|
+
|
5
|
+
$Author$
|
6
|
+
created at: Mon Apr 7 18:53:05 JST 1997
|
7
|
+
|
8
|
+
Copyright (C) 1997-2001 Yukihiro Matsumoto
|
9
|
+
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
/************************************************
|
13
|
+
= NAME
|
14
|
+
|
15
|
+
fcntl - load the C fcntl.h defines
|
16
|
+
|
17
|
+
= DESCRIPTION
|
18
|
+
|
19
|
+
This module is just a translation of the C <fcntl.h> file.
|
20
|
+
|
21
|
+
= NOTE
|
22
|
+
|
23
|
+
Only #define symbols get translated; you must still correctly
|
24
|
+
pack up your own arguments to pass as args for locking functions, etc.
|
25
|
+
|
26
|
+
************************************************/
|
27
|
+
|
28
|
+
#include "ruby.h"
|
29
|
+
#include <fcntl.h>
|
30
|
+
|
31
|
+
/* Fcntl loads the constants defined in the system's <fcntl.h> C header
|
32
|
+
* file, and used with both the fcntl(2) and open(2) POSIX system calls.
|
33
|
+
*
|
34
|
+
* To perform a fcntl(2) operation, use IO::fcntl.
|
35
|
+
*
|
36
|
+
* To perform an open(2) operation, use IO::sysopen.
|
37
|
+
*
|
38
|
+
* The set of operations and constants available depends upon specific
|
39
|
+
* operating system. Some values listed below may not be supported on your
|
40
|
+
* system.
|
41
|
+
*
|
42
|
+
* See your fcntl(2) man page for complete details.
|
43
|
+
*
|
44
|
+
* Open /tmp/tempfile as a write-only file that is created if it doesn't
|
45
|
+
* exist:
|
46
|
+
*
|
47
|
+
* require 'fcntl'
|
48
|
+
*
|
49
|
+
* fd = IO.sysopen('/tmp/tempfile',
|
50
|
+
* Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT)
|
51
|
+
* f = IO.open(fd)
|
52
|
+
* f.syswrite("TEMP DATA")
|
53
|
+
* f.close
|
54
|
+
*
|
55
|
+
* Get the flags on file +s+:
|
56
|
+
*
|
57
|
+
* m = s.fcntl(Fcntl::F_GETFL, 0)
|
58
|
+
*
|
59
|
+
* Set the non-blocking flag on +f+ in addition to the existing flags in +m+.
|
60
|
+
*
|
61
|
+
* f.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK|m)
|
62
|
+
*
|
63
|
+
*/
|
64
|
+
void
|
65
|
+
Init_fcntl(void)
|
66
|
+
{
|
67
|
+
VALUE mFcntl = rb_define_module("Fcntl");
|
68
|
+
#ifdef F_DUPFD
|
69
|
+
/* Document-const: F_DUPFD
|
70
|
+
*
|
71
|
+
* Duplicate a file descriptor to the mimimum unused file descriptor
|
72
|
+
* greater than or equal to the argument.
|
73
|
+
*
|
74
|
+
* The close-on-exec flag of the duplicated file descriptor is set.
|
75
|
+
* (Ruby uses F_DUPFD_CLOEXEC internally if available to avoid race
|
76
|
+
* condition. F_SETFD is used if F_DUPFD_CLOEXEC is not available.)
|
77
|
+
*/
|
78
|
+
rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD));
|
79
|
+
#endif
|
80
|
+
#ifdef F_GETFD
|
81
|
+
/* Document-const: F_GETFD
|
82
|
+
*
|
83
|
+
* Read the close-on-exec flag of a file descriptor.
|
84
|
+
*/
|
85
|
+
rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD));
|
86
|
+
#endif
|
87
|
+
#ifdef F_GETLK
|
88
|
+
/* Document-const: F_GETLK
|
89
|
+
*
|
90
|
+
* Determine whether a given region of a file is locked. This uses one of
|
91
|
+
* the F_*LK flags.
|
92
|
+
*/
|
93
|
+
rb_define_const(mFcntl, "F_GETLK", INT2NUM(F_GETLK));
|
94
|
+
#endif
|
95
|
+
#ifdef F_SETFD
|
96
|
+
/* Document-const: F_SETFD
|
97
|
+
*
|
98
|
+
* Set the close-on-exec flag of a file descriptor.
|
99
|
+
*/
|
100
|
+
rb_define_const(mFcntl, "F_SETFD", INT2NUM(F_SETFD));
|
101
|
+
#endif
|
102
|
+
#ifdef F_GETFL
|
103
|
+
/* Document-const: F_GETFL
|
104
|
+
*
|
105
|
+
* Get the file descriptor flags. This will be one or more of the O_*
|
106
|
+
* flags.
|
107
|
+
*/
|
108
|
+
rb_define_const(mFcntl, "F_GETFL", INT2NUM(F_GETFL));
|
109
|
+
#endif
|
110
|
+
#ifdef F_SETFL
|
111
|
+
/* Document-const: F_SETFL
|
112
|
+
*
|
113
|
+
* Set the file descriptor flags. This will be one or more of the O_*
|
114
|
+
* flags.
|
115
|
+
*/
|
116
|
+
rb_define_const(mFcntl, "F_SETFL", INT2NUM(F_SETFL));
|
117
|
+
#endif
|
118
|
+
#ifdef F_SETLK
|
119
|
+
/* Document-const: F_SETLK
|
120
|
+
*
|
121
|
+
* Acquire a lock on a region of a file. This uses one of the F_*LCK
|
122
|
+
* flags.
|
123
|
+
*/
|
124
|
+
rb_define_const(mFcntl, "F_SETLK", INT2NUM(F_SETLK));
|
125
|
+
#endif
|
126
|
+
#ifdef F_SETLKW
|
127
|
+
/* Document-const: F_SETLKW
|
128
|
+
*
|
129
|
+
* Acquire a lock on a region of a file, waiting if necessary. This uses
|
130
|
+
* one of the F_*LCK flags
|
131
|
+
*/
|
132
|
+
rb_define_const(mFcntl, "F_SETLKW", INT2NUM(F_SETLKW));
|
133
|
+
#endif
|
134
|
+
#ifdef FD_CLOEXEC
|
135
|
+
/* Document-const: FD_CLOEXEC
|
136
|
+
*
|
137
|
+
* the value of the close-on-exec flag.
|
138
|
+
*/
|
139
|
+
rb_define_const(mFcntl, "FD_CLOEXEC", INT2NUM(FD_CLOEXEC));
|
140
|
+
#endif
|
141
|
+
#ifdef F_RDLCK
|
142
|
+
/* Document-const: F_RDLCK
|
143
|
+
*
|
144
|
+
* Read lock for a region of a file
|
145
|
+
*/
|
146
|
+
rb_define_const(mFcntl, "F_RDLCK", INT2NUM(F_RDLCK));
|
147
|
+
#endif
|
148
|
+
#ifdef F_UNLCK
|
149
|
+
/* Document-const: F_UNLCK
|
150
|
+
*
|
151
|
+
* Remove lock for a region of a file
|
152
|
+
*/
|
153
|
+
rb_define_const(mFcntl, "F_UNLCK", INT2NUM(F_UNLCK));
|
154
|
+
#endif
|
155
|
+
#ifdef F_WRLCK
|
156
|
+
/* Document-const: F_WRLCK
|
157
|
+
*
|
158
|
+
* Write lock for a region of a file
|
159
|
+
*/
|
160
|
+
rb_define_const(mFcntl, "F_WRLCK", INT2NUM(F_WRLCK));
|
161
|
+
#endif
|
162
|
+
#ifdef O_CREAT
|
163
|
+
/* Document-const: O_CREAT
|
164
|
+
*
|
165
|
+
* Create the file if it doesn't exist
|
166
|
+
*/
|
167
|
+
rb_define_const(mFcntl, "O_CREAT", INT2NUM(O_CREAT));
|
168
|
+
#endif
|
169
|
+
#ifdef O_EXCL
|
170
|
+
/* Document-const: O_EXCL
|
171
|
+
*
|
172
|
+
* Used with O_CREAT, fail if the file exists
|
173
|
+
*/
|
174
|
+
rb_define_const(mFcntl, "O_EXCL", INT2NUM(O_EXCL));
|
175
|
+
#endif
|
176
|
+
#ifdef O_NOCTTY
|
177
|
+
/* Document-const: O_NOCTTY
|
178
|
+
*
|
179
|
+
* Open TTY without it becoming the controlling TTY
|
180
|
+
*/
|
181
|
+
rb_define_const(mFcntl, "O_NOCTTY", INT2NUM(O_NOCTTY));
|
182
|
+
#endif
|
183
|
+
#ifdef O_TRUNC
|
184
|
+
/* Document-const: O_TRUNC
|
185
|
+
*
|
186
|
+
* Truncate the file on open
|
187
|
+
*/
|
188
|
+
rb_define_const(mFcntl, "O_TRUNC", INT2NUM(O_TRUNC));
|
189
|
+
#endif
|
190
|
+
#ifdef O_APPEND
|
191
|
+
/* Document-const: O_APPEND
|
192
|
+
*
|
193
|
+
* Open the file in append mode
|
194
|
+
*/
|
195
|
+
rb_define_const(mFcntl, "O_APPEND", INT2NUM(O_APPEND));
|
196
|
+
#endif
|
197
|
+
#ifdef O_NONBLOCK
|
198
|
+
/* Document-const: O_NONBLOCK
|
199
|
+
*
|
200
|
+
* Open the file in non-blocking mode
|
201
|
+
*/
|
202
|
+
rb_define_const(mFcntl, "O_NONBLOCK", INT2NUM(O_NONBLOCK));
|
203
|
+
#endif
|
204
|
+
#ifdef O_NDELAY
|
205
|
+
/* Document-const: O_NDELAY
|
206
|
+
*
|
207
|
+
* Open the file in non-blocking mode
|
208
|
+
*/
|
209
|
+
rb_define_const(mFcntl, "O_NDELAY", INT2NUM(O_NDELAY));
|
210
|
+
#endif
|
211
|
+
#ifdef O_RDONLY
|
212
|
+
/* Document-const: O_RDONLY
|
213
|
+
*
|
214
|
+
* Open the file in read-only mode
|
215
|
+
*/
|
216
|
+
rb_define_const(mFcntl, "O_RDONLY", INT2NUM(O_RDONLY));
|
217
|
+
#endif
|
218
|
+
#ifdef O_RDWR
|
219
|
+
/* Document-const: O_RDWR
|
220
|
+
*
|
221
|
+
* Open the file in read-write mode
|
222
|
+
*/
|
223
|
+
rb_define_const(mFcntl, "O_RDWR", INT2NUM(O_RDWR));
|
224
|
+
#endif
|
225
|
+
#ifdef O_WRONLY
|
226
|
+
/* Document-const: O_WRONLY
|
227
|
+
*
|
228
|
+
* Open the file in write-only mode.
|
229
|
+
*/
|
230
|
+
rb_define_const(mFcntl, "O_WRONLY", INT2NUM(O_WRONLY));
|
231
|
+
#endif
|
232
|
+
#ifdef O_ACCMODE
|
233
|
+
/* Document-const: O_ACCMODE
|
234
|
+
*
|
235
|
+
* Mask to extract the read/write flags
|
236
|
+
*/
|
237
|
+
rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_ACCMODE));
|
238
|
+
#else
|
239
|
+
/* Document-const: O_ACCMODE
|
240
|
+
*
|
241
|
+
* Mask to extract the read/write flags
|
242
|
+
*/
|
243
|
+
rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_RDONLY | O_WRONLY | O_RDWR));
|
244
|
+
#endif
|
245
|
+
}
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fcntl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yukihiro Matsumoto
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Loads constants defined in the OS fcntl.h C header file
|
56
|
+
email:
|
57
|
+
- matz@ruby-lang.org
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/fcntl/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ext/fcntl/extconf.rb
|
64
|
+
- ext/fcntl/fcntl.c
|
65
|
+
homepage: https://github.com/ruby/fcntl
|
66
|
+
licenses:
|
67
|
+
- BSD-2-Clause
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.5.0dev
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.6.12
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Loads constants defined in the OS fcntl.h C header file
|
89
|
+
test_files: []
|