There are a couple of functions to encode data into a file. You will usually need no more than one of them, depending on the job you want to do. The functions also differ in the headers they generate. Some functions do generate full MIME-compliant headers. This may sound like the best choice, but it's not always the wisest choice. Please follow the following guidelines.
All of the functions have a bunch of parameters for greater flexibility. Don't be confused by their number, usually you'll need to fill only a few of them. There's a number of common parameters which can be explained separately:
Now for the functions ...
int UUEncodeMulti | (FILE *outfile, FILE *infile, |
char *infname, int encoding, | |
char *outfname, char *mimetype, | |
int filemode) |
int UUEncodePartial | (FILE *outfile, FILE *infile, |
char *infname, int encoding, | |
char *outfname, char *mimetype, | |
int filemode, int partno, | |
long linperfile) |
Each call produces linperfile lines of encoded output. For uuencoded and xxencoded files, each output line encodes 45 bytes of input data, each Base64 line encodes 57 bytes. If linperfile==0, this function is equivalent to UUEncodeMulti.
Different handling is necessary when reading from an input stream (if infile!=NULL) compared to reading from a file (if infname!=NULL). In the first case, the function must be called until feof() becomes true on the input file, or an error occurs. In the second case, the file will be opened internally. Instead of UURET-_OK, a value of UURET-_CONT is returned for all but the last part.
int UUEncodeToStream | (FILE *outfile, FILE *infile, |
char *infname, int encoding, | |
char *outfname, int filemode) |
int UUEncodeToFile | (FILE *infile, char *infname, |
int encoding, char *outfname, | |
char *diskname, long linperfile) |
If diskname!=NULL and does not contain directory information, the target filename is the concatenation of the save path and diskname. If diskname is an absolute path name, it is used itself.
From the so-generated target filename, the extension is stripped. For single-part output files, the extension set with the UUOPT-_ENCEXT option is used. Otherwise, the three-digit part number is used as extension. If the destination file does already exist, the value of the UUOPT-_OVERWRITE is checked; if overwriting is not allowed, encoding fails with UURET-_EXISTS.
int UUE_PrepSingle | (FILE *outfile, FILE *infile, |
char *infname, int encoding, | |
char *outfname, int filemode, | |
char *destination, char *from, | |
char *subject, int isemail) |
If from!=NULL, it is sent as the sender's email address in the ``From'' header field. Some MDA programs are able to provide the sender's address themselves, so this value may be NULL in certain cases.
If subject!=NULL, the text is included in the ``Subject'' header field. The subject is extended with information about the file name and part number (in this case, always ``(001/001)'').
``Destination'' must not be NULL. Depending on the ``isemail'' flag, its contents are sent either in the ``To'' or ``Newsgroups'' header field.
int UUE_PrepPartial | (FILE *outfile, FILE *infile, |
char *infname, int encoding, | |
char *outfname, int filemode, | |
int partno, long linperfile, | |
long filesize, | |
char *destination, char *from, | |
char *subject, int isemail) |
The only additional parameter is filesize. Usually, this value can be 0, as the size of the input file can usually be determined by performing a stat() call. However, this might not be possible if infile refers to a pipe. In that case, the value of filesize is used.
If the size of the input data cannot be determined, and filesize is 0, the function refuses encoding into multiple files and produces only a single stream of output.
If data is read from a file instead from a stream (infile==NULL), the function opens the file internally and returns UURET-_CONT instead of UURET-_OK on successful completion for all but the last part.