Add pwd utility and performance to cat
This commit is contained in:
parent
049289f452
commit
2f6f90dce4
4 changed files with 23 additions and 5 deletions
16
cat.nim
16
cat.nim
|
|
@ -3,11 +3,19 @@ import common
|
|||
|
||||
proc catFile(file:string) =
|
||||
if not existsFile(file):
|
||||
echo "cat: " & file & ": No such file or directory"
|
||||
err "cat: " & file & ": No such file or directory"
|
||||
system.quit 1
|
||||
var s = newFileStream(file, fmRead)
|
||||
while not s.atEnd:
|
||||
write(stdout, s.readChar)
|
||||
const bufSize = 1024
|
||||
var
|
||||
f = open(file, fmRead)
|
||||
buffer {.noinit.}: array[bufSize, char]
|
||||
while true:
|
||||
let readBytes = readBuffer(f, addr(buffer[0]), bufSize)
|
||||
if readBytes == 0:
|
||||
break
|
||||
discard writeBuffer(stdout, addr(buffer[0]), readBytes)
|
||||
if readBytes < bufSize:
|
||||
break
|
||||
|
||||
proc catStdin() =
|
||||
var line = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue