Plan 9 from Bell Labs’s /usr/web/sources/contrib/pdt/gphrfs/gphr.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>

int
gphrdial(char* host, char* net, char* service)
{
	return host ? dial(netmkaddr(host, net, service), 0, 0, 0) : -1;
}

long
gphrget(int fd, char* selector, char** buf)
{
	char *newbuf, *rb, wb[512];
	long n, nlast;

	n = snprint(wb, 512, "%s\r\n", selector ? selector : "");
	if(fd < 0 || write(fd, wb, n) < n) return -1;

	n = 0;
	if((rb = *buf = malloc(512)) == nil) return -1;
	do{
		nlast = read(fd, rb, 512);
		n += nlast;
		if((newbuf = realloc(*buf, n+512)) == nil){
			free(*buf);
			*buf = nil;
			return -1;
		}
		*buf = newbuf;
		rb = *buf+n;
	}while(nlast);

	close(fd);
	return n;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.