shithub: riscv

ref: b638c7753d8498eaec90f06a7c140ffe0ed76cdb
dir: /sys/src/cmd/auth/lib/readarg.c/

View raw version
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <authsrv.h>
#include "authcmdlib.h"

int
readarg(int fd, char *arg, int len)
{
	char buf[1];
	int i;

	i = 0;
	memset(arg, 0, len);
	while(read(fd, buf, 1) == 1){
		if(i < len - 1)
			arg[i++] = *buf;
		if(*buf == '\0'){
			arg[i] = '\0';
			return 0;
		}
	}
	return -1;
}