ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/uuencode.c
(Generate patch)

Comparing Convert-UUlib/uulib/uuencode.c (file contents):
Revision 1.11 by root, Sat Sep 24 06:02:04 2022 UTC vs.
Revision 1.12 by root, Sat Sep 24 06:22:47 2022 UTC

28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <ctype.h> 30#include <ctype.h>
31#include <stdio.h> 31#include <stdio.h>
32#include <time.h> 32#include <time.h>
33
34#ifdef STDC_HEADERS
35#include <stdlib.h> 33#include <stdlib.h>
36#include <string.h> 34#include <string.h>
37#endif 35#include <errno.h>
36
38#ifdef HAVE_UNISTD_H 37#ifdef HAVE_UNISTD_H
39#include <unistd.h> 38#include <unistd.h>
40#endif
41#ifdef HAVE_ERRNO_H
42#include <errno.h>
43#endif 39#endif
44 40
45#include <uudeview.h> 41#include <uudeview.h>
46#include <uuint.h> 42#include <uuint.h>
47#include <fptools.h> 43#include <fptools.h>
251 size_t llen; 247 size_t llen;
252 248
253 if (outfile==NULL || infile==NULL || 249 if (outfile==NULL || infile==NULL ||
254 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 250 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
255 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 251 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
256 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 252 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeStream()");
257 uustring (S_PARM_CHECK), "UUEncodeStream()");
258 return UURET_ILLVAL; 253 return UURET_ILLVAL;
259 } 254 }
260 255
261 /* 256 /*
262 * Special handling for plain text and quoted printable. Text is 257 * Special handling for plain text and quoted printable. Text is
278 /* 273 /*
279 * Busy Callback 274 * Busy Callback
280 */ 275 */
281 276
282 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { 277 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
283 UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, 278 UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL));
284 uustring (S_ENCODE_CANCEL));
285 return UURET_CANCEL; 279 return UURET_CANCEL;
286 } 280 }
287 281
288 if (encoding == PT_ENCODED) { 282 if (encoding == PT_ENCODED) {
289 /* 283 /*
431 /* 425 /*
432 * Busy Callback 426 * Busy Callback
433 */ 427 */
434 428
435 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { 429 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
436 UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, 430 UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL));
437 uustring (S_ENCODE_CANCEL));
438 return UURET_CANCEL; 431 return UURET_CANCEL;
439 } 432 }
440 433
441 for (index=0; index<count; index++) { 434 for (index=0; index<count; index++) {
442 if (llen > 127) { 435 if (llen > 127) {
505 */ 498 */
506 499
507 table = etables[encoding]; 500 table = etables[encoding];
508 501
509 if (table==NULL || bpl[encoding]==0) { 502 if (table==NULL || bpl[encoding]==0) {
510 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
511 uustring (S_PARM_CHECK), "UUEncodeStream()"); 503 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeStream()");
512 return UURET_ILLVAL; 504 return UURET_ILLVAL;
513 } 505 }
514 506
515 while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) { 507 while (!FP_feof (infile) && (linperfile <= 0 || line < linperfile)) {
516 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) { 508 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) {
526 /* 518 /*
527 * Busy Callback 519 * Busy Callback
528 */ 520 */
529 521
530 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) { 522 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
531 UUMessage (uuencode_id, __LINE__, UUMSG_NOTE, 523 UUMessage (UUMSG_NOTE, uustring (S_ENCODE_CANCEL));
532 uustring (S_ENCODE_CANCEL));
533 return UURET_CANCEL; 524 return UURET_CANCEL;
534 } 525 }
535 526
536 /* 527 /*
537 * for UU and XX, encode the number of bytes as first character 528 * for UU and XX, encode the number of bytes as first character
631 if (outfile==NULL || 622 if (outfile==NULL ||
632 (infile == NULL && infname==NULL) || 623 (infile == NULL && infname==NULL) ||
633 (outfname==NULL && infname==NULL) || 624 (outfname==NULL && infname==NULL) ||
634 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 625 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
635 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 626 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
636 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 627 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeMulti()");
637 uustring (S_PARM_CHECK), "UUEncodeMulti()");
638 return UURET_ILLVAL; 628 return UURET_ILLVAL;
639 } 629 }
640 630
641 progress.action = 0; 631 progress.action = 0;
642 632
643 if (infile==NULL) { 633 if (infile==NULL) {
644 if (stat (infname, &finfo) == -1) { 634 if (stat (infname, &finfo) == -1) {
645 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 635 UUMessage (UUMSG_ERROR,
646 uustring (S_NOT_STAT_FILE), 636 uustring (S_NOT_STAT_FILE),
647 infname, strerror (uu_errno=errno)); 637 infname, strerror (uu_errno=errno));
648 return UURET_IOERR; 638 return UURET_IOERR;
649 } 639 }
650 if ((theifile = fopen (infname, "rb")) == NULL) { 640 if ((theifile = fopen (infname, "rb")) == NULL) {
651 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 641 UUMessage (UUMSG_ERROR,
652 uustring (S_NOT_OPEN_FILE), 642 uustring (S_NOT_OPEN_FILE),
653 infname, strerror (uu_errno=errno)); 643 infname, strerror (uu_errno=errno));
654 return UURET_IOERR; 644 return UURET_IOERR;
655 } 645 }
656 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); 646 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
734 } 724 }
735 } 725 }
736 726
737 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { 727 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
738 if (res != UURET_CANCEL) { 728 if (res != UURET_CANCEL) {
739 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 729 UUMessage (UUMSG_ERROR,
740 uustring (S_ERR_ENCODING), 730 uustring (S_ERR_ENCODING),
741 UUFNameFilter ((infname)?infname:outfname), 731 UUFNameFilter ((infname)?infname:outfname),
742 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res)); 732 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res));
743 } 733 }
744 progress.action = 0; 734 progress.action = 0;
801 791
802 if ((outfname==NULL&&infname==NULL) || partno<=0 || 792 if ((outfname==NULL&&infname==NULL) || partno<=0 ||
803 (infile == NULL&&infname==NULL) || outfile==NULL || 793 (infile == NULL&&infname==NULL) || outfile==NULL ||
804 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 794 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
805 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 795 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
806 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 796 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodePartial()");
807 uustring (S_PARM_CHECK), "UUEncodePartial()");
808 return UURET_ILLVAL; 797 return UURET_ILLVAL;
809 } 798 }
810 799
811 /* 800 /*
812 * The first part needs a set of headers 801 * The first part needs a set of headers
815 progress.action = 0; 804 progress.action = 0;
816 805
817 if (partno == 1) { 806 if (partno == 1) {
818 if (infile==NULL) { 807 if (infile==NULL) {
819 if (stat (infname, &finfo) == -1) { 808 if (stat (infname, &finfo) == -1) {
820 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 809 UUMessage (UUMSG_ERROR,
821 uustring (S_NOT_STAT_FILE), 810 uustring (S_NOT_STAT_FILE),
822 infname, strerror (uu_errno=errno)); 811 infname, strerror (uu_errno=errno));
823 return UURET_IOERR; 812 return UURET_IOERR;
824 } 813 }
825 if ((theifile = fopen (infname, "rb")) == NULL) { 814 if ((theifile = fopen (infname, "rb")) == NULL) {
826 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 815 UUMessage (UUMSG_ERROR,
827 uustring (S_NOT_OPEN_FILE), 816 uustring (S_NOT_OPEN_FILE),
828 infname, strerror (uu_errno=errno)); 817 infname, strerror (uu_errno=errno));
829 return UURET_IOERR; 818 return UURET_IOERR;
830 } 819 }
831 if (linperfile <= 0) 820 if (linperfile <= 0)
837 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); 826 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
838 thesize = (long) finfo.st_size; 827 thesize = (long) finfo.st_size;
839 } 828 }
840 else { 829 else {
841 if (fstat (fileno (infile), &finfo) != 0) { 830 if (fstat (fileno (infile), &finfo) != 0) {
842 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, 831 UUMessage (UUMSG_WARNING, uustring (S_STAT_ONE_PART));
843 uustring (S_STAT_ONE_PART));
844 numparts = 1; 832 numparts = 1;
845 themode = (filemode)?filemode:0644; 833 themode = (filemode)?filemode:0644;
846 thesize = -1; 834 thesize = -1;
847 } 835 }
848 else { 836 else {
972 960
973 if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile, 961 if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile,
974 crcptr, pcrcptr)) != UURET_OK) { 962 crcptr, pcrcptr)) != UURET_OK) {
975 if (infile==NULL) fclose (theifile); 963 if (infile==NULL) fclose (theifile);
976 if (res != UURET_CANCEL) { 964 if (res != UURET_CANCEL) {
977 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 965 UUMessage (UUMSG_ERROR,
978 uustring (S_ERR_ENCODING), 966 uustring (S_ERR_ENCODING),
979 UUFNameFilter ((outfname)?outfname:infname), 967 UUFNameFilter ((outfname)?outfname:infname),
980 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 968 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
981 } 969 }
982 progress.action = 0; 970 progress.action = 0;
1060 if (outfile==NULL || 1048 if (outfile==NULL ||
1061 (infile == NULL&&infname==NULL) || 1049 (infile == NULL&&infname==NULL) ||
1062 (outfname==NULL&&infname==NULL) || 1050 (outfname==NULL&&infname==NULL) ||
1063 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1051 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1064 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 1052 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1065 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1053 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeToStream()");
1066 uustring (S_PARM_CHECK), "UUEncodeToStream()");
1067 return UURET_ILLVAL; 1054 return UURET_ILLVAL;
1068 } 1055 }
1069 1056
1070 progress.action = 0; 1057 progress.action = 0;
1071 1058
1072 if (infile==NULL) { 1059 if (infile==NULL) {
1073 if (stat (infname, &finfo) == -1) { 1060 if (stat (infname, &finfo) == -1) {
1074 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1061 UUMessage (UUMSG_ERROR,
1075 uustring (S_NOT_STAT_FILE), 1062 uustring (S_NOT_STAT_FILE),
1076 infname, strerror (uu_errno=errno)); 1063 infname, strerror (uu_errno=errno));
1077 return UURET_IOERR; 1064 return UURET_IOERR;
1078 } 1065 }
1079 if ((theifile = fopen (infname, "rb")) == NULL) { 1066 if ((theifile = fopen (infname, "rb")) == NULL) {
1080 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1067 UUMessage (UUMSG_ERROR,
1081 uustring (S_NOT_OPEN_FILE), 1068 uustring (S_NOT_OPEN_FILE),
1082 infname, strerror (uu_errno=errno)); 1069 infname, strerror (uu_errno=errno));
1083 return UURET_IOERR; 1070 return UURET_IOERR;
1084 } 1071 }
1085 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777); 1072 themode = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
1131 } 1118 }
1132 } 1119 }
1133 1120
1134 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) { 1121 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
1135 if (res != UURET_CANCEL) { 1122 if (res != UURET_CANCEL) {
1136 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1123 UUMessage (UUMSG_ERROR,
1137 uustring (S_ERR_ENCODING), 1124 uustring (S_ERR_ENCODING),
1138 UUFNameFilter ((infname)?infname:outfname), 1125 UUFNameFilter ((infname)?infname:outfname),
1139 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 1126 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
1140 } 1127 }
1141 progress.action = 0; 1128 progress.action = 0;
1191 1178
1192 if ((diskname==NULL&&infname==NULL) || 1179 if ((diskname==NULL&&infname==NULL) ||
1193 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1180 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1194 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1181 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1195 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 1182 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1196 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1183 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUEncodeToFile()");
1197 uustring (S_PARM_CHECK), "UUEncodeToFile()");
1198 return UURET_ILLVAL; 1184 return UURET_ILLVAL;
1199 } 1185 }
1200 1186
1201 if (diskname) { 1187 if (diskname) {
1202 if ((ptr = strchr (diskname, '/')) == NULL) 1188 if ((ptr = strchr (diskname, '/')) == NULL)
1203 ptr = strchr (diskname, '\\'); 1189 ptr = strchr (diskname, '\\');
1204 if (ptr) { 1190 if (ptr) {
1205 len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5; 1191 len = strlen (diskname) + ((uuencodeext)?strlen(uuencodeext):3) + 5;
1206 1192
1207 if ((oname = malloc (len)) == NULL) { 1193 if ((oname = malloc (len)) == NULL) {
1208 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1194 UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len);
1209 uustring (S_OUT_OF_MEMORY), len);
1210 return UURET_NOMEM; 1195 return UURET_NOMEM;
1211 } 1196 }
1212 sprintf (oname, "%s", diskname); 1197 sprintf (oname, "%s", diskname);
1213 } 1198 }
1214 else { 1199 else {
1215 len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname) 1200 len = ((uusavepath)?strlen(uusavepath):0) + strlen (diskname)
1216 + ((uuencodeext)?strlen(uuencodeext):0) + 5; 1201 + ((uuencodeext)?strlen(uuencodeext):0) + 5;
1217 1202
1218 if ((oname = malloc (len)) == NULL) { 1203 if ((oname = malloc (len)) == NULL) {
1219 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1204 UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len);
1220 uustring (S_OUT_OF_MEMORY), len);
1221 return UURET_NOMEM; 1205 return UURET_NOMEM;
1222 } 1206 }
1223 sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname); 1207 sprintf (oname, "%s%s", (uusavepath)?uusavepath:"", diskname);
1224 } 1208 }
1225 } 1209 }
1227 len = ((uusavepath) ? strlen (uusavepath) : 0) + 1211 len = ((uusavepath) ? strlen (uusavepath) : 0) +
1228 strlen(UUFNameFilter(infname)) + 1212 strlen(UUFNameFilter(infname)) +
1229 ((uuencodeext)?strlen(uuencodeext):0) + 5; 1213 ((uuencodeext)?strlen(uuencodeext):0) + 5;
1230 1214
1231 if ((oname = malloc (len)) == NULL) { 1215 if ((oname = malloc (len)) == NULL) {
1232 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1216 UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len);
1233 uustring (S_OUT_OF_MEMORY), len);
1234 return UURET_NOMEM; 1217 return UURET_NOMEM;
1235 } 1218 }
1236 optr = UUFNameFilter (infname); 1219 optr = UUFNameFilter (infname);
1237 sprintf (oname, "%s%s", 1220 sprintf (oname, "%s%s",
1238 (uusavepath)?uusavepath:"", 1221 (uusavepath)?uusavepath:"",
1258 1241
1259 progress.action = 0; 1242 progress.action = 0;
1260 1243
1261 if (infile==NULL) { 1244 if (infile==NULL) {
1262 if (stat (infname, &finfo) == -1) { 1245 if (stat (infname, &finfo) == -1) {
1263 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1246 UUMessage (UUMSG_ERROR,
1264 uustring (S_NOT_STAT_FILE), 1247 uustring (S_NOT_STAT_FILE),
1265 infname, strerror (uu_errno=errno)); 1248 infname, strerror (uu_errno=errno));
1266 FP_free (oname); 1249 FP_free (oname);
1267 return UURET_IOERR; 1250 return UURET_IOERR;
1268 } 1251 }
1269 if ((theifile = fopen (infname, "rb")) == NULL) { 1252 if ((theifile = fopen (infname, "rb")) == NULL) {
1270 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1253 UUMessage (UUMSG_ERROR,
1271 uustring (S_NOT_OPEN_FILE), 1254 uustring (S_NOT_OPEN_FILE),
1272 infname, strerror (uu_errno=errno)); 1255 infname, strerror (uu_errno=errno));
1273 FP_free (oname); 1256 FP_free (oname);
1274 return UURET_IOERR; 1257 return UURET_IOERR;
1275 } 1258 }
1320 * check if target file exists 1303 * check if target file exists
1321 */ 1304 */
1322 1305
1323 if (!uu_overwrite) { 1306 if (!uu_overwrite) {
1324 if (stat (oname, &finfo) == 0) { 1307 if (stat (oname, &finfo) == 0) {
1325 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1308 UUMessage (UUMSG_ERROR, uustring (S_TARGET_EXISTS), oname);
1326 uustring (S_TARGET_EXISTS), oname);
1327 if (infile==NULL) fclose (theifile); 1309 if (infile==NULL) fclose (theifile);
1328 progress.action = 0; 1310 progress.action = 0;
1329 free (oname); 1311 free (oname);
1330 return UURET_EXISTS; 1312 return UURET_EXISTS;
1331 } 1313 }
1350 progress.fsize = linperfile*bpl[encoding]; 1332 progress.fsize = linperfile*bpl[encoding];
1351 1333
1352 progress.action = UUACT_ENCODING; 1334 progress.action = UUACT_ENCODING;
1353 1335
1354 if ((outfile = fopen (oname, "w")) == NULL) { 1336 if ((outfile = fopen (oname, "w")) == NULL) {
1355 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1337 UUMessage (UUMSG_ERROR,
1356 uustring (S_NOT_OPEN_TARGET), 1338 uustring (S_NOT_OPEN_TARGET),
1357 oname, strerror (uu_errno = errno)); 1339 oname, strerror (uu_errno = errno));
1358 if (infile==NULL) fclose (theifile); 1340 if (infile==NULL) fclose (theifile);
1359 progress.action = 0; 1341 progress.action = 0;
1360 free (oname); 1342 free (oname);
1427 } 1409 }
1428 1410
1429 if ((res = UUEncodeStream (outfile, theifile, 1411 if ((res = UUEncodeStream (outfile, theifile,
1430 encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) { 1412 encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) {
1431 if (res != UURET_CANCEL) { 1413 if (res != UURET_CANCEL) {
1432 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1414 UUMessage (UUMSG_ERROR,
1433 uustring (S_ERR_ENCODING), 1415 uustring (S_ERR_ENCODING),
1434 UUFNameFilter ((infname)?infname:outfname), 1416 UUFNameFilter ((infname)?infname:outfname),
1435 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 1417 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
1436 } 1418 }
1437 if (infile==NULL) fclose (theifile); 1419 if (infile==NULL) fclose (theifile);
1515 int res, len; 1497 int res, len;
1516 1498
1517 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1499 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1518 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1500 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1519 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 1501 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1520 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1502 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUE_PrepSingle()");
1521 uustring (S_PARM_CHECK), "UUE_PrepSingle()");
1522 return UURET_ILLVAL; 1503 return UURET_ILLVAL;
1523 } 1504 }
1524 1505
1525 oname = UUFNameFilter ((outfname)?outfname:infname); 1506 oname = UUFNameFilter ((outfname)?outfname:infname);
1526 len = ((subject)?strlen(subject):0) + strlen(oname) + 40; 1507 len = ((subject)?strlen(subject):0) + strlen(oname) + 40;
1536 if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) { 1517 if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) {
1537 mimetype = "text/plain"; 1518 mimetype = "text/plain";
1538 } 1519 }
1539 1520
1540 if ((subline = (char *) malloc (len)) == NULL) { 1521 if ((subline = (char *) malloc (len)) == NULL) {
1541 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1522 UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len);
1542 uustring (S_OUT_OF_MEMORY), len);
1543 return UURET_NOMEM; 1523 return UURET_NOMEM;
1544 } 1524 }
1545 1525
1546 if (encoding == YENC_ENCODED) { 1526 if (encoding == YENC_ENCODED) {
1547 if (subject) 1527 if (subject)
1627 crc32_t *crcptr=NULL; 1607 crc32_t *crcptr=NULL;
1628 1608
1629 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1609 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1630 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1610 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1631 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) { 1611 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1632 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1612 UUMessage (UUMSG_ERROR, uustring (S_PARM_CHECK), "UUE_PrepPartial()");
1633 uustring (S_PARM_CHECK), "UUE_PrepPartial()");
1634 return UURET_ILLVAL; 1613 return UURET_ILLVAL;
1635 } 1614 }
1636 1615
1637 oname = UUFNameFilter ((outfname)?outfname:infname); 1616 oname = UUFNameFilter ((outfname)?outfname:infname);
1638 len = ((subject)?strlen(subject):0) + strlen (oname) + 40; 1617 len = ((subject)?strlen(subject):0) + strlen (oname) + 40;
1642 */ 1621 */
1643 1622
1644 if (partno == 1) { 1623 if (partno == 1) {
1645 if (infile==NULL) { 1624 if (infile==NULL) {
1646 if (stat (infname, &finfo) == -1) { 1625 if (stat (infname, &finfo) == -1) {
1647 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1626 UUMessage (UUMSG_ERROR,
1648 uustring (S_NOT_STAT_FILE), 1627 uustring (S_NOT_STAT_FILE),
1649 infname, strerror (uu_errno=errno)); 1628 infname, strerror (uu_errno=errno));
1650 return UURET_IOERR; 1629 return UURET_IOERR;
1651 } 1630 }
1652 if ((theifile = fopen (infname, "rb")) == NULL) { 1631 if ((theifile = fopen (infname, "rb")) == NULL) {
1653 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1632 UUMessage (UUMSG_ERROR,
1654 uustring (S_NOT_OPEN_FILE), 1633 uustring (S_NOT_OPEN_FILE),
1655 infname, strerror (uu_errno=errno)); 1634 infname, strerror (uu_errno=errno));
1656 return UURET_IOERR; 1635 return UURET_IOERR;
1657 } 1636 }
1658 if (linperfile <= 0) 1637 if (linperfile <= 0)
1665 thesize = (long) finfo.st_size; 1644 thesize = (long) finfo.st_size;
1666 } 1645 }
1667 else { 1646 else {
1668 if (fstat (fileno (infile), &finfo) != 0) { 1647 if (fstat (fileno (infile), &finfo) != 0) {
1669 if (filesize <= 0) { 1648 if (filesize <= 0) {
1670 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, 1649 UUMessage (UUMSG_WARNING, uustring (S_STAT_ONE_PART));
1671 uustring (S_STAT_ONE_PART));
1672 numparts = 1; 1650 numparts = 1;
1673 themode = (filemode)?filemode:0644; 1651 themode = (filemode)?filemode:0644;
1674 thesize = -1; 1652 thesize = -1;
1675 } 1653 }
1676 else { 1654 else {
1716 (long) time(NULL), thesize, 1694 (long) time(NULL), thesize,
1717 (strlen(oname)>16)?"oops":oname); 1695 (strlen(oname)>16)?"oops":oname);
1718 } 1696 }
1719 1697
1720 if ((subline = (char *) malloc (len)) == NULL) { 1698 if ((subline = (char *) malloc (len)) == NULL) {
1721 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1699 UUMessage (UUMSG_ERROR, uustring (S_OUT_OF_MEMORY), len);
1722 uustring (S_OUT_OF_MEMORY), len);
1723 if (infile==NULL) fclose (theifile); 1700 if (infile==NULL) fclose (theifile);
1724 return UURET_NOMEM; 1701 return UURET_NOMEM;
1725 } 1702 }
1726 1703
1727 1704

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines