Enhance the ioctl toolbox command

1) Implement documented but unimplemented read-only option.
2) Allow standard input to be used as the <device> by passing
   "-".  On some devices, opening the device has side effects.
   Allowing standard input can prevent this by using a sequence
   of something like:

      # Open the device on file descriptor 3
      exec 3<> /dev/something
      ioctl -d - 0 0 <&3
      ioctl -d - 1 0 <&3
      dd if=myfile >&3
      # Close file descriptor 3
      exec 3>&-

Change-Id: If17ac3cffa7ccb159051550724b4ce7d8efa5feb
Signed-off-by: Scott Anderson <saa@android.com>
diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c
index fb555d2..fd24885 100644
--- a/toolbox/ioctl.c
+++ b/toolbox/ioctl.c
@@ -63,10 +63,14 @@
         exit(1);
     }
 
-    fd = open(argv[optind], O_RDWR | O_SYNC);
-    if (fd < 0) {
-        fprintf(stderr, "cannot open %s\n", argv[optind]);
-        return 1;
+    if (!strcmp(argv[optind], "-")) {
+        fd = STDIN_FILENO;
+    } else {
+        fd = open(argv[optind], read_only ? O_RDONLY : (O_RDWR | O_SYNC));
+        if (fd < 0) {
+            fprintf(stderr, "cannot open %s\n", argv[optind]);
+            return 1;
+        }
     }
     optind++;