Merge branch 'vendor/OPENRESOLV' with the following changes:
[dragonfly.git] / test / socket / checkfd / checkfd.c
CommitLineData
73610d44 1#include <err.h>
36e1dffe
SZ
2#include <errno.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <unistd.h>
6
7int
8main(int argc, char *argv[])
9{
10 int i;
11
12 if (argc < 2)
13 exit(1);
14
15 for (i = 1; i < argc; ++i) {
16 char *endptr;
17 int fd;
18
19 fd = strtol(argv[i], &endptr, 10);
20 if (*endptr != '\0')
21 exit(1);
22
23 if (close(fd) < 0) {
24 int error = errno;
25
26 if (error != EBADF) {
73610d44 27 warnx("close error %d", error);
36e1dffe
SZ
28 exit(2);
29 }
30 } else {
73610d44 31 warnx("%d is still valid", fd);
36e1dffe
SZ
32 exit(2);
33 }
34 }
35 exit(0);
36}