summaryrefslogtreecommitdiff
path: root/src/libstddjb/openslurpclose.c
blob: 5f67d7648d5dd3578f922ee54baef513e407f890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* ISC license. */

#include <errno.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>

int openslurpclose (stralloc *sa, char const *fn)
{
  int r ;
  int e ;
  int fd = open_readb(fn) ;
  if (fd == -1) return 0 ;
  r = slurp(sa, fd) ;
  e = errno ;
  fd_close(fd) ;
  errno = e ;
  return r ;
}