uuencode.c revision 126530de59706e11b663297e8dced72dc740d8cc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* uuencode [-m] [input] decode_pathname
*
* Encode a file so it can be mailed to a remote system.
*/
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <locale.h>
#include <errno.h>
#include <assert.h>
#include <signal.h>
/*
* (Size of TABLE_SIZE octal is large enough to convert a basic 6-bit
* data chunk.)
*/
#define TABLE_SIZE 0x40
static unsigned char base64_table_initializer[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789+/";
static unsigned char encode_table[TABLE_SIZE];
/* ENC is the basic 1 character encoding function to make a char printing */
static char *prog;
int
{
int c, i;
int errflag = 0;
int base64flag = 0;
/* Set locale environment variables local definitions */
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'm':
base64flag++;
break;
default:
case '?':
errflag++;
}
/* optional 1st argument */
if (argc > 1) {
exit(1);
}
} else {
mode = 0777;
}
exit(2);
}
/* figure out the input file mode */
errno = 0;
} else {
}
/*
* encoding varies depending on whether we are
* using base64 encoding or the historical algorithm
*/
if (base64flag) {
sizeof (encode_table));
} else {
for (i = 0; i < TABLE_SIZE; i++)
encode_table[i] = (unsigned char)i + 0x20;
}
/*
* here's the meat of the whole thing
*/
if (base64flag)
else
exit(6);
}
if (base64flag)
else
exit(6);
}
exit(6);
}
return (0);
}
/*
* copy from in to out, encoding as you go along.
*/
static void
{
unsigned char in_buf[80];
unsigned char out_buf[112];
int i;
if (! base64) {
/* historical algorithm */
for (;;) {
/* 1 (up to) 45 character line */
for (i = 0; i < n; i += 3) {
iptr += 3;
}
*(optr++) = '\n';
/*LINTED*/
out);
exit(6);
}
if (n == 0)
break;
}
} else {
/* base64 algorithm */
/*
* read must be a multiple of 3 bytes for
* this algorithm to work, and also must
* be small enough that read_size * (4/3)
* will always be 76 bytes or less, since
* base64 lines can be no longer than that
*/
opos = 0;
for (i = 0; i < n / 3; i++) {
iptr += 3;
opos += 3;
/* need output padding ? */
if (n - opos < 3)
break;
/*LINTED*/
exit(6);
}
}
/*
* Take care of any output padding that is
* necessary.
*/
switch (n - opos) {
case 0:
/* no-op - 24 bits of data encoded */
*(optr++) = '\n';
break;
case 1:
/* 8 bits encoded - pad with 2 '=' */
*(optr++) = '=';
*(optr++) = '=';
*(optr++) = '\n';
break;
case 2:
/* 16 bits encoded - pad with 1 '=' */
<< 2);
*(optr++) = '=';
*(optr++) = '\n';
break;
default:
/* impossible */
break;
}
/*LINTED*/
exit(6);
}
}
}
}