diff -r 9155a0813ffc toys/posix/uuencode.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/posix/uuencode.c	Fri Mar 15 11:33:27 2013 +1300
@@ -0,0 +1,116 @@
+/* uuencode.c - Encode a binary file
+ *
+ * Copyright 2013 Andre Renaud <andre@bluewatersys.com>
+ *
+ * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/uuencode.html
+
+USE_UUENCODE(NEWTOY(uuencode, "<1>2m", TOYFLAG_USR|TOYFLAG_BIN))
+
+config UUENCODE
+  bool "uuencode"
+  default y
+  help
+    usage: uuencode [-m] [file] decode_pathname
+
+    Encode binary data from file
+
+    -m	Use MIME Base64 algorithm
+*/
+
+#define FOR_uuencode
+#include "toys.h"
+
+static inline void uuout(int ch)
+{
+  if (ch == 0) putchar('`');
+  else putchar(0x20 + ch);
+}
+
+static inline void b64out(int ch)
+{
+  putchar("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[ch]);
+}
+
+static inline void outblank(int historic)
+{
+  if (historic)
+    putchar('`');
+  else
+    putchar('=');
+}
+
+static void uuencode_file(FILE *input, const char *output_name,
+    int historic, mode_t mode)
+{
+  int line_len = 45;
+  void (*out)(int) = historic ? uuout : b64out;
+  int max_size = sizeof(toybuf) / line_len * line_len;
+
+  printf("begin%s %3.3o %s\n", historic ? "" : "-base64",
+      mode & 0x1ff, output_name);
+
+  while (!feof(input)) {
+    size_t bytes = fread(toybuf, 1, max_size, input);
+    size_t i;
+    if (bytes == 0)
+      break;
+    if (bytes < 0)
+      perror_exit("Unable to read");
+
+    if (bytes < max_size && bytes % 3) {
+      int extra = bytes % 3;
+      memset(&toybuf[bytes], 0, 3 - extra);
+    }
+
+    for (i = 0; i < bytes; i+=3) {
+      if (historic && (i % line_len) == 0)
+        out(min(line_len, bytes - i));
+
+      out((toybuf[i] >> 2) & 0x3f);
+      out((toybuf[i] << 4 | ((toybuf[i + 1] >> 4) & 0xf)) & 0x3f);
+      if (i + 1 >= bytes)
+        outblank(historic);
+      else
+        out((toybuf[i + 1] << 2 | ((toybuf[i + 2] >> 6) & 0x3)) & 0x3f);
+      if (i + 2 >= bytes)
+        outblank(historic);
+      else
+        out(toybuf[i + 2] & 0x3f);
+
+      if ((i % line_len) == line_len - 3)
+        printf("\n");
+    }
+
+    if (bytes % line_len != 0)
+      printf("\n");
+  }
+
+  if (historic)
+    printf("`\nend\n");
+  else
+    printf("====\n");
+}
+
+void uuencode_main(void)
+{
+  FILE *input = stdin;
+  const char *name = toys.optargs[0];
+  mode_t mode = 0664;
+
+  if (toys.optc == 2) {
+    struct stat buf;
+    if (stat(toys.optargs[0], &buf) < 0)
+      perror_exit("Unable to stat '%s'", toys.optargs[0]);
+    mode = buf.st_mode;
+    input = fopen(toys.optargs[0], "rb");
+    if (!input)
+      perror_exit("Unable to open '%s'", toys.optargs[0]);
+    name = toys.optargs[1];
+  }
+
+  uuencode_file(input, name, !(toys.optflags & FLAG_m), mode);
+
+  if (input != stdin)
+    fclose(input);
+}
+
