├── .rdoc_options ├── .document ├── ext └── fcntl │ ├── extconf.rb │ └── fcntl.c ├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── sync-ruby.yml │ └── push_gem.yml ├── bin ├── setup └── console ├── Gemfile ├── .gitignore ├── Rakefile ├── fcntl.gemspec ├── BSDL ├── README.md └── COPYING /.rdoc_options: -------------------------------------------------------------------------------- 1 | --- 2 | main_page: README.md 3 | -------------------------------------------------------------------------------- /.document: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.md 3 | ext/fcntl/*.[ch] 4 | -------------------------------------------------------------------------------- /ext/fcntl/extconf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | require 'mkmf' 3 | create_makefile('fcntl') 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: 'github-actions' 4 | directory: '/' 5 | schedule: 6 | interval: 'weekly' 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :development do 6 | gem "bundler" 7 | gem "rake" 8 | gem "rake-compiler" 9 | gem "rdoc" 10 | end 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /html/ 8 | /pkg/ 9 | /spec/reports/ 10 | /tmp/ 11 | *.so 12 | *.bundle 13 | *.dll 14 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "fcntl" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | name = "fcntl" 4 | 5 | require 'rake/extensiontask' 6 | extask = Rake::ExtensionTask.new(name) do |x| 7 | x.lib_dir << "/#{RUBY_VERSION}/#{x.platform}" 8 | end 9 | 10 | require "rdoc/task" 11 | RDoc::Task.new do |rdoc| 12 | File.read(File.join(__dir__, ".document")).gsub(/#.*/, "").split.each do |pattern| 13 | rdoc.rdoc_files.concat(Dir.glob(pattern, base: __dir__)) 14 | end 15 | end 16 | 17 | task :default => :compile 18 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ruby-versions: 7 | uses: ruby/actions/.github/workflows/ruby_versions.yml@master 8 | with: 9 | engine: cruby 10 | min_version: 2.5 11 | 12 | test: 13 | needs: ruby-versions 14 | name: build (${{ matrix.ruby }} / ${{ matrix.os }}) 15 | strategy: 16 | matrix: 17 | ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }} 18 | os: [ ubuntu-latest, macos-latest ] 19 | exclude: 20 | - { os: macos-latest, ruby: 2.5 } 21 | runs-on: ${{ matrix.os }} 22 | steps: 23 | - uses: actions/checkout@v6.0.1 24 | - name: Set up Ruby 25 | uses: ruby/setup-ruby@v1 26 | with: 27 | ruby-version: ${{ matrix.ruby }} 28 | bundler-cache: true 29 | - name: Run test 30 | run: bundle exec rake compile 31 | -------------------------------------------------------------------------------- /.github/workflows/sync-ruby.yml: -------------------------------------------------------------------------------- 1 | name: Sync ruby 2 | on: 3 | push: 4 | branches: [master] 5 | jobs: 6 | sync: 7 | name: Sync ruby 8 | runs-on: ubuntu-latest 9 | if: ${{ github.repository_owner == 'ruby' }} 10 | steps: 11 | - uses: actions/checkout@v6.0.1 12 | 13 | - name: Create GitHub App token 14 | id: app-token 15 | uses: actions/create-github-app-token@v2 16 | with: 17 | app-id: 2060836 18 | private-key: ${{ secrets.RUBY_SYNC_DEFAULT_GEMS_PRIVATE_KEY }} 19 | owner: ruby 20 | repositories: ruby 21 | 22 | - name: Sync to ruby/ruby 23 | uses: convictional/trigger-workflow-and-wait@v1.6.5 24 | with: 25 | owner: ruby 26 | repo: ruby 27 | workflow_file_name: sync_default_gems.yml 28 | github_token: ${{ steps.app-token.outputs.token }} 29 | ref: master 30 | client_payload: | 31 | {"gem":"${{ github.event.repository.name }}","before":"${{ github.event.before }}","after":"${{ github.event.after }}"} 32 | propagate_failure: true 33 | wait_interval: 10 34 | -------------------------------------------------------------------------------- /fcntl.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # frozen_string_literal: true 3 | 4 | source_version = ["", "ext/fcntl/"].find do |dir| 5 | begin 6 | break File.open(File.join(__dir__, "#{dir}fcntl.c")) {|f| 7 | f.gets("\n#define FCNTL_VERSION ") 8 | f.gets[/\s*"(.+)"/, 1] 9 | } 10 | rescue Errno::ENOENT 11 | end 12 | end 13 | 14 | Gem::Specification.new do |spec| 15 | spec.name = "fcntl" 16 | spec.version = source_version 17 | spec.authors = ["Yukihiro Matsumoto"] 18 | spec.email = ["matz@ruby-lang.org"] 19 | 20 | spec.summary = "Loads constants defined in the OS fcntl.h C header file" 21 | spec.description = "Loads constants defined in the OS fcntl.h C header file" 22 | spec.homepage = "https://github.com/ruby/fcntl" 23 | spec.licenses = ["Ruby", "BSD-2-Clause"] 24 | 25 | spec.files = ["ext/fcntl/extconf.rb", "ext/fcntl/fcntl.c"] 26 | spec.extra_rdoc_files = [".document", ".rdoc_options", "BSDL", "COPYING", "README.md"] 27 | spec.bindir = "exe" 28 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 29 | spec.require_paths = ["lib"] 30 | spec.extensions = "ext/fcntl/extconf.rb" 31 | spec.required_ruby_version = ">= 2.5.0" 32 | end 33 | -------------------------------------------------------------------------------- /.github/workflows/push_gem.yml: -------------------------------------------------------------------------------- 1 | name: Publish gem to rubygems.org 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | push: 13 | if: github.repository == 'ruby/fcntl' 14 | runs-on: ubuntu-latest 15 | 16 | environment: 17 | name: rubygems.org 18 | url: https://rubygems.org/gems/fcntl 19 | 20 | permissions: 21 | contents: write 22 | id-token: write 23 | 24 | steps: 25 | - name: Harden Runner 26 | uses: step-security/harden-runner@df199fb7be9f65074067a9eb93f12bb4c5547cf2 # v2.13.3 27 | with: 28 | egress-policy: audit 29 | 30 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v5.0.1 31 | 32 | - name: Set up Ruby 33 | uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0 34 | with: 35 | bundler-cache: true 36 | ruby-version: ruby 37 | 38 | - name: Publish to RubyGems 39 | uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2 40 | 41 | - name: Create GitHub release 42 | run: | 43 | tag_name="$(git describe --tags --abbrev=0)" 44 | gh release create "${tag_name}" --verify-tag --generate-notes 45 | env: 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | -------------------------------------------------------------------------------- /BSDL: -------------------------------------------------------------------------------- 1 | Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 | SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fcntl 2 | 3 | Fcntl loads the constants defined in the system's `` C header file, and used with both the fcntl(2) and open(2) POSIX system calls. 4 | 5 | * To perform a fcntl(2) operation, use IO::fcntl. 6 | * To perform an open(2) operation, use IO::sysopen. 7 | 8 | The set of operations and constants available depends upon specific operating system. Some values listed below may not be supported on your system. 9 | 10 | See your fcntl(2) man page for complete details. 11 | 12 | ## Installation 13 | 14 | Add this line to your application's Gemfile: 15 | 16 | ```ruby 17 | gem 'fcntl' 18 | ``` 19 | 20 | And then execute: 21 | 22 | $ bundle 23 | 24 | Or install it yourself as: 25 | 26 | $ gem install fcntl 27 | 28 | ## Usage 29 | 30 | Open `/tmp/tempfile` as a write-only file that is created if it doesn't 31 | exist: 32 | 33 | ```ruby 34 | require 'fcntl' 35 | 36 | fd = IO.sysopen('/tmp/tempfile', 37 | Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) 38 | f = IO.open(fd) 39 | f.syswrite("TEMP DATA") 40 | f.close 41 | ``` 42 | 43 | Get the flags on file `s`: 44 | 45 | ```ruby 46 | m = s.fcntl(Fcntl::F_GETFL, 0) 47 | ``` 48 | 49 | Set the non-blocking flag on `f` in addition to the existing flags in `m`. 50 | 51 | ```ruby 52 | f.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK|m) 53 | ``` 54 | 55 | ## Development 56 | 57 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 58 | 59 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 60 | 61 | ## Contributing 62 | 63 | Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/fcntl. 64 | 65 | 66 | ## License 67 | 68 | The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause). 69 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Ruby is copyrighted free software by Yukihiro Matsumoto . 2 | You can redistribute it and/or modify it under either the terms of the 3 | 2-clause BSDL (see the file BSDL), or the conditions below: 4 | 5 | 1. You may make and give away verbatim copies of the source form of the 6 | software without restriction, provided that you duplicate all of the 7 | original copyright notices and associated disclaimers. 8 | 9 | 2. You may modify your copy of the software in any way, provided that 10 | you do at least ONE of the following: 11 | 12 | a. place your modifications in the Public Domain or otherwise 13 | make them Freely Available, such as by posting said 14 | modifications to Usenet or an equivalent medium, or by allowing 15 | the author to include your modifications in the software. 16 | 17 | b. use the modified software only within your corporation or 18 | organization. 19 | 20 | c. give non-standard binaries non-standard names, with 21 | instructions on where to get the original software distribution. 22 | 23 | d. make other distribution arrangements with the author. 24 | 25 | 3. You may distribute the software in object code or binary form, 26 | provided that you do at least ONE of the following: 27 | 28 | a. distribute the binaries and library files of the software, 29 | together with instructions (in the manual page or equivalent) 30 | on where to get the original distribution. 31 | 32 | b. accompany the distribution with the machine-readable source of 33 | the software. 34 | 35 | c. give non-standard binaries non-standard names, with 36 | instructions on where to get the original software distribution. 37 | 38 | d. make other distribution arrangements with the author. 39 | 40 | 4. You may modify and include the part of the software into any other 41 | software (possibly commercial). But some files in the distribution 42 | are not written by the author, so that they are not under these terms. 43 | 44 | For the list of those files and their copying conditions, see the 45 | file LEGAL. 46 | 47 | 5. The scripts and library files supplied as input to or produced as 48 | output from the software do not automatically fall under the 49 | copyright of the software, but belong to whomever generated them, 50 | and may be sold commercially, and may be aggregated with this 51 | software. 52 | 53 | 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 54 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 55 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 56 | PURPOSE. 57 | -------------------------------------------------------------------------------- /ext/fcntl/fcntl.c: -------------------------------------------------------------------------------- 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 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 30 | 31 | /* 32 | * Document-module: Fcntl 33 | * 34 | * Fcntl loads the constants defined in the system's C header 35 | * file, and used with both the fcntl(2) and open(2) POSIX system calls. 36 | * 37 | * To perform a fcntl(2) operation, use IO::fcntl. 38 | * 39 | * To perform an open(2) operation, use IO::sysopen. 40 | * 41 | * The set of operations and constants available depends upon specific 42 | * operating system. Some values listed below may not be supported on your 43 | * system. 44 | * 45 | * See your fcntl(2) man page for complete details. 46 | * 47 | * Open /tmp/tempfile as a write-only file that is created if it doesn't 48 | * exist: 49 | * 50 | * require 'fcntl' 51 | * 52 | * fd = IO.sysopen('/tmp/tempfile', 53 | * Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) 54 | * f = IO.open(fd) 55 | * f.syswrite("TEMP DATA") 56 | * f.close 57 | * 58 | * Get the flags on file +s+: 59 | * 60 | * m = s.fcntl(Fcntl::F_GETFL, 0) 61 | * 62 | * Set the non-blocking flag on +f+ in addition to the existing flags in +m+. 63 | * 64 | * f.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK|m) 65 | * 66 | */ 67 | 68 | #define FCNTL_VERSION "1.3.0" 69 | 70 | void 71 | Init_fcntl(void) 72 | { 73 | VALUE mFcntl = rb_define_module("Fcntl"); 74 | 75 | /* The version string. */ 76 | rb_define_const(mFcntl, "VERSION", rb_str_new_cstr(FCNTL_VERSION)); 77 | 78 | #ifdef F_DUPFD 79 | /* 80 | * Duplicate a file descriptor to the minimum unused file descriptor 81 | * greater than or equal to the argument. 82 | * 83 | * The close-on-exec flag of the duplicated file descriptor is set. 84 | * (Ruby uses F_DUPFD_CLOEXEC internally if available to avoid race 85 | * condition. F_SETFD is used if F_DUPFD_CLOEXEC is not available.) 86 | */ 87 | rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD)); 88 | #endif 89 | #ifdef F_GETFD 90 | /* 91 | * Read the close-on-exec flag of a file descriptor. 92 | */ 93 | rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD)); 94 | #endif 95 | #ifdef F_GETLK 96 | /* 97 | * Determine whether a given region of a file is locked. This uses one of 98 | * the F_*LK flags. 99 | */ 100 | rb_define_const(mFcntl, "F_GETLK", INT2NUM(F_GETLK)); 101 | #endif 102 | #ifdef F_SETFD 103 | /* 104 | * Set the close-on-exec flag of a file descriptor. 105 | */ 106 | rb_define_const(mFcntl, "F_SETFD", INT2NUM(F_SETFD)); 107 | #endif 108 | #ifdef F_GETFL 109 | /* 110 | * Get the file descriptor flags. This will be one or more of the O_* 111 | * flags. 112 | */ 113 | rb_define_const(mFcntl, "F_GETFL", INT2NUM(F_GETFL)); 114 | #endif 115 | #ifdef F_SETFL 116 | /* 117 | * Set the file descriptor flags. This will be one or more of the O_* 118 | * flags. 119 | */ 120 | rb_define_const(mFcntl, "F_SETFL", INT2NUM(F_SETFL)); 121 | #endif 122 | #ifdef F_SETLK 123 | /* 124 | * Acquire a lock on a region of a file. This uses one of the F_*LCK 125 | * flags. 126 | */ 127 | rb_define_const(mFcntl, "F_SETLK", INT2NUM(F_SETLK)); 128 | #endif 129 | #ifdef F_SETLKW 130 | /* 131 | * Acquire a lock on a region of a file, waiting if necessary. This uses 132 | * one of the F_*LCK flags 133 | */ 134 | rb_define_const(mFcntl, "F_SETLKW", INT2NUM(F_SETLKW)); 135 | #endif 136 | #ifdef FD_CLOEXEC 137 | /* 138 | * the value of the close-on-exec flag. 139 | */ 140 | rb_define_const(mFcntl, "FD_CLOEXEC", INT2NUM(FD_CLOEXEC)); 141 | #endif 142 | #ifdef 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 | /* 150 | * Remove lock for a region of a file 151 | */ 152 | rb_define_const(mFcntl, "F_UNLCK", INT2NUM(F_UNLCK)); 153 | #endif 154 | #ifdef F_WRLCK 155 | /* 156 | * Write lock for a region of a file 157 | */ 158 | rb_define_const(mFcntl, "F_WRLCK", INT2NUM(F_WRLCK)); 159 | #endif 160 | #ifdef F_SETPIPE_SZ 161 | /* 162 | * Change the capacity of the pipe referred to by fd to be at least arg bytes. 163 | */ 164 | rb_define_const(mFcntl, "F_SETPIPE_SZ", INT2NUM(F_SETPIPE_SZ)); 165 | #endif 166 | #ifdef F_GETPIPE_SZ 167 | /* 168 | * Return (as the function result) the capacity of the pipe referred to by fd. 169 | */ 170 | rb_define_const(mFcntl, "F_GETPIPE_SZ", INT2NUM(F_GETPIPE_SZ)); 171 | #endif 172 | #ifdef O_CREAT 173 | /* 174 | * Create the file if it doesn't exist 175 | */ 176 | rb_define_const(mFcntl, "O_CREAT", INT2NUM(O_CREAT)); 177 | #endif 178 | #ifdef O_EXCL 179 | /* 180 | * Used with O_CREAT, fail if the file exists 181 | */ 182 | rb_define_const(mFcntl, "O_EXCL", INT2NUM(O_EXCL)); 183 | #endif 184 | #ifdef O_NOCTTY 185 | /* 186 | * Open TTY without it becoming the controlling TTY 187 | */ 188 | rb_define_const(mFcntl, "O_NOCTTY", INT2NUM(O_NOCTTY)); 189 | #endif 190 | #ifdef O_TRUNC 191 | /* 192 | * Truncate the file on open 193 | */ 194 | rb_define_const(mFcntl, "O_TRUNC", INT2NUM(O_TRUNC)); 195 | #endif 196 | #ifdef O_APPEND 197 | /* 198 | * Open the file in append mode 199 | */ 200 | rb_define_const(mFcntl, "O_APPEND", INT2NUM(O_APPEND)); 201 | #endif 202 | #ifdef O_NONBLOCK 203 | /* 204 | * Open the file in non-blocking mode 205 | */ 206 | rb_define_const(mFcntl, "O_NONBLOCK", INT2NUM(O_NONBLOCK)); 207 | #endif 208 | #ifdef O_NDELAY 209 | /* 210 | * Open the file in non-blocking mode 211 | */ 212 | rb_define_const(mFcntl, "O_NDELAY", INT2NUM(O_NDELAY)); 213 | #endif 214 | #ifdef O_RDONLY 215 | /* 216 | * Open the file in read-only mode 217 | */ 218 | rb_define_const(mFcntl, "O_RDONLY", INT2NUM(O_RDONLY)); 219 | #endif 220 | #ifdef O_RDWR 221 | /* 222 | * Open the file in read-write mode 223 | */ 224 | rb_define_const(mFcntl, "O_RDWR", INT2NUM(O_RDWR)); 225 | #endif 226 | #ifdef 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 | #ifndef O_ACCMODE 233 | int O_ACCMODE = (O_RDONLY | O_WRONLY | O_RDWR); 234 | #endif 235 | /* 236 | * Mask to extract the read/write flags 237 | */ 238 | rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_ACCMODE)); 239 | #ifdef F_DUP2FD 240 | /* 241 | * It is a FreeBSD specific constant and equivalent 242 | * to dup2 call. 243 | */ 244 | rb_define_const(mFcntl, "F_DUP2FD", INT2NUM(F_DUP2FD)); 245 | #endif 246 | #ifdef F_DUP2FD_CLOEXEC 247 | /* 248 | * It is a FreeBSD specific constant and acts 249 | * similarly as F_DUP2FD but set the FD_CLOEXEC 250 | * flag in addition. 251 | */ 252 | rb_define_const(mFcntl, "F_DUP2FD_CLOEXEC", INT2NUM(F_DUP2FD_CLOEXEC)); 253 | #endif 254 | 255 | #ifdef F_PREALLOCATE 256 | /* 257 | * macOS specific flag used for preallocating file space. 258 | */ 259 | rb_define_const(mFcntl, "F_PREALLOCATE", INT2NUM(F_PREALLOCATE)); 260 | #endif 261 | 262 | #ifdef F_ALLOCATECONTIG 263 | /* 264 | * macOS specific flag used with F_PREALLOCATE for allocating contiguous 265 | * space. 266 | */ 267 | rb_define_const(mFcntl, "F_ALLOCATECONTIG", INT2NUM(F_ALLOCATECONTIG)); 268 | #endif 269 | 270 | #ifdef F_ALLOCATEALL 271 | /* 272 | * macOS specific flag used with F_PREALLOCATE for allocating all contiguous 273 | * space or no space. 274 | */ 275 | rb_define_const(mFcntl, "F_ALLOCATEALL", INT2NUM(F_ALLOCATEALL)); 276 | #endif 277 | 278 | #ifdef F_ALLOCATEPERSIST 279 | /* 280 | * macOS specific flag used with F_PREALLOCATE. Allocate space that is not 281 | * freed when close is called. 282 | */ 283 | rb_define_const(mFcntl, "F_ALLOCATEPERSIST", INT2NUM(F_ALLOCATEPERSIST)); 284 | #endif 285 | 286 | #ifdef F_PEOFPOSMODE 287 | /* 288 | * macOS specific flag used with F_PREALLOCATE. Allocate from the physical 289 | * end of file 290 | */ 291 | rb_define_const(mFcntl, "F_PEOFPOSMODE", INT2NUM(F_PEOFPOSMODE)); 292 | #endif 293 | 294 | #ifdef F_VOLPOSMODE 295 | /* 296 | * macOS specific flag used with F_PREALLOCATE. Allocate from the volume offset. 297 | */ 298 | rb_define_const(mFcntl, "F_VOLPOSMODE", INT2NUM(F_VOLPOSMODE)); 299 | #endif 300 | } 301 | --------------------------------------------------------------------------------