common.c 766 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "ssh2.h"
  12. void
  13. freeptr(void **vpp)
  14. {
  15. char **cpp;
  16. cpp = vpp;
  17. free(*cpp);
  18. *cpp = nil;
  19. }
  20. int
  21. readfile(char *file, char *buf, int size)
  22. {
  23. int n, fd;
  24. fd = open(file, OREAD);
  25. if (fd < 0)
  26. return -1;
  27. n = readn(fd, buf, size - 1);
  28. if (n < 0)
  29. buf[0] = '\0';
  30. else
  31. buf[n] = '\0';
  32. close(fd);
  33. return n;
  34. }