summaryrefslogtreecommitdiff
path: root/src/libstddjb/fd_close.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/fd_close.c')
-rw-r--r--src/libstddjb/fd_close.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstddjb/fd_close.c b/src/libstddjb/fd_close.c
new file mode 100644
index 0000000..8b107f6
--- /dev/null
+++ b/src/libstddjb/fd_close.c
@@ -0,0 +1,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 ;
+}