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

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

int fd_close (int fd)
{
  register unsigned int i = 0 ;
doit:
  if (!close(fd)) return 0 ;
  i++ ;
  if (errno == EINTR) goto doit ;
  return ((errno == EBADF) && (i > 1)) ? 0 : -1 ;
}