ffi-stat 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffi-stat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adam Tanner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # FFI::Stat
2
+
3
+ FFI bindings for libc stat. The primary use of this library is by other FFI libraries that require a stat struct.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ffi-stat'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ffi-stat
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "ffi/stat"
23
+
24
+ file = "test.txt"
25
+ fd = $stdin.fileno
26
+
27
+ FFI::Stat.stat(file) #=> FFI::Stat::Stat
28
+ FFI::Stat.lstat(file) #=> FFI::Stat::Stat
29
+ FFI::Stat.fstat(fd) #=> FFI::Stat::Stat
30
+ ```
31
+
32
+ ## Platforms
33
+
34
+ Currently FFI::Stat has only been tested and known to work on Mac OS X Mountain Lion. Support for other OS platforms are on the roadmap.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/**/*_spec.rb"
6
+ end
7
+
8
+ task default: :test
data/ffi-stat.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ffi/stat/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ffi-stat"
8
+ gem.version = FFI::Stat::VERSION
9
+ gem.authors = ["Adam Tanner"]
10
+ gem.email = ["adam@adamtanner.org"]
11
+ gem.description = %q{FFI bindings for libc stat}
12
+ gem.summary = %q{FFI bindings for libc stat}
13
+ gem.homepage = "https://github.com/adamtanner/ffi-stat"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib/ffi"]
19
+
20
+ gem.add_dependency "ffi"
21
+
22
+ gem.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,12 @@
1
+ module FFI
2
+ module Stat
3
+ module Library
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+
7
+ attach_function :stat, [ :string, :pointer ], :int
8
+ attach_function :lstat, [ :string, :pointer ], :int
9
+ attach_function :fstat, [ :int, :pointer ], :int
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module FFI
2
+ module Stat
3
+ class Stat < FFI::Struct
4
+ layout :st_dev, :dev_t,
5
+ :st_ino, :ino_t,
6
+ :st_mode, :mode_t,
7
+ :st_nlink, :nlink_t,
8
+ :st_uid, :uid_t,
9
+ :st_gid, :gid_t,
10
+ :st_rdev, :dev_t,
11
+ :st_atimespec, FFI::Stat::Timespec,
12
+ :st_mtimespec, FFI::Stat::Timespec,
13
+ :st_ctimespec, FFI::Stat::Timespec,
14
+ :st_size, :off_t,
15
+ :st_blocks, :quad_t,
16
+ :st_blksize, :ulong,
17
+ :st_flags, :ulong,
18
+ :st_gen, :ulong
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ module FFI
2
+ module Stat
3
+ class Timespec < FFI::Struct
4
+ layout :tv_sec, :long,
5
+ :tv_nsec, :long
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module FFI
2
+ module Stat
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/ffi/stat.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "ffi"
2
+
3
+ require "ffi/stat/timespec"
4
+ require "ffi/stat/stat"
5
+ require "ffi/stat/library"
6
+
7
+ module FFI
8
+ module Stat
9
+ def self.stat(path)
10
+ stat_struct = FFI::Stat::Stat.new
11
+
12
+ FFI::Stat::Library.stat(path, stat_struct.pointer)
13
+
14
+ stat_struct
15
+ end
16
+
17
+ def self.lstat(path)
18
+ stat_struct = FFI::Stat::Stat.new
19
+
20
+ FFI::Stat::Library.lstat(path, stat_struct.pointer)
21
+
22
+ stat_struct
23
+ end
24
+
25
+ def self.fstat(fd)
26
+ stat_struct = FFI::Stat::Stat.new
27
+
28
+ FFI::Stat::Library.fstat(fd, stat_struct.pointer)
29
+
30
+ stat_struct
31
+ end
32
+ end
33
+ end
data/spec/stat_spec.rb ADDED
@@ -0,0 +1,82 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "ffi/stat"
4
+
5
+ describe FFI::Stat do
6
+ it "can stat a file" do
7
+ file = File.expand_path __FILE__
8
+
9
+ stat_struct = FFI::Stat.stat file
10
+
11
+ stat_struct[:st_dev ].wont_be_nil
12
+ stat_struct[:st_ino ].wont_be_nil
13
+ stat_struct[:st_mode ].wont_be_nil
14
+ stat_struct[:st_nlink ].wont_be_nil
15
+ stat_struct[:st_uid ].wont_be_nil
16
+ stat_struct[:st_gid ].wont_be_nil
17
+ stat_struct[:st_rdev ].wont_be_nil
18
+ stat_struct[:st_size ].wont_be_nil
19
+
20
+ stat_struct[:st_atimespec][:tv_sec ].wont_be_nil
21
+ stat_struct[:st_atimespec][:tv_nsec].wont_be_nil
22
+ stat_struct[:st_mtimespec][:tv_sec ].wont_be_nil
23
+ stat_struct[:st_mtimespec][:tv_nsec].wont_be_nil
24
+ stat_struct[:st_ctimespec][:tv_sec ].wont_be_nil
25
+ stat_struct[:st_ctimespec][:tv_nsec].wont_be_nil
26
+
27
+ stat_struct[:st_blksize ].wont_be_nil
28
+ stat_struct[:st_blocks ].wont_be_nil
29
+ end
30
+
31
+ it "can lstat a file" do
32
+ file = File.expand_path __FILE__
33
+
34
+ stat_struct = FFI::Stat.lstat file
35
+
36
+ stat_struct[:st_dev ].wont_be_nil
37
+ stat_struct[:st_ino ].wont_be_nil
38
+ stat_struct[:st_mode ].wont_be_nil
39
+ stat_struct[:st_nlink ].wont_be_nil
40
+ stat_struct[:st_uid ].wont_be_nil
41
+ stat_struct[:st_gid ].wont_be_nil
42
+ stat_struct[:st_rdev ].wont_be_nil
43
+ stat_struct[:st_size ].wont_be_nil
44
+
45
+ stat_struct[:st_atimespec][:tv_sec ].wont_be_nil
46
+ stat_struct[:st_atimespec][:tv_nsec].wont_be_nil
47
+ stat_struct[:st_mtimespec][:tv_sec ].wont_be_nil
48
+ stat_struct[:st_mtimespec][:tv_nsec].wont_be_nil
49
+ stat_struct[:st_ctimespec][:tv_sec ].wont_be_nil
50
+ stat_struct[:st_ctimespec][:tv_nsec].wont_be_nil
51
+
52
+ stat_struct[:st_blksize ].wont_be_nil
53
+ stat_struct[:st_blocks ].wont_be_nil
54
+ end
55
+
56
+ it "can fstat a file descriptor" do
57
+ file = File.open(__FILE__)
58
+
59
+ stat_struct = FFI::Stat.fstat file.fileno
60
+
61
+ stat_struct[:st_dev ].wont_be_nil
62
+ stat_struct[:st_ino ].wont_be_nil
63
+ stat_struct[:st_mode ].wont_be_nil
64
+ stat_struct[:st_nlink ].wont_be_nil
65
+ stat_struct[:st_uid ].wont_be_nil
66
+ stat_struct[:st_gid ].wont_be_nil
67
+ stat_struct[:st_rdev ].wont_be_nil
68
+ stat_struct[:st_size ].wont_be_nil
69
+
70
+ stat_struct[:st_atimespec][:tv_sec ].wont_be_nil
71
+ stat_struct[:st_atimespec][:tv_nsec].wont_be_nil
72
+ stat_struct[:st_mtimespec][:tv_sec ].wont_be_nil
73
+ stat_struct[:st_mtimespec][:tv_nsec].wont_be_nil
74
+ stat_struct[:st_ctimespec][:tv_sec ].wont_be_nil
75
+ stat_struct[:st_ctimespec][:tv_nsec].wont_be_nil
76
+
77
+ stat_struct[:st_blksize ].wont_be_nil
78
+ stat_struct[:st_blocks ].wont_be_nil
79
+
80
+ file.close
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-stat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Tanner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: FFI bindings for libc stat
47
+ email:
48
+ - adam@adamtanner.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - ffi-stat.gemspec
59
+ - lib/ffi/stat.rb
60
+ - lib/ffi/stat/library.rb
61
+ - lib/ffi/stat/stat.rb
62
+ - lib/ffi/stat/timespec.rb
63
+ - lib/ffi/stat/version.rb
64
+ - spec/stat_spec.rb
65
+ homepage: https://github.com/adamtanner/ffi-stat
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib/ffi
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: -4291905060190788636
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -4291905060190788636
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: FFI bindings for libc stat
95
+ test_files:
96
+ - spec/stat_spec.rb