[hackers] [sbase] uuencode: Style fix || sin
commit 9ad90daef77bd703e2225f6b50fd7b1b9254cd0c
Author: sin <sin_AT_2f30.org>
Date: Fri Feb 13 11:17:48 2015 +0000
uuencode: Style fix
diff --git a/uuencode.c b/uuencode.c
index af41473..55061e7 100644
--- a/uuencode.c
+++ b/uuencode.c
_AT_@ -9,55 +9,13 @@
static int mflag = 0;
-static void uuencodeb64(FILE *, const char *, const char *);
-static void uuencode(FILE *, const char *, const char *);
-
-static void
-usage(void)
-{
- eprintf("usage: %s [-m] [file] name\n", argv0);
-}
-
-int
-main(int argc, char *argv[])
-{
- FILE *fp;
-
- ARGBEGIN {
- case 'm':
- mflag = 1;
- break;
- default:
- usage();
- } ARGEND;
-
- if (argc == 0 || argc > 2)
- usage();
-
- if (argc == 1) {
- if (mflag)
- uuencodeb64(stdin, argv[0], "<stdin>");
- else
- uuencode(stdin, argv[0], "<stdin>");
- } else {
- if (!(fp = fopen(argv[0], "r")))
- eprintf("fopen %s:", argv[0]);
- if (mflag)
- uuencodeb64(fp, argv[1], argv[0]);
- else
- uuencode(fp, argv[1], argv[0]);
- fclose(fp);
- }
- return 0;
-}
-
-static const char b64et[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-/* much faster */
static unsigned int
b64e(unsigned char b[2])
{
unsigned int o = 0;
unsigned int p = b[2] | (b[1] << 8) | (b[0] << 16);
+ const char b64et[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
o = b64et[p & 0x3f]; p >>= 6;
o = (o << 8) | b64et[p & 0x3f]; p >>= 6;
o = (o << 8) | b64et[p & 0x3f]; p >>= 6;
_AT_@ -72,6 +30,7 @@ uuencodeb64(FILE *fp, const char *name, const char *s)
ssize_t n, m = 0;
unsigned char buf[45], *pb;
unsigned int out[sizeof(buf)/3 + 1], *po;
+
if (fstat(fileno(fp), &st) < 0)
eprintf("fstat %s:", s);
printf("begin-base64 %o %s\n", st.st_mode & 0777, name);
_AT_@ -133,3 +92,42 @@ uuencode(FILE *fp, const char *name, const char *s)
eprintf("'%s' read error:", s);
printf("%c\nend\n", '`');
}
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-m] [file] name\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *fp;
+
+ ARGBEGIN {
+ case 'm':
+ mflag = 1;
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc == 0 || argc > 2)
+ usage();
+
+ if (argc == 1) {
+ if (mflag)
+ uuencodeb64(stdin, argv[0], "<stdin>");
+ else
+ uuencode(stdin, argv[0], "<stdin>");
+ } else {
+ if (!(fp = fopen(argv[0], "r")))
+ eprintf("fopen %s:", argv[0]);
+ if (mflag)
+ uuencodeb64(fp, argv[1], argv[0]);
+ else
+ uuencode(fp, argv[1], argv[0]);
+ fclose(fp);
+ }
+ return 0;
+}
Received on Fri Feb 13 2015 - 12:22:59 CET
This archive was generated by hypermail 2.3.0
: Fri Feb 13 2015 - 12:24:18 CET