ffi-stat 0.0.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75578daf5dd9e3def32adfd97911183fd408b0fc
4
+ data.tar.gz: d00f4b82dc49410d44f09fd9875ffe0573148f63
5
+ SHA512:
6
+ metadata.gz: cb571d9904734efc83355fb4f9f40dcea233f3628bc1b921675da2e18addbee03ec15cefa59c9c99e909d65a8258325968616ef46db9473f08738a23201de02f
7
+ data.tar.gz: 7a6f5f8486c2113280e509a9183d99737a6d193974a7b2aef55b4166ab77b229b47e807144be472448708c2a9bdce431fa43a3600b87803524b3e0ad023939d2
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # FFI::Stat
2
2
 
3
- FFI bindings for libc stat. The primary use of this library is by other FFI libraries that require a stat struct.
3
+ FFI platform-specific bindings for the stat struct and related functions. The
4
+ primary use case of this library is assist other FFI libraries that require a
5
+ stat struct.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'ffi-stat'
11
+ gem "ffi-stat"
10
12
 
11
13
  And then execute:
12
14
 
@@ -24,19 +26,25 @@ require "ffi/stat"
24
26
  file = "test.txt"
25
27
  fd = $stdin.fileno
26
28
 
27
- FFI::Stat.stat(file) #=> FFI::Stat::Stat
28
- FFI::Stat.lstat(file) #=> FFI::Stat::Stat
29
- FFI::Stat.fstat(fd) #=> FFI::Stat::Stat
29
+ if FFI::Platform.is_os("darwin")
30
+ FFI::Stat.stat(file) #=> FFI::Stat::Stat
31
+ FFI::Stat.lstat(file) #=> FFI::Stat::Stat
32
+ FFI::Stat.fstat(fd) #=> FFI::Stat::Stat
33
+ end
30
34
  ```
31
35
 
32
36
  ## Platforms
33
37
 
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.
38
+ FFI::Stat has support for the stat struct on the following platforms:
39
+
40
+ * x86_64-darwin
41
+ * x86_64-linux
35
42
 
36
43
  ## Contributing
37
44
 
38
45
  1. Fork it
39
46
  2. Create your feature branch (`git checkout -b my-new-feature`)
40
47
  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
48
+ 4. Ensure all tests pass (`rake test`)
49
+ 5. Push to the branch (`git push origin my-new-feature`)
50
+ 6. Create new Pull Request
data/ffi-stat.gemspec CHANGED
@@ -1,23 +1,23 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ffi/stat/version'
5
4
 
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"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ffi-stat"
7
+ spec.version = "0.2.0"
8
+ spec.authors = ["Adam Tanner"]
9
+ spec.email = ["adam@adamtanner.org"]
10
+ spec.description = %q{ Ruby FFI bindings for stat }
11
+ spec.summary = %q{ Ruby FFI bindings for stat }
12
+ spec.homepage = "https://github.com/adamtanner/ffi-stat"
13
+ spec.license = "MIT"
14
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"]
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "ffi"
21
-
22
- gem.add_development_dependency "rake"
20
+ spec.add_dependency "ffi"
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
23
  end
@@ -0,0 +1,58 @@
1
+ module FFI::Stat
2
+ module Native
3
+ extend FFI::Library
4
+
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
+
12
+ class Timespec < FFI::Struct
13
+ layout :tv_sec, :time_t,
14
+ :tv_nsec, :long
15
+ end
16
+
17
+ class Stat < FFI::Struct
18
+ layout :st_dev, :dev_t,
19
+ :st_ino, :uint32,
20
+ :st_mode, :mode_t,
21
+ :st_nlink, :nlink_t,
22
+ :st_uid, :uid_t,
23
+ :st_gid, :gid_t,
24
+ :st_rdev, :dev_t,
25
+ :st_atimespec, FFI::Stat::Timespec,
26
+ :st_mtimespec, FFI::Stat::Timespec,
27
+ :st_ctimespec, FFI::Stat::Timespec,
28
+ :st_size, :off_t,
29
+ :st_blocks, :blkcnt_t,
30
+ :st_blksize, :blksize_t,
31
+ :st_flags, :uint32,
32
+ :st_gen, :uint32
33
+ end
34
+
35
+ def self.stat(path)
36
+ stat = FFI::Stat::Stat.new
37
+
38
+ FFI::Stat::Native.stat(path, stat.pointer)
39
+
40
+ stat
41
+ end
42
+
43
+ def self.lstat(path)
44
+ stat = FFI::Stat::Stat.new
45
+
46
+ FFI::Stat::Native.lstat(path, stat.pointer)
47
+
48
+ stat
49
+ end
50
+
51
+ def self.fstat(fd)
52
+ stat = FFI::Stat::Stat.new
53
+
54
+ FFI::Stat::Native.fstat(fd, stat.pointer)
55
+
56
+ stat
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ module FFI::Stat
2
+ class Timespec < FFI::Struct
3
+ layout :tv_sec, :time_t,
4
+ :tv_nsec, :long
5
+ end
6
+
7
+ class Stat < FFI::Struct
8
+ layout :st_dev, :dev_t,
9
+ :st_ino, :ino_t,
10
+ :st_nlink, :nlink_t,
11
+ :st_mode, :mode_t,
12
+ :st_uid, :uid_t,
13
+ :st_gid, :gid_t,
14
+ :__pad0, :int,
15
+ :st_rdev, :dev_t,
16
+ :st_size, :off_t,
17
+ :st_blksize, :blksize_t,
18
+ :st_blocks, :blkcnt_t,
19
+ :st_atimespec, FFI::Stat::Timespec,
20
+ :st_mtimespec, FFI::Stat::Timespec,
21
+ :st_ctimespec, FFI::Stat::Timespec
22
+ end
23
+ end
data/lib/ffi/stat.rb CHANGED
@@ -1,33 +1,6 @@
1
1
  require "ffi"
2
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
3
+ module FFI::Stat
33
4
  end
5
+
6
+ require "ffi/stat/#{FFI::Platform::NAME}/stat"
data/spec/stat_spec.rb CHANGED
@@ -4,79 +4,21 @@ require "ffi/stat"
4
4
 
5
5
  describe FFI::Stat do
6
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
7
+ skip unless FFI::Stat.respond_to?(:stat)
8
+
9
+ ffi_stat = FFI::Stat.stat(__FILE__)
10
+ rb_stat = File.stat(__FILE__)
11
+
12
+ ffi_stat[:st_dev].must_equal(rb_stat.dev)
13
+ ffi_stat[:st_ino].must_equal(rb_stat.ino)
14
+ ffi_stat[:st_mode].must_equal(rb_stat.mode)
15
+ ffi_stat[:st_nlink].must_equal(rb_stat.nlink)
16
+ ffi_stat[:st_uid].must_equal(rb_stat.uid)
17
+ ffi_stat[:st_gid].must_equal(rb_stat.gid)
18
+ ffi_stat[:st_rdev].must_equal(rb_stat.rdev)
19
+
20
+ ffi_stat[:st_size].must_equal(rb_stat.size)
21
+ ffi_stat[:st_blksize].must_equal(rb_stat.blksize)
22
+ ffi_stat[:st_blocks].must_equal(rb_stat.blocks)
81
23
  end
82
24
  end
metadata CHANGED
@@ -1,49 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Tanner
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-03 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
- description: FFI bindings for libc stat
55
+ description: ' Ruby FFI bindings for stat '
47
56
  email:
48
57
  - adam@adamtanner.org
49
58
  executables: []
@@ -57,40 +66,32 @@ files:
57
66
  - Rakefile
58
67
  - ffi-stat.gemspec
59
68
  - 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
69
+ - lib/ffi/stat/x86_64-darwin/stat.rb
70
+ - lib/ffi/stat/x86_64-linux/stat.rb
64
71
  - spec/stat_spec.rb
65
72
  homepage: https://github.com/adamtanner/ffi-stat
66
- licenses: []
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
67
76
  post_install_message:
68
77
  rdoc_options: []
69
78
  require_paths:
70
79
  - lib
71
80
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
81
  requirements:
74
- - - ! '>='
82
+ - - '>='
75
83
  - !ruby/object:Gem::Version
76
84
  version: '0'
77
- segments:
78
- - 0
79
- hash: -3092432383365459650
80
85
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ! '>='
87
+ - - '>='
84
88
  - !ruby/object:Gem::Version
85
89
  version: '0'
86
- segments:
87
- - 0
88
- hash: -3092432383365459650
89
90
  requirements: []
90
91
  rubyforge_project:
91
- rubygems_version: 1.8.23
92
+ rubygems_version: 2.0.3
92
93
  signing_key:
93
- specification_version: 3
94
- summary: FFI bindings for libc stat
94
+ specification_version: 4
95
+ summary: Ruby FFI bindings for stat
95
96
  test_files:
96
97
  - spec/stat_spec.rb
@@ -1,12 +0,0 @@
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
data/lib/ffi/stat/stat.rb DELETED
@@ -1,21 +0,0 @@
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
@@ -1,8 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- module FFI
2
- module Stat
3
- VERSION = "0.0.2"
4
- end
5
- end