uudecode.c (103201) | uudecode.c (103203) |
---|---|
1/*- 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; 43#endif /* not lint */ 44#endif 45 46#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; 43#endif /* not lint */ 44#endif 45 46#include <sys/cdefs.h> |
47__FBSDID("$FreeBSD: head/usr.bin/uudecode/uudecode.c 103201 2002-09-10 20:53:46Z fanf $"); | 47__FBSDID("$FreeBSD: head/usr.bin/uudecode/uudecode.c 103203 2002-09-10 21:10:33Z fanf $"); |
48 49/* 50 * uudecode [file ...] 51 * 52 * create the specified file, decoding as you go. 53 * used with uuencode. 54 */ 55#include <sys/param.h> --- 12 unchanged lines hidden (view full) --- 68 69const char *filename; 70char *outfile; 71int cflag, iflag, oflag, pflag, sflag; 72 73static void usage(void); 74int decode(void); 75int decode2(void); | 48 49/* 50 * uudecode [file ...] 51 * 52 * create the specified file, decoding as you go. 53 * used with uuencode. 54 */ 55#include <sys/param.h> --- 12 unchanged lines hidden (view full) --- 68 69const char *filename; 70char *outfile; 71int cflag, iflag, oflag, pflag, sflag; 72 73static void usage(void); 74int decode(void); 75int decode2(void); |
76void base64_decode(const char *); | 76int base64_decode(const char *); |
77 78int 79main(int argc, char *argv[]) 80{ 81 int rval, ch; 82 83 while ((ch = getopt(argc, argv, "cio:ps")) != -1) { 84 switch(ch) { --- 151 unchanged lines hidden (view full) --- 236 stat(buffn, &st) < 0 || (S_ISREG(st.st_mode) && 237 fchmod(fileno(stdout), getmode(mode, 0) & 0666) < 0)) { 238 warn("%s: %s", filename, buffn); 239 return (1); 240 } 241 } 242 free(mode); 243 | 77 78int 79main(int argc, char *argv[]) 80{ 81 int rval, ch; 82 83 while ((ch = getopt(argc, argv, "cio:ps")) != -1) { 84 switch(ch) { --- 151 unchanged lines hidden (view full) --- 236 stat(buffn, &st) < 0 || (S_ISREG(st.st_mode) && 237 fchmod(fileno(stdout), getmode(mode, 0) & 0666) < 0)) { 238 warn("%s: %s", filename, buffn); 239 return (1); 240 } 241 } 242 free(mode); 243 |
244 if (base64) 245 return (base64_decode(buffn)); 246 |
|
244 /* for each input line */ 245 for (;;) { 246 if (fgets(p = buf, sizeof(buf), stdin) == NULL) { 247 warnx("%s: short file", filename); 248 return (1); 249 } | 247 /* for each input line */ 248 for (;;) { 249 if (fgets(p = buf, sizeof(buf), stdin) == NULL) { 250 warnx("%s: short file", filename); 251 return (1); 252 } |
250 if (base64) { 251 if (strncmp(buf, "====", 4) == 0) 252 return (0); 253 base64_decode(buf); 254 continue; 255 } | 253 |
256#define DEC(c) (((c) - ' ') & 077) /* single character decode */ 257#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) ) 258/* #define IS_DEC(c) (1) */ 259 260#define OUT_OF_RANGE \ 261{ \ 262 warnx( \ 263"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \ --- 48 unchanged lines hidden (view full) --- 312 (strcmp(buf, "end") && strcmp(buf, "end\n") && 313 strcmp(buf, "end\r\n"))) { 314 warnx("%s: no \"end\" line", filename); 315 return (1); 316 } 317 return (0); 318} 319 | 254#define DEC(c) (((c) - ' ') & 077) /* single character decode */ 255#define IS_DEC(c) ( (((c) - ' ') >= 0) && (((c) - ' ') <= 077 + 1) ) 256/* #define IS_DEC(c) (1) */ 257 258#define OUT_OF_RANGE \ 259{ \ 260 warnx( \ 261"\n\tinput file: %s\n\tencoded file: %s\n\tcharacter out of range: [%d-%d]", \ --- 48 unchanged lines hidden (view full) --- 310 (strcmp(buf, "end") && strcmp(buf, "end\n") && 311 strcmp(buf, "end\r\n"))) { 312 warnx("%s: no \"end\" line", filename); 313 return (1); 314 } 315 return (0); 316} 317 |
320void 321base64_decode(const char *stream) | 318int 319base64_decode(const char *outname) |
322{ | 320{ |
321 int n; 322 char buf[MAXPATHLEN+1]; |
|
323 unsigned char out[MAXPATHLEN * 4]; | 323 unsigned char out[MAXPATHLEN * 4]; |
324 int rv; | |
325 | 324 |
326 if (index(stream, '\r') != NULL) 327 *index(stream, '\r') = '\0'; 328 if (index(stream, '\n') != NULL) 329 *index(stream, '\n') = '\0'; 330 rv = b64_pton(stream, out, (sizeof(out) / sizeof(out[0]))); 331 if (rv == -1) 332 errx(1, "b64_pton: error decoding base64 input stream"); 333 fwrite(out, 1, rv, stdout); | 325 for (;;) { 326 if (fgets(buf, sizeof(buf), stdin) == NULL) { 327 warnx("%s: short file", filename); 328 return (1); 329 } 330 if (strcmp(buf, "====") == 0 || 331 strcmp(buf, "====\n") == 0 || 332 strcmp(buf, "====\r\n") == 0) 333 return (0); 334 n = strlen(buf); 335 while (n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r')) 336 buf[--n] = '\0'; 337 n = b64_pton(buf, out, sizeof(out)); 338 if (n < 0) { 339 warnx("%s: %s: error decoding base64 input stream", filename, outname); 340 return (1); 341 } 342 fwrite(out, 1, n, stdout); 343 } |
334} 335 336static void 337usage(void) 338{ 339 (void)fprintf(stderr, 340"usage: uudecode [-cips] [file ...]\n" 341" uudecode [-i] -o output_file [file]\n" 342" b64decode [-cips] [file ...]\n" 343" b64decode [-i] -o output_file [file]\n"); 344 exit(1); 345} | 344} 345 346static void 347usage(void) 348{ 349 (void)fprintf(stderr, 350"usage: uudecode [-cips] [file ...]\n" 351" uudecode [-i] -o output_file [file]\n" 352" b64decode [-cips] [file ...]\n" 353" b64decode [-i] -o output_file [file]\n"); 354 exit(1); 355} |