~ft/zuke

9830943f0ead458292de34c3fe4877966c3dbdba — Sigrid Haflínudóttir 7 months ago 108260c
use readn and correct loop break conditions
2 files changed, 10 insertions(+), 21 deletions(-)

M icy.c
M zuke.c
M icy.c => icy.c +3 -6
@@ 2,7 2,7 @@ int
icyfill(Meta *m)
{
	char *s, *e, *p, *path, *d;
	int f, r, n;
	int f, n;

	path = strdup(m->path);
	s = strchr(path, ':')+3;


@@ 18,11 18,8 @@ icyfill(Meta *m)
		return -1;
	fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
	s = malloc(4096);
	for(r = 0; r < 4096; r += n){
		if((n = read(f, s+r, 4096-r)) < 1)
			break;
	}
	s[r] = 0;
	n = readn(f, s, 4095);
	s[n] = 0;
	for(; s = strchr(s, '\n');){
		s++;
		if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){

M zuke.c => zuke.c +7 -15
@@ 430,7 430,7 @@ playerthread(void *player_)
	Ioproc *io;
	Image *thiscover;
	ulong c;
	int p[2], fd, pid, n, got, noinit, trycoverload;
	int p[2], fd, pid, n, noinit, trycoverload;
	u64int bytesfrom, bf;
	Meta *cur;



@@ 481,19 481,11 @@ restart:
		sendul(player->ev, Evready);
		buf = malloc(Relbufsz);
		io = ioproc();
		for(c = 0, got = 0; got < Relbufsz; got += n){
			if((c = nbrecvul(player->ctl)) != 0)
				break;
			n = ioread(io, p[1], buf+got, Relbufsz-got);
			if(n < 1)
				break;
		}
		if(c == 0)
			c = recvul(player->ctl);
		n = ioreadn(io, p[1], buf, Relbufsz);
		c = recvul(player->ctl);
		if(c != Cstart)
			goto freeplayer;
		iowrite(io, audio, buf, got);
		byteswritten = got;
		byteswritten = iowrite(io, audio, buf, n);
		bytesfrom = 0;
		c = 0;
		noinit = 1;


@@ 507,8 499,8 @@ restart:
		n = Relbufsz;
		if(bytesfrom > byteswritten && n > bytesfrom-byteswritten)
			n = bytesfrom-byteswritten;
		n = ioread(io, p[1], buf, n);
		if(n < 1)
		n = ioreadn(io, p[1], buf, n);
		if(n < 0)
			break;

		thiscover = nil;


@@ 639,7 631,7 @@ readplist(void)
		if((s = realloc(s, alloc)) == nil)
			sysfatal("no memory");
		for(n = 0; sz < alloc; sz += n){
			n = read(0, s+sz, alloc-sz);
			n = readn(0, s+sz, alloc-sz);
			if(n < 0)
				sysfatal("%r");
			if(n == 0)