Convert mount to use getopt.
[oweals/busybox.git] / util-linux / fdflush.c
index 58b8b37d6ab0a3b045d0b5d9a2b6d6bda20673b1..28f5cb68a02244da47ab04a0073e9d6aff2c317b 100644 (file)
@@ -1,8 +1,9 @@
-
+/* vi: set sw=4 ts=4: */
 /*
  * Mini fdflush implementation for busybox
  *
- * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  */
 
-#include "internal.h"
 #include <stdio.h>
 #include <sys/ioctl.h>
-#include <linux/fd.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include "busybox.h"
 
+/* From <linux/fd.h> */
+#define FDFLUSH  _IO(2,0x4b)
 
 extern int fdflush_main(int argc, char **argv)
 {
-    int        value;
-    int        fd;
-    if ( **(argv+1) == '-' ) {
-       usage( "fdflush device\n");
-    }
+       int fd;
+
+       if (argc <= 1 || **(++argv) == '-')
+               show_usage();
 
-    fd = open(*argv, 0);
-    if ( fd < 0 ) {
-       perror(*argv);
-       exit(FALSE);
-    }
+       if ((fd = open(*argv, 0)) < 0)
+               perror_msg_and_die("%s", *argv);
 
-    value = ioctl(fd, FDFLUSH, 0);
-    close(fd);
+       if (ioctl(fd, FDFLUSH, 0))
+               perror_msg_and_die("%s", *argv);
 
-    if ( value ) {
-       perror(*argv);
-       exit(FALSE);
-    }
-    exit (TRUE);
+       return EXIT_SUCCESS;
 }