Merge branch 'vendor/TNFTP'
[dragonfly.git] / test / socket / checkfd / checkfd.c
1 #include <err.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6
7 int
8 main(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) {
27                                 warnx("close error %d", error);
28                                 exit(2);
29                         }
30                 } else {
31                         warnx("%d is still valid", fd);
32                         exit(2);
33                 }
34         }
35         exit(0);
36 }