just include fcntl.h not sys/fcntl.h
[oweals/busybox.git] / archival / gunzip.c
index 367e0470c53e7c5cbd7fffd551a398e035328ad3..7b939290b4b13e80234aca26a6eddbacc9449689 100644 (file)
@@ -12,8 +12,8 @@
  * handling.
  *
  * General cleanup to better adhere to the style guide and make use of standard
- * busybox functions by Glenn McGrath <bug1@optushome.com.au>
- * 
+ * busybox functions by Glenn McGrath <bug1@iinet.net.au>
+ *
  * 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
  * the Free Software Foundation; either version 2 of the License, or
@@ -63,7 +63,6 @@ static char *license_msg[] = {
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <getopt.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -76,7 +75,7 @@ static char *license_msg[] = {
 #define GUNZIP_OPT_TEST                4
 #define GUNZIP_OPT_DECOMPRESS  8
 
-extern int gunzip_main(int argc, char **argv)
+int gunzip_main(int argc, char **argv)
 {
        char status = EXIT_SUCCESS;
        unsigned long opt;
@@ -98,15 +97,13 @@ extern int gunzip_main(int argc, char **argv)
                optind++;
 
                if (old_path == NULL || strcmp(old_path, "-") == 0) {
-                       src_fd = fileno(stdin);
+                       src_fd = STDIN_FILENO;
                        opt |= GUNZIP_OPT_STDOUT;
                } else {
                        src_fd = bb_xopen(old_path, O_RDONLY);
 
                        /* Get the time stamp on the input file. */
-                       if (stat(old_path, &stat_buf) < 0) {
-                               bb_error_msg_and_die("Couldn't stat file %s", old_path);
-                       }
+                       xstat(old_path, &stat_buf);
                }
 
                /* Check that the input is sane.  */
@@ -117,9 +114,9 @@ extern int gunzip_main(int argc, char **argv)
 
                /* Set output filename and number */
                if (opt & GUNZIP_OPT_TEST) {
-                       dst_fd = bb_xopen("/dev/null", O_WRONLY);       /* why does test use filenum 2 ? */
+                       dst_fd = bb_xopen(bb_dev_null, O_WRONLY);       /* why does test use filenum 2 ? */
                } else if (opt & GUNZIP_OPT_STDOUT) {
-                       dst_fd = fileno(stdout);
+                       dst_fd = STDOUT_FILENO;
                } else {
                        char *extension;
 
@@ -153,12 +150,12 @@ extern int gunzip_main(int argc, char **argv)
                /* do the decompression, and cleanup */
                if (bb_xread_char(src_fd) == 0x1f) {
                        unsigned char magic2;
-                       
+
                        magic2 = bb_xread_char(src_fd);
 #ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
                        if (magic2 == 0x9d) {
                                status = uncompress(src_fd, dst_fd);
-                       } else 
+                       } else
 #endif
                                if (magic2 == 0x8b) {
                                        check_header_gzip(src_fd);
@@ -178,10 +175,10 @@ extern int gunzip_main(int argc, char **argv)
                        delete_path = new_path;
                }
 
-               if (dst_fd != fileno(stdout)) {
+               if (dst_fd != STDOUT_FILENO) {
                        close(dst_fd);
                }
-               if (src_fd != fileno(stdin)) {
+               if (src_fd != STDIN_FILENO) {
                        close(src_fd);
                }