* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)uuencode.c 5.6 (Berkeley) %G%";
* uuencode [input] output
* Encode a file so it can be mailed to a remote system.
/* ENC is the basic 1 character encoding function to make a char printing */
#define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
/* optional 1st argument */
if ((in
= fopen(argv
[1], "r")) == NULL
) {
fprintf(stderr
,"Usage: uuencode [infile] remotefile\n");
/* figure out the input file mode */
if (fstat(fileno(in
), &sbuf
) < 0 || !isatty(fileno(in
)))
mode
= 0666 & ~umask(0666);
mode
= sbuf
.st_mode
& 0777;
printf("begin %o %s\n", mode
, argv
[1]);
* copy from in to out, encoding as you go along.
/* 1 (up to) 45 character line */
n
= fread(buf
, 1, 45, in
);
* output one group of 3 bytes, pointed at by p, on file f.
register int c1
, c2
, c3
, c4
;
c2
= (*p
<< 4) & 060 | (p
[1] >> 4) & 017;
c3
= (p
[1] << 2) & 074 | (p
[2] >> 6) & 03;