summaryrefslogtreecommitdiff
path: root/misc-utils/ftl_format.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc-utils/ftl_format.c')
-rw-r--r--misc-utils/ftl_format.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/misc-utils/ftl_format.c b/misc-utils/ftl_format.c
index bf3c8f2..34d436c 100644
--- a/misc-utils/ftl_format.c
+++ b/misc-utils/ftl_format.c
@@ -312,18 +312,20 @@ int main(int argc, char *argv[])
exit(errflg > 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
- if (stat(argv[optind], &buf) != 0) {
+ fd = open(argv[optind], O_RDWR);
+ if (fd == -1) {
+ perror("open failed");
+ exit(EXIT_FAILURE);
+ }
+ if (fstat(fd, &buf) != 0) {
perror("status check failed");
+ close(fd);
exit(EXIT_FAILURE);
}
if (!(buf.st_mode & S_IFCHR)) {
fprintf(stderr, "%s is not a character special device\n",
argv[optind]);
- exit(EXIT_FAILURE);
- }
- fd = open(argv[optind], O_RDWR);
- if (fd == -1) {
- perror("open failed");
+ close(fd);
exit(EXIT_FAILURE);
}