Skip to content

Commit

Permalink
[Truffle] Update File.trucate to use errno.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed May 7, 2015
1 parent dc1de58 commit 440a90f
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ public int truncate(RubyString path, int length) {

@Specialization
public int truncate(RubyString path, long length) {
if (length < 0) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final int result = posix().truncate(pathString, length);
if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().invalidArgumentError(Long.toString(length), this));
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
return posix().truncate(pathString, length);
return result;
}

}
Expand Down

0 comments on commit 440a90f

Please sign in to comment.