Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for MRI 1.8.

  • Loading branch information...
commit a8f22f2596eb32646c110fc41ff5bf6d5b2d034f 1 parent 1cc3ae7
@pwnall authored
Showing with 38 additions and 13 deletions.
  1. +4 −13 lib/fallocate.rb
  2. +19 −0 lib/fallocate/18.rb
  3. +15 −0 lib/fallocate/19.rb
View
17 lib/fallocate.rb
@@ -9,18 +9,9 @@ module Fallocate
attach_function :posix_fallocate, [:int, :off_t, :off_t], :int
end
-class File
- # Ensures there is enough disk space for writing to a file.
- #
- # This method asks the filesystem to allocate disk blocks for a file region,
- # so that writes to that region will not fail due to out-of-space errors.
- #
- # @param [Integer] offset the 0-based offset of the region's starting byte
- # @param [Integer] length the region's length, in bytes
- def allocate(offset = 0, length)
- errno = Fallocate.posix_fallocate fileno, offset, length
- return if errno == 0
- raise SystemCallError.new(errno)
- end
+if RUBY_VERSION >= '1.9'
+ require 'fallocate/19.rb'
+else
+ require 'fallocate/18.rb'
end
View
19 lib/fallocate/18.rb
@@ -0,0 +1,19 @@
+class File
+ # Ensures there is enough disk space for writing to a file.
+ #
+ # This method asks the filesystem to allocate disk blocks for a file region,
+ # so that writes to that region will not fail due to out-of-space errors.
+ #
+ # @param [Integer] offset the 0-based offset of the region's starting byte
+ # @param [Integer] length the region's length, in bytes
+ def allocate(offset, length = nil)
+ unless length
+ length = offset
+ offset = 0
+ end
+
+ errno = Fallocate.posix_fallocate fileno, offset, length
+ return if errno == 0
+ raise SystemCallError.new(errno)
+ end
+end
View
15 lib/fallocate/19.rb
@@ -0,0 +1,15 @@
+class File
+ # Ensures there is enough disk space for writing to a file.
+ #
+ # This method asks the filesystem to allocate disk blocks for a file region,
+ # so that writes to that region will not fail due to out-of-space errors.
+ #
+ # @param [Integer] offset the 0-based offset of the region's starting byte
+ # @param [Integer] length the region's length, in bytes
+ def allocate(offset = 0, length)
+ errno = Fallocate.posix_fallocate fileno, offset, length
+ return if errno == 0
+ raise SystemCallError.new(errno)
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.