blob: fcecedc46c1ddec5ce005d6d8948ccbd02d846ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
/* ISC license. */
#include <sys/types.h>
#include <errno.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/djbunix.h>
static ssize_t readnclose (int fd, char *s, size_t n)
{
ssize_t r = allread(fd, s, n) ;
int e = errno ;
fd_close(fd) ;
if ((r > 0) && (r < (ssize_t)n)) e = EPIPE ;
errno = e ;
return r ;
}
ssize_t openreadnclose (char const *file, char *s, size_t n)
{
int fd = open_readb(file) ;
return fd < 0 ? fd : readnclose(fd, s, n) ;
}
ssize_t openreadnclose_nb (char const *file, char *s, size_t n)
{
int fd = open_read(file) ;
return fd < 0 ? fd : readnclose(fd, s, n) ;
}
|