Skip to content

Commit fc7865d

Browse files
committed
do not give bad example by not closing the fd
1 parent 6aecc26 commit fc7865d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

getopt/getopt_long.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
#include <unistd.h>
23
#include <getopt.h>
34
#include <fcntl.h>
45
#include <err.h>
@@ -14,7 +15,7 @@ usage(void)
1415
int
1516
main(int argc, char *argv[])
1617
{
17-
int bflag, ch, fd;
18+
int bflag, ch, fd = -1;
1819
int daggerset;
1920

2021
/* options descriptor */
@@ -52,5 +53,8 @@ main(int argc, char *argv[])
5253
argc -= optind;
5354
argv += optind;
5455

56+
if (fd != -1)
57+
close(fd);
58+
5559
return (0);
5660
}

0 commit comments

Comments
 (0)