Changed gz_open to ruturn a stream
[oweals/busybox.git] / uuencode.c
index 41e6590756504b5e6855c869299b67cc070eaad3..35a533309f84e96f6116dda3bda09aead4b4060e 100644 (file)
 /* Hacked to work with BusyBox by Alfred M. Szmidt */
 
 
-#include "busybox.h"
 
 #include <stdio.h>
 #include <errno.h>
 #include <getopt.h>
-#include <pwd.h>
+#include <stdlib.h>
+#include "busybox.h"
 
 #define        RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
 
 static void encode __P ((void));
 
 /* Pointer to the translation table we currently use.  */
-const char *trans_ptr;
+static const char *trans_ptr;
 
 /* The two currently defined translation tables.  The first is the
    standard uuencoding, the second is base64 encoding.  */
-const char uu_std[64] = {
+static const char uu_std[64] = {
   '`', '!', '"', '#', '$', '%', '&', '\'',
   '(', ')', '*', '+', ',', '-', '.', '/',
   '0', '1', '2', '3', '4', '5', '6', '7',
@@ -49,7 +49,7 @@ const char uu_std[64] = {
   'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
 };
 
-const char uu_base64[64] = {
+static const char uu_base64[64] = {
   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
   'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
   'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
@@ -142,7 +142,7 @@ static void encode()
   }
 
   if (ferror (stdin))
-    error_msg("Read error\n");
+    error_msg("Read error");
 
   if (trans_ptr == uu_std) {
     putchar (ENC ('\0'));
@@ -160,17 +160,14 @@ int uuencode_main (int argc,
   trans_ptr = uu_std;      /* Standard encoding is old uu format */
 
   /* Parse any options */
-  while ((opt = getopt (argc, argv, "m")) != EOF) {
+  while ((opt = getopt (argc, argv, "m")) > 0) {
     switch (opt) {
      case 'm':
       trans_ptr = uu_base64;
       break;
 
-     case 0:
-      break;
-
      default:
-      usage(uuencode_usage);
+      show_usage();
     }
   }
 
@@ -178,7 +175,7 @@ int uuencode_main (int argc,
    case 2:
     /* Optional first argument is input file.  */
     if (!freopen (argv[optind], "r", stdin) || fstat (fileno (stdin), &sb)) {
-      error_msg("%s: %s\n", argv[optind], strerror(errno));
+      perror_msg("%s", argv[optind]);
       return EXIT_FAILURE;
     }
     mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
@@ -191,7 +188,7 @@ int uuencode_main (int argc,
 
    case 0:
    default:
-    usage(uuencode_usage);
+    show_usage();
   }
 
   printf("begin%s %o %s\n", trans_ptr == uu_std ? "" : "-base64",
@@ -199,7 +196,7 @@ int uuencode_main (int argc,
   encode();
   printf(trans_ptr == uu_std ? "end\n" : "====\n");
   if (ferror (stdout)) {
-    error_msg("Write error\n");
+    error_msg("Write error");
     return EXIT_FAILURE;
   }
   return EXIT_SUCCESS;