summaryrefslogtreecommitdiff
path: root/appl
diff options
context:
space:
mode:
Diffstat (limited to 'appl')
-rw-r--r--appl/cmd/9export.b16
-rw-r--r--appl/cmd/auth/aescbc.b16
-rw-r--r--appl/cmd/auxi/rstyxd.b8
-rw-r--r--appl/cmd/crypt.b4
-rw-r--r--appl/cmd/disk/prep/fdisk.b3
-rw-r--r--appl/cmd/disk/prep/pedit.b3
-rw-r--r--appl/cmd/disk/prep/prep.b3
-rw-r--r--appl/cmd/import.b18
-rw-r--r--appl/lib/auth9.b8
-rw-r--r--appl/lib/disks.b20
-rw-r--r--appl/lib/scsiio.b16
-rw-r--r--appl/wm/wm.b13
12 files changed, 29 insertions, 99 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);
diff --git a/appl/lib/auth9.b b/appl/lib/auth9.b
index 06accb53..d9f38c71 100644
--- a/appl/lib/auth9.b
+++ b/appl/lib/auth9.b
@@ -288,12 +288,8 @@ decrypt(key: array of byte, data: array of byte, n: int)
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/lib/disks.b b/appl/lib/disks.b
index ac718af1..2918b2cc 100644
--- a/appl/lib/disks.b
+++ b/appl/lib/disks.b
@@ -72,14 +72,14 @@ partitiongeometry(d: ref Disk): int
rawfd := sys->open(d.prefix+"data", Sys->OREAD);
if(rawfd != nil
&& sys->seek(rawfd, big 0, 0) == big 0
- && readn(rawfd, buf, 512) == 512
+ && sys->readn(rawfd, buf, 512) == 512
&& int t[Omagic] == Magic0
&& int t[Omagic+1] == Magic1) {
rawfd = nil;
}else{
rawfd = nil;
if(sys->seek(d.fd, big 0, 0) < big 0
- || readn(d.fd, buf, 512) != 512
+ || sys->readn(d.fd, buf, 512) != 512
|| int t[Omagic] != Magic0
|| int t[Omagic+1] != Magic1)
return -1;
@@ -350,7 +350,7 @@ putle32(p: array of byte, i: big)
Disk.readn(d: self ref Disk, buf: array of byte, nb: int): int
{
- return readn(d.fd, buf, nb);
+ return sys->readn(d.fd, buf, nb);
}
chstext(p: array of byte): string
@@ -361,17 +361,3 @@ chstext(p: array of byte): string
s := (int p[1] & 16r3F);
return sys->sprint("%d/%d/%d", c, h, s);
}
-
-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;
-}
diff --git a/appl/lib/scsiio.b b/appl/lib/scsiio.b
index 152a22dd..3b4ce115 100644
--- a/appl/lib/scsiio.b
+++ b/appl/lib/scsiio.b
@@ -264,7 +264,7 @@ Scsi.open(dev: string): ref Scsi
return nil;
buf := array[512] of byte;
- n := readn(ctlfd, buf, len buf);
+ n := sys->readn(ctlfd, buf, len buf);
if(n < 8){
if(n >= 0)
sys->werrstr("error reading ctl file");
@@ -301,17 +301,3 @@ qunlock(s: ref Scsi)
{
<-s.lock;
}
-
-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;
-}
diff --git a/appl/wm/wm.b b/appl/wm/wm.b
index d8232b0b..d2dee3f8 100644
--- a/appl/wm/wm.b
+++ b/appl/wm/wm.b
@@ -402,9 +402,20 @@ dragwin(ptr: chan of ref Pointer, c: ref Client, w: ref Window, off: Point): str
if(buttons == 0)
return "too late";
p: ref Pointer;
+ scr := screen.image.r;
+ Margin: con 10;
do{
p = <-ptr;
- w.img.origin(w.img.r.min, p.xy.sub(off));
+ org := p.xy.sub(off);
+ if(org.y < scr.min.y)
+ org.y = scr.min.y;
+ else if(org.y > scr.max.y - Margin)
+ org.y = scr.max.y - Margin;
+ if(org.x < scr.min.x && org.x + w.r.dx() < scr.min.x + Margin)
+ org.x = scr.min.x + Margin - w.r.dx();
+ else if(org.x > scr.max.x - Margin)
+ org.x = scr.max.x - Margin;
+ w.img.origin(w.img.r.min, org);
} while (p.buttons != 0);
c.ptr <-= p;
buttons = 0;