Browse files

fixed/improved some stuff

  • Loading branch information...
1 parent f11c3c8 commit 8b4ab410c07b15c5d85ed494036b39febe82a6dc rofl0r committed Aug 27, 2010
Showing with 12 additions and 24 deletions.
  1. +2 −1 sdk/io/Reader.ooc
  2. +1 −1 sdk/lang/Buffer.ooc
  3. +7 −20 sdk/os/FileDescriptor.ooc
  4. +2 −2 sdk/os/native/PipeWin32.ooc
View
3 sdk/io/Reader.ooc
@@ -31,9 +31,10 @@ Reader: abstract class {
rewinded once `end` has been read.
*/
readUntil: func (end: Char) -> String {
- sb := Buffer new(40) // let's be optimistic
+ sb := Buffer new(1024) // let's be pragmatic
while(hasNext?()) {
c := read()
+ // FIXME this behaviour would lead to errors when reading a binary file
// for some reason, some files end with the ASCII character 8, ie. BackSpace.
// we definitely don't want that to end up in the String.
if(c == end || (!hasNext?() && c == 8)) break
View
2 sdk/lang/Buffer.ooc
@@ -913,7 +913,7 @@ BufferReader: class extends Reader {
}
read: func(chars: Char*, offset: Int, count: Int) -> SizeT {
- copySize := buffer get(chars as Char* + offset, marker, count)
+ copySize := buffer get(chars + offset, marker, count)
marker += copySize
return copySize
}
View
27 sdk/os/FileDescriptor.ooc
@@ -4,28 +4,18 @@ include fcntl
import unistd
open: extern func(CString, Int) -> Int
-write: extern func(FileDescriptor, Pointer, Int) -> Int
-read: extern func(FileDescriptor, Pointer, Int) -> Int
-close: extern func(FileDescriptor) -> Int
+
STDIN_FILENO : extern FileDescriptor
STDOUT_FILENO: extern FileDescriptor
STDERR_FILENO: extern FileDescriptor
-FileDescriptor: cover from Int {
+// FIXME deprecated ? looks like an ancestor of File
- write: func(data: Pointer, len: Int) -> Int{
- result := write(this, data, len)
- //_errMsg(result, "write")
- return result
- }
+FileDescriptor: cover from Int {
write: func ~string (str: String) -> Int {
- write(str, str length())
- }
-
- read: func ~toBuf (buf: Pointer, len: Int) -> Int {
- read(this, buf, len)
+ write(str toCString(), str size)
}
read: func ~evilAlloc (len: Int) -> Pointer {
@@ -34,12 +24,9 @@ FileDescriptor: cover from Int {
return buf
}
- close: func() -> Int{
- result := close(this)
- //_errMsg(result, "close")
- return result
- }
-
+ write: extern(write) func(Pointer, Int) -> Int
+ read: extern(read) func(Pointer, Int) -> Int
+ close: extern(close) func -> Int
/*
dup2: func(fd: FileDescriptor) -> FileDescriptor {
return dup2(This, fd)
View
4 sdk/os/native/PipeWin32.ooc
@@ -46,7 +46,7 @@ PipeWin32: class extends Pipe {
}
// Don't try to read if there's no bytes ready atm
- if(totalBytesAvail == 0) return "" as Char*
+ if(totalBytesAvail == 0) return CString new (0)
// don't request more than there's available
bytesAsked := totalBytesAvail > bytesRequested ? bytesRequested : totalBytesAvail
@@ -56,7 +56,7 @@ PipeWin32: class extends Pipe {
if(!ReadFile(readFD, buffer, bytesAsked, bytesRead&, null)) {
if(GetLastError() == ERROR_HANDLE_EOF) {
// then it's okay
- return "\0" as Char*
+ return CString new(0)
}
Exception new(This, "Couldn't read pipe") throw()
}

0 comments on commit 8b4ab41

Please sign in to comment.