xref: /plan9/sys/src/cmd/ssh2/common.c (revision 63afb9a5d3f910047231762bcce0ee49fed3d07c)
1 #include <u.h>
2 #include <libc.h>
3 #include "ssh2.h"
4 
5 void
freeptr(void ** vpp)6 freeptr(void **vpp)
7 {
8 	char **cpp;
9 
10 	cpp = vpp;
11 	free(*cpp);
12 	*cpp = nil;
13 }
14 
15 int
readfile(char * file,char * buf,int size)16 readfile(char *file, char *buf, int size)
17 {
18 	int n, fd;
19 
20 	fd = open(file, OREAD);
21 	if (fd < 0)
22 		return -1;
23 	n = readn(fd, buf, size - 1);
24 	if (n < 0)
25 		buf[0] = '\0';
26 	else
27 		buf[n] = '\0';
28 	close(fd);
29 	return n;
30 }
31