Notes on portability, and on when #include <linux/blah> is appropriate.
[oweals/busybox.git] / archival / cpio.c
index 8f85779c9bdfa2738f5b62ab16e4526289ccfb19..26f845bc95ced9ee24ff5c64235d690077db3eb3 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * Mini cpio implementation for busybox
  *
- * Copyright (C) 2001 by Glenn McGrath 
+ * Copyright (C) 2001 by Glenn McGrath
  *
  * 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 <fcntl.h>
-#include <getopt.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include "unarchive.h"
 #include "busybox.h"
 
-#define CPIO_OPT_EXTRACT               0x01
-#define CPIO_OPT_TEST                  0x02
-#define CPIO_OPT_UNCONDITIONAL         0x04
-#define CPIO_OPT_VERBOSE               0x08
-#define CPIO_OPT_FILE                  0x10
+#define CPIO_OPT_EXTRACT                       0x01
+#define CPIO_OPT_TEST                          0x02
+#define CPIO_OPT_UNCONDITIONAL         0x04
+#define CPIO_OPT_VERBOSE                       0x08
+#define CPIO_OPT_FILE                          0x10
 #define CPIO_OPT_CREATE_LEADING_DIR    0x20
-#define CPIO_OPT_PRESERVE_MTIME        0x40
+#define CPIO_OPT_PRESERVE_MTIME                0x40
 
-extern int cpio_main(int argc, char **argv)
+int cpio_main(int argc, char **argv)
 {
        archive_handle_t *archive_handle;
        char *cpio_filename = NULL;
@@ -47,7 +46,7 @@ extern int cpio_main(int argc, char **argv)
 
        /* Initialise */
        archive_handle = init_handle();
-       archive_handle->src_fd = fileno(stdin);
+       archive_handle->src_fd = STDIN_FILENO;
        archive_handle->seek = seek_by_char;
        archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
 
@@ -59,10 +58,10 @@ extern int cpio_main(int argc, char **argv)
        }
 
        if (opt & CPIO_OPT_TEST) {
-               /* if both extract and test option are given, ignore extract option */
+               /* if both extract and test options are given, ignore extract option */
                if (opt & CPIO_OPT_EXTRACT) {
                        opt &= ~CPIO_OPT_EXTRACT;
-               }               
+               }
                archive_handle->action_header = header_list;
        }
        if (opt & CPIO_OPT_EXTRACT) {
@@ -79,7 +78,7 @@ extern int cpio_main(int argc, char **argv)
                        archive_handle->action_header = header_list;
                }
        }
-       if (cpio_filename) {    /* CPIO_OPT_FILE */
+       if (cpio_filename) { /* CPIO_OPT_FILE */
                archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY);
                archive_handle->seek = seek_by_jump;
        }