diff options
Diffstat (limited to 'appl/cmd')
| -rw-r--r-- | appl/cmd/9export.b | 16 | ||||
| -rw-r--r-- | appl/cmd/auth/aescbc.b | 16 | ||||
| -rw-r--r-- | appl/cmd/auxi/rstyxd.b | 8 | ||||
| -rw-r--r-- | appl/cmd/crypt.b | 4 | ||||
| -rw-r--r-- | appl/cmd/disk/prep/fdisk.b | 3 | ||||
| -rw-r--r-- | appl/cmd/disk/prep/pedit.b | 3 | ||||
| -rw-r--r-- | appl/cmd/disk/prep/prep.b | 3 | ||||
| -rw-r--r-- | appl/cmd/import.b | 18 |
8 files changed, 11 insertions, 60 deletions
diff --git a/appl/cmd/9export.b b/appl/cmd/9export.b index 1c430d88..83a2ddb4 100644 --- a/appl/cmd/9export.b +++ b/appl/cmd/9export.b @@ -124,7 +124,7 @@ init(nil: ref Draw->Context, args: list of string) key[12:] = secret[0:ns]; if(sys->write(fd, key[12:], 4) != 4) fail("import", sys->sprint("can't write key to remote: %r")); - if(readn(fd, key, 4) != 4) + if(sys->readn(fd, key, 4) != 4) fail("import", sys->sprint("can't read remote key: %r")); digest := array[Keyring->SHA1dlen] of byte; kr->sha1(key, len key, digest, nil); @@ -137,20 +137,6 @@ init(nil: ref Draw->Context, args: list of string) fail("export", sys->sprint("can't export %s: %r", tree)); } -readn(fd: ref Sys->FD, buf: array of byte, nb: int): int -{ - for(nr := 0; nr < nb;){ - n := sys->read(fd, buf[nr:], nb-nr); - if(n <= 0){ - if(nr == 0) - return n; - break; - } - nr += n; - } - return nr; -} - S(a: array of byte): string { s := ""; diff --git a/appl/cmd/auth/aescbc.b b/appl/cmd/auth/aescbc.b index c5b6e301..e168cd47 100644 --- a/appl/cmd/auth/aescbc.b +++ b/appl/cmd/auth/aescbc.b @@ -81,7 +81,7 @@ init(nil: ref Draw->Context, args: list of string) fd := sys->open(keyfile, Sys->OREAD); if(fd == nil) error(sys->sprint("can't open %q: %r", keyfile), "keyfile"); - n := readn(fd, buf, len buf); + n := sys->readn(fd, buf, len buf); while(n > 0 && buf[n-1] == byte '\n') n--; if(n <= 0) @@ -175,20 +175,6 @@ eqbytes(a: array of byte, b: array of byte, n: int): int return 1; } -readn(fd: ref Sys->FD, buf: array of byte, nb: int): int -{ - for(nr := 0; nr < nb;){ - n := sys->read(fd, buf[nr:], nb-nr); - if(n <= 0){ - if(nr == 0) - return n; - break; - } - nr += n; - } - return nr; -} - Read(buf: array of byte, n: int) { if(bin.read(buf, n) != n){ diff --git a/appl/cmd/auxi/rstyxd.b b/appl/cmd/auxi/rstyxd.b index 2f853ad5..aa0498dc 100644 --- a/appl/cmd/auxi/rstyxd.b +++ b/appl/cmd/auxi/rstyxd.b @@ -91,12 +91,8 @@ readargs(fd: ref Sys->FD): list of string readn(fd: ref Sys->FD, nb: int): array of byte { buf:= array[nb] of byte; - for(n:=0; n<nb;){ - m := sys->read(fd, buf[n:], nb-n); - if(m <= 0) - return nil; - n += m; - } + if(sys->readn(fd, buf, nb) != nb) + return nil; return buf; } diff --git a/appl/cmd/crypt.b b/appl/cmd/crypt.b index a478abfc..eec73bc9 100644 --- a/appl/cmd/crypt.b +++ b/appl/cmd/crypt.b @@ -153,11 +153,11 @@ cryptpipe(decrypt: int, alg: string, sk: array of byte): (string, array of ref S (err, c) := ssl->connect(pfd[1]); if (err != nil) - return ("could not connect ssl: "+sys->sprint("%r"), nil, nil, nil); + return ("could not connect ssl: "+err, nil, nil, nil); pfd[1] = nil; err = ssl->secret(c, sk, sk); if (err != nil) - return ("could not write secret: "+sys->sprint("%r"), nil, nil, nil); + return ("could not write secret: "+err, nil, nil, nil); if (alg != nil) if (sys->fprint(c.cfd, "alg %s", alg) == -1) diff --git a/appl/cmd/disk/prep/fdisk.b b/appl/cmd/disk/prep/fdisk.b index 00ecbb36..b01045ff 100644 --- a/appl/cmd/disk/prep/fdisk.b +++ b/appl/cmd/disk/prep/fdisk.b @@ -14,7 +14,6 @@ include "disks.m"; Disk, PCpart: import disks; NTentry, Toffset, TentrySize: import Disks; Magic0, Magic1: import Disks; - readn: import disks; include "pedit.m"; pedit: Pedit; @@ -299,7 +298,7 @@ diskread(disk: ref Disk, data: array of byte, ndata: int, sec: big, off: int) a := sec*big disk.secsize + big off; if(sys->seek(disk.fd, a, 0) != a) sysfatal(sys->sprint("diskread seek %bud.%ud: %r", sec, off)); - if(readn(disk.fd, data, ndata) != ndata) + if(sys->readn(disk.fd, data, ndata) != ndata) sysfatal(sys->sprint("diskread %ud at %bud.%ud: %r", ndata, sec, off)); } diff --git a/appl/cmd/disk/prep/pedit.b b/appl/cmd/disk/prep/pedit.b index f55bcaff..d9494cae 100644 --- a/appl/cmd/disk/prep/pedit.b +++ b/appl/cmd/disk/prep/pedit.b @@ -14,7 +14,6 @@ include "bufio.m"; include "disks.m"; disks: Disks; Disk: import disks; - readn: import disks; include "draw.m"; include "calc.tab.m"; @@ -378,7 +377,7 @@ rdctlpart(edit: ref Edit) edit.ctlpart = array[0] of ref Part; sys->seek(disk.ctlfd, big 0, 0); buf := array[4096] of byte; - if(readn(disk.ctlfd, buf, len buf) <= 0) + if(sys->readn(disk.ctlfd, buf, len buf) <= 0) return; for(i := 0; i < len buf; i++) if(buf[i] == byte 0) diff --git a/appl/cmd/disk/prep/prep.b b/appl/cmd/disk/prep/prep.b index fa4c60a1..02df806c 100644 --- a/appl/cmd/disk/prep/prep.b +++ b/appl/cmd/disk/prep/prep.b @@ -16,7 +16,6 @@ include "bufio.m"; include "disks.m"; disks: Disks; Disk: import disks; - readn: import disks; include "pedit.m"; pedit: Pedit; @@ -279,7 +278,7 @@ rdpart(edit: ref Edit) { disk := edit.disk; sys->seek(disk.fd, big disk.secsize, 0); - if(readn(disk.fd, osecbuf, disk.secsize) != disk.secsize) + if(sys->readn(disk.fd, osecbuf, disk.secsize) != disk.secsize) return; osecbuf[disk.secsize] = byte 0; secbuf[0:] = osecbuf; diff --git a/appl/cmd/import.b b/appl/cmd/import.b index 657deb38..fb69d0ab 100644 --- a/appl/cmd/import.b +++ b/appl/cmd/import.b @@ -117,7 +117,7 @@ init(nil: ref Draw->Context, args: list of string) key[4:] = ai.secret[0:ns]; if(sys->write(c.dfd, key, 4) != 4) fail("import", sys->sprint("can't write key to remote: %r")); - if(readn(c.dfd, key[12:], 4) != 4) + if(sys->readn(c.dfd, key[12:], 4) != 4) fail("import", sys->sprint("can't read remote key: %r")); digest := array[Keyring->SHA1dlen] of byte; kr->sha1(key, len key, digest, nil); @@ -135,20 +135,6 @@ init(nil: ref Draw->Context, args: list of string) fail("mount failed", sys->sprint("import %s %s: mount failed: %r", addr, file)); } -readn(fd: ref Sys->FD, buf: array of byte, nb: int): int -{ - for(nr := 0; nr < nb;){ - n := sys->read(fd, buf[nr:], nb-nr); - if(n <= 0){ - if(nr == 0) - return n; - break; - } - nr += n; - } - return nr; -} - S(a: array of byte): string { s := ""; @@ -180,7 +166,7 @@ netmkaddr(addr, net, svc: string): string { if(net == nil) net = "net"; - (n, l) := sys->tokenize(addr, "!"); + (n, nil) := sys->tokenize(addr, "!"); if(n <= 1){ if(svc== nil) return sys->sprint("%s!%s", net, addr); |
