Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit dd8d0c8dd5fbc36aafb95c1db4ca44fb74542f63 0 parents
Postmodern authored
4 .gitignore
@@ -0,0 +1,4 @@
+doc
+pkg
+.bundle
+.yardoc
1  .specopts
@@ -0,0 +1 @@
+--colour --format specdoc
1  .yardopts
@@ -0,0 +1 @@
+--markup markdown --title 'FFI LibC Documentation' --protected --files ChangeLog.md,LICENSE.txt
4 ChangeLog.md
@@ -0,0 +1,4 @@
+### 0.1.0 / 2010-05-18
+
+* Initial release.
+
24 Gemfile
@@ -0,0 +1,24 @@
+source 'http://rubygems.org'
+
+group :runtime do
+ gem 'ffi', '~> 0.6.0'
+end
+
+group :development do
+ gem 'bundler', '~> 0.9.25'
+ gem 'rake', '~> 0.8.7'
+ gem 'jeweler', '~> 1.4.0', :git => 'git://github.com/technicalpickles/jeweler.git'
+end
+
+group :doc do
+ case RUBY_PLATFORM
+ when 'java'
+ gem 'maruku', '~> 0.6.0'
+ else
+ gem 'rdiscount', '~> 1.6.3'
+ end
+
+ gem 'yard', '~> 0.5.3'
+end
+
+gem 'rspec', '~> 1.3.0', :group => [:development, :test]
23 LICENSE.txt
@@ -0,0 +1,23 @@
+
+The MIT License
+
+Copyright (c) 2010 Hal Brodigan
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 README.md
@@ -0,0 +1,26 @@
+# ffi-libc
+
+* [github.com/postmodern/ffi-libc](http://github.com/postmodern/ffi-libc/)
+* [github.com/postmodern/ffi-libc/issues](http://github.com/postmodern/ffi-libc/issues)
+* Postmodern (postmodern.mod3 at gmail.com)
+
+## Description
+
+Useful Ruby FFI bindings for `libc`.
+
+## Features
+
+## Examples
+
+## Requirements
+
+* [ffi](http://github.com/ffi/ffi) >= 0.6.0
+
+## Install
+
+ $ sudo gem install ffi-libc
+
+## License
+
+See {file:LICENSE.txt} for license information.
+
39 Rakefile
@@ -0,0 +1,39 @@
+require 'rubygems'
+require 'bundler'
+
+begin
+ Bundler.setup(:development, :doc)
+rescue Bundler::BundlerError => e
+ STDERR.puts e.message
+ STDERR.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+
+require 'rake'
+require 'rake/clean'
+require 'jeweler'
+
+Jeweler::Tasks.new do |gem|
+ gem.name = 'ffi-libc'
+ gem.licenses = ['MIT']
+ gem.summary = %Q{Useful FFI bindings for libc}
+ gem.email = 'postmodern.mod3@gmail.com'
+ gem.homepage = %Q{http://github.com/postmodern/ffi-libc}
+ gem.description = %Q{Useful Ruby FFI bindings for libc.}
+ gem.authors = ['Postmodern']
+ gem.add_development_dependency 'bundler', '~> 0.9.23'
+ gem.has_rdoc = 'yard'
+end
+
+require 'spec/rake/spectask'
+
+desc "Run all specifications"
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs += ['lib', 'spec']
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+ spec.spec_opts = ['--options', '.specopts']
+end
+task :default => :spec
+
+require 'yard'
+YARD::Rake::YardocTask.new
1  VERSION
@@ -0,0 +1 @@
+0.1.0
2  lib/ffi/libc.rb
@@ -0,0 +1,2 @@
+require 'ffi/libc/types'
+require 'ffi/libc/libc'
54 lib/ffi/libc/libc.rb
@@ -0,0 +1,54 @@
+require 'ffi/libc/types'
+
+require 'ffi'
+
+module FFI
+ module LibC
+ extend FFI::Library
+
+ ffi_lib 'c'
+
+ # errno.h
+ attach_variable :sys_errlist, :pointer
+ attach_variable :sys_nerr, :int
+ attach_variable :errno, :int
+
+ # string.h
+ attach_function :bzero, [:pointer, :size_t], :void
+ attach_function :memset, [:pointer, :int, :size_t], :pointer
+ attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
+ attach_function :memcmp, [:pointer, :pointer, :size_t], :int
+ attach_function :memchr, [:pointer, :int, :size_t], :pointer
+ attach_function :memrchr, [:pointer, :int, :size_t], :pointer
+ attach_function :strcpy, [:string, :string], :pointer
+ attach_function :strncpy, [:string, :string, :size_t], :pointer
+ attach_function :strlen, [:string], :size_t
+ attach_function :index, [:string, :int], :string
+ attach_function :rindex, [:string, :int], :string
+ attach_function :strchr, [:string, :int], :string
+ attach_function :strrchr, [:string, :int], :string
+ attach_function :strstr, [:string, :string], :string
+ attach_function :strerror, [:int], :string
+
+ # stdio.h
+ attach_function :fopen, [:string, :string], :FILE
+ attach_function :fdopen, [:int, :string], :FILE
+ attach_function :freopen, [:string, :string, :FILE], :FILE
+ attach_function :fseek, [:FILE, :long, :int], :int
+ attach_function :ftell, [:FILE], :long
+ attach_function :rewind, [:FILE], :void
+ attach_function :fread, [:pointer, :size_t, :size_t, :FILE], :size_t
+ attach_function :fwrite, [:pointer, :size_t, :size_t, :FILE], :size_t
+ attach_function :fgetc, [:FILE], :int
+ attach_function :fgets, [:pointer, :int, :FILE], :pointer
+ attach_function :fputc, [:int, :FILE], :int
+ attach_function :fputs, [:string, :FILE], :int
+ attach_function :fflush, [:FILE], :int
+ attach_function :fclose, [:FILE], :int
+ attach_function :clearerr, [:FILE], :void
+ attach_function :feof, [:FILE], :int
+ attach_function :ferror, [:FILE], :int
+ attach_function :fileno, [:FILE], :int
+ attach_function :perror, [:string], :void
+ end
+end
11 lib/ffi/libc/types.rb
@@ -0,0 +1,11 @@
+require 'ffi'
+
+module FFI
+ module LibC
+ extend FFI::Library
+
+ typedef :uint, :size_t
+ typedef :int, :ssize_t
+ typedef :pointer, :FILE
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.