… | |
… | |
81 | #include <fptools.h> |
81 | #include <fptools.h> |
82 | #include <uustring.h> |
82 | #include <uustring.h> |
83 | |
83 | |
84 | #include "safealloc.c" |
84 | #include "safealloc.c" |
85 | |
85 | |
86 | char * uulib_id = "$Id: uulib.c,v 1.23 2020/12/10 22:49:15 root Exp $"; |
86 | char * uulib_id = "$Id: uulib.c,v 1.24 2020/12/11 20:09:23 root Exp $"; |
87 | |
87 | |
88 | #ifdef SYSTEM_WINDLL |
88 | #ifdef SYSTEM_WINDLL |
89 | BOOL _export WINAPI |
89 | BOOL _export WINAPI |
90 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
90 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
91 | LPVOID lpCmdLine) |
91 | LPVOID lpCmdLine) |
… | |
… | |
436 | case UUOPT_WBUF: |
436 | case UUOPT_WBUF: |
437 | *ivalue = uu_wbuf; |
437 | *ivalue = uu_wbuf; |
438 | result = 0; |
438 | result = 0; |
439 | break; |
439 | break; |
440 | case UUOPT_VERSION: |
440 | case UUOPT_VERSION: |
441 | _FP_strncpy (cvalue, uulibversion, clength); |
441 | FP_strncpy (cvalue, uulibversion, clength); |
442 | result = 0; |
442 | result = 0; |
443 | break; |
443 | break; |
444 | case UUOPT_FAST: |
444 | case UUOPT_FAST: |
445 | if (ivalue) *ivalue = uu_fast_scanning; |
445 | if (ivalue) *ivalue = uu_fast_scanning; |
446 | result = uu_fast_scanning; |
446 | result = uu_fast_scanning; |
… | |
… | |
476 | case UUOPT_OVERWRITE: |
476 | case UUOPT_OVERWRITE: |
477 | if (ivalue) *ivalue = uu_overwrite; |
477 | if (ivalue) *ivalue = uu_overwrite; |
478 | result = uu_overwrite; |
478 | result = uu_overwrite; |
479 | break; |
479 | break; |
480 | case UUOPT_SAVEPATH: |
480 | case UUOPT_SAVEPATH: |
481 | _FP_strncpy (cvalue, uusavepath, clength); |
481 | FP_strncpy (cvalue, uusavepath, clength); |
482 | result = 0; |
482 | result = 0; |
483 | break; |
483 | break; |
484 | case UUOPT_PROGRESS: |
484 | case UUOPT_PROGRESS: |
485 | if (clength==sizeof(uuprogress)) { |
485 | if (clength==sizeof(uuprogress)) { |
486 | memcpy (cvalue, &progress, sizeof (uuprogress)); |
486 | memcpy (cvalue, &progress, sizeof (uuprogress)); |
… | |
… | |
504 | case UUOPT_TINYB64: |
504 | case UUOPT_TINYB64: |
505 | if (ivalue) *ivalue = uu_tinyb64; |
505 | if (ivalue) *ivalue = uu_tinyb64; |
506 | result = uu_tinyb64; |
506 | result = uu_tinyb64; |
507 | break; |
507 | break; |
508 | case UUOPT_ENCEXT: |
508 | case UUOPT_ENCEXT: |
509 | _FP_strncpy (cvalue, uuencodeext, clength); |
509 | FP_strncpy (cvalue, uuencodeext, clength); |
510 | result = 0; |
510 | result = 0; |
511 | break; |
511 | break; |
512 | case UUOPT_REMOVE: |
512 | case UUOPT_REMOVE: |
513 | if (ivalue) *ivalue = uu_remove_input; |
513 | if (ivalue) *ivalue = uu_remove_input; |
514 | result = uu_remove_input; |
514 | result = uu_remove_input; |
… | |
… | |
564 | break; |
564 | break; |
565 | case UUOPT_OVERWRITE: |
565 | case UUOPT_OVERWRITE: |
566 | uu_overwrite = ivalue; |
566 | uu_overwrite = ivalue; |
567 | break; |
567 | break; |
568 | case UUOPT_SAVEPATH: |
568 | case UUOPT_SAVEPATH: |
569 | _FP_free (uusavepath); |
569 | FP_free (uusavepath); |
570 | uusavepath = _FP_strdup (cvalue); |
570 | uusavepath = FP_strdup (cvalue); |
571 | break; |
571 | break; |
572 | case UUOPT_IGNMODE: |
572 | case UUOPT_IGNMODE: |
573 | uu_ignmode = ivalue; |
573 | uu_ignmode = ivalue; |
574 | break; |
574 | break; |
575 | case UUOPT_USETEXT: |
575 | case UUOPT_USETEXT: |
… | |
… | |
580 | break; |
580 | break; |
581 | case UUOPT_TINYB64: |
581 | case UUOPT_TINYB64: |
582 | uu_tinyb64 = ivalue; |
582 | uu_tinyb64 = ivalue; |
583 | break; |
583 | break; |
584 | case UUOPT_ENCEXT: |
584 | case UUOPT_ENCEXT: |
585 | _FP_free (uuencodeext); |
585 | FP_free (uuencodeext); |
586 | uuencodeext = _FP_strdup (cvalue); |
586 | uuencodeext = FP_strdup (cvalue); |
587 | break; |
587 | break; |
588 | case UUOPT_REMOVE: |
588 | case UUOPT_REMOVE: |
589 | uu_remove_input = ivalue; |
589 | uu_remove_input = ivalue; |
590 | break; |
590 | break; |
591 | case UUOPT_MOREMIME: |
591 | case UUOPT_MOREMIME: |
… | |
… | |
749 | if (delflag && fileid==NULL) { |
749 | if (delflag && fileid==NULL) { |
750 | if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) { |
750 | if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) { |
751 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
751 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
752 | uustring (S_OUT_OF_MEMORY), sizeof (itbd)); |
752 | uustring (S_OUT_OF_MEMORY), sizeof (itbd)); |
753 | } |
753 | } |
754 | else if ((killem->fname = _FP_strdup (filename)) == NULL) { |
754 | else if ((killem->fname = FP_strdup (filename)) == NULL) { |
755 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
755 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
756 | uustring (S_OUT_OF_MEMORY), strlen(filename)+1); |
756 | uustring (S_OUT_OF_MEMORY), strlen(filename)+1); |
757 | _FP_free (killem); |
757 | FP_free (killem); |
758 | } |
758 | } |
759 | else { |
759 | else { |
760 | killem->NEXT = ftodel; |
760 | killem->NEXT = ftodel; |
761 | ftodel = killem; |
761 | ftodel = killem; |
762 | } |
762 | } |
… | |
… | |
766 | progress.partno = 0; |
766 | progress.partno = 0; |
767 | progress.numparts = 1; |
767 | progress.numparts = 1; |
768 | progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1); |
768 | progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1); |
769 | progress.percent = 0; |
769 | progress.percent = 0; |
770 | progress.foffset = 0; |
770 | progress.foffset = 0; |
771 | _FP_strncpy (progress.curfile, |
771 | FP_strncpy (progress.curfile, |
772 | (strlen(filename)>255)? |
772 | (strlen(filename)>255)? |
773 | (filename+strlen(filename)-255):filename, |
773 | (filename+strlen(filename)-255):filename, |
774 | 256); |
774 | 256); |
775 | progress.action = UUACT_SCANNING; |
775 | progress.action = UUACT_SCANNING; |
776 | |
776 | |
777 | if (fileid == NULL) |
777 | if (fileid == NULL) |
778 | fileid = filename; |
778 | fileid = filename; |
779 | |
779 | |
780 | while (!feof (datei) && !ferror (datei)) { |
780 | while (!FP_feof (datei) && !ferror (datei)) { |
781 | /* |
781 | /* |
782 | * Peek file, or some systems won't detect EOF |
782 | * Peek file, or some systems won't detect EOF |
783 | */ |
783 | */ |
784 | res = _FP_fgetc (datei); |
784 | res = FP_getc (datei); |
785 | if (feof (datei) || ferror (datei)) |
785 | if (FP_feof (datei) || ferror (datei)) |
786 | break; |
786 | break; |
787 | else |
787 | else |
788 | ungetc (res, datei); |
788 | ungetc (res, datei); |
789 | |
789 | |
790 | if ((loaded = ScanPart (datei, fileid, &sr)) == NULL) { |
790 | if ((loaded = ScanPart (datei, fileid, &sr)) == NULL) { |
… | |
… | |
1037 | #endif |
1037 | #endif |
1038 | goto skip_copy; |
1038 | goto skip_copy; |
1039 | } |
1039 | } |
1040 | |
1040 | |
1041 | progress.action = 0; |
1041 | progress.action = 0; |
1042 | _FP_strncpy (progress.curfile, |
1042 | FP_strncpy (progress.curfile, |
1043 | (strlen(uugen_fnbuffer)>255)? |
1043 | (strlen(uugen_fnbuffer)>255)? |
1044 | (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer, |
1044 | (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer, |
1045 | 256); |
1045 | 256); |
1046 | progress.partno = 0; |
1046 | progress.partno = 0; |
1047 | progress.numparts = 1; |
1047 | progress.numparts = 1; |
… | |
… | |
1072 | close (fildes); |
1072 | close (fildes); |
1073 | return UURET_IOERR; |
1073 | return UURET_IOERR; |
1074 | } |
1074 | } |
1075 | UUSETBUF (target, target_buf, uu_wbuf); |
1075 | UUSETBUF (target, target_buf, uu_wbuf); |
1076 | |
1076 | |
1077 | while (!feof (source)) { |
1077 | while (!FP_feof (source)) { |
1078 | |
1078 | |
1079 | if (UUBUSYPOLL(ftell(source),progress.fsize)) { |
1079 | if (UUBUSYPOLL(ftell(source),progress.fsize)) { |
1080 | UUMessage (uulib_id, __LINE__, UUMSG_NOTE, |
1080 | UUMessage (uulib_id, __LINE__, UUMSG_NOTE, |
1081 | uustring (S_DECODE_CANCEL)); |
1081 | uustring (S_DECODE_CANCEL)); |
1082 | fclose (source); |
1082 | fclose (source); |
… | |
… | |
1087 | return UURET_CANCEL; |
1087 | return UURET_CANCEL; |
1088 | } |
1088 | } |
1089 | |
1089 | |
1090 | bytes = fread (uugen_inbuffer, 1, 1024, source); |
1090 | bytes = fread (uugen_inbuffer, 1, 1024, source); |
1091 | |
1091 | |
1092 | if (ferror (source) || (bytes == 0 && !feof (source))) { |
1092 | if (ferror (source) || (bytes == 0 && !FP_feof (source))) { |
1093 | progress.action = 0; |
1093 | progress.action = 0; |
1094 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1094 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1095 | uustring (S_READ_ERROR), |
1095 | uustring (S_READ_ERROR), |
1096 | thefile->binfile, strerror (uu_errno = errno)); |
1096 | thefile->binfile, strerror (uu_errno = errno)); |
1097 | fclose (source); |
1097 | fclose (source); |
… | |
… | |
1137 | thefile->binfile, |
1137 | thefile->binfile, |
1138 | strerror (uu_errno = errno)); |
1138 | strerror (uu_errno = errno)); |
1139 | } |
1139 | } |
1140 | |
1140 | |
1141 | skip_copy: |
1141 | skip_copy: |
1142 | _FP_free (thefile->binfile); |
1142 | FP_free (thefile->binfile); |
1143 | thefile->binfile = NULL; |
1143 | thefile->binfile = NULL; |
1144 | thefile->state &= ~UUFILE_TMPFILE; |
1144 | thefile->state &= ~UUFILE_TMPFILE; |
1145 | thefile->state |= UUFILE_DECODED; |
1145 | thefile->state |= UUFILE_DECODED; |
1146 | progress.action = 0; |
1146 | progress.action = 0; |
1147 | |
1147 | |
… | |
… | |
1186 | uustring (S_NOT_OPEN_FILE), |
1186 | uustring (S_NOT_OPEN_FILE), |
1187 | thefile->thisfile->data->sfname, |
1187 | thefile->thisfile->data->sfname, |
1188 | strerror (uu_errno=errno)); |
1188 | strerror (uu_errno=errno)); |
1189 | return UURET_IOERR; |
1189 | return UURET_IOERR; |
1190 | } |
1190 | } |
1191 | _FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024); |
1191 | FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024); |
1192 | } |
1192 | } |
1193 | |
1193 | |
1194 | /* |
1194 | /* |
1195 | * seek to beginning of info |
1195 | * seek to beginning of info |
1196 | */ |
1196 | */ |
1197 | |
1197 | |
1198 | fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET); |
1198 | fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET); |
1199 | maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length; |
1199 | maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length; |
1200 | |
1200 | |
1201 | while (!feof (inpfile) && |
1201 | while (!FP_feof (inpfile) && |
1202 | (uu_fast_scanning || ftell(inpfile) < maxpos)) { |
1202 | (uu_fast_scanning || ftell(inpfile) < maxpos)) { |
1203 | if (_FP_fgets (uugen_inbuffer, 511, inpfile) == NULL) |
1203 | if (FP_fgets (uugen_inbuffer, 511, inpfile) == NULL) |
1204 | break; |
1204 | break; |
1205 | uugen_inbuffer[511] = '\0'; |
1205 | uugen_inbuffer[511] = '\0'; |
1206 | |
1206 | |
1207 | if (ferror (inpfile)) |
1207 | if (ferror (inpfile)) |
1208 | break; |
1208 | break; |
… | |
… | |
1252 | if (thefile == NULL) |
1252 | if (thefile == NULL) |
1253 | return UURET_ILLVAL; |
1253 | return UURET_ILLVAL; |
1254 | |
1254 | |
1255 | oldname = thefile->filename; |
1255 | oldname = thefile->filename; |
1256 | |
1256 | |
1257 | if ((thefile->filename = _FP_strdup (newname)) == NULL) { |
1257 | if ((thefile->filename = FP_strdup (newname)) == NULL) { |
1258 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1258 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1259 | uustring (S_NOT_RENAME), |
1259 | uustring (S_NOT_RENAME), |
1260 | oldname, newname); |
1260 | oldname, newname); |
1261 | thefile->filename = oldname; |
1261 | thefile->filename = oldname; |
1262 | return UURET_NOMEM; |
1262 | return UURET_NOMEM; |
1263 | } |
1263 | } |
1264 | _FP_free (oldname); |
1264 | FP_free (oldname); |
1265 | return UURET_OK; |
1265 | return UURET_OK; |
1266 | } |
1266 | } |
1267 | |
1267 | |
1268 | int UUEXPORT |
1268 | int UUEXPORT |
1269 | UURemoveTemp (uulist *thefile) |
1269 | UURemoveTemp (uulist *thefile) |
… | |
… | |
1276 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1276 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1277 | uustring (S_TMP_NOT_REMOVED), |
1277 | uustring (S_TMP_NOT_REMOVED), |
1278 | thefile->binfile, |
1278 | thefile->binfile, |
1279 | strerror (uu_errno = errno)); |
1279 | strerror (uu_errno = errno)); |
1280 | } |
1280 | } |
1281 | _FP_free (thefile->binfile); |
1281 | FP_free (thefile->binfile); |
1282 | thefile->binfile = NULL; |
1282 | thefile->binfile = NULL; |
1283 | thefile->state &= ~UUFILE_TMPFILE; |
1283 | thefile->state &= ~UUFILE_TMPFILE; |
1284 | } |
1284 | } |
1285 | return UURET_OK; |
1285 | return UURET_OK; |
1286 | } |
1286 | } |
… | |
… | |
1301 | if (unlink (iter->fname)) { |
1301 | if (unlink (iter->fname)) { |
1302 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1302 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1303 | uustring (S_TMP_NOT_REMOVED), |
1303 | uustring (S_TMP_NOT_REMOVED), |
1304 | iter->fname, strerror (uu_errno = errno)); |
1304 | iter->fname, strerror (uu_errno = errno)); |
1305 | } |
1305 | } |
1306 | _FP_free (iter->fname); |
1306 | FP_free (iter->fname); |
1307 | ptr = iter; |
1307 | ptr = iter; |
1308 | iter = iter->NEXT; |
1308 | iter = iter->NEXT; |
1309 | _FP_free (ptr); |
1309 | FP_free (ptr); |
1310 | } |
1310 | } |
1311 | |
1311 | |
1312 | ftodel = NULL; |
1312 | ftodel = NULL; |
1313 | |
1313 | |
1314 | /* |
1314 | /* |
… | |
… | |
1336 | } |
1336 | } |
1337 | |
1337 | |
1338 | UUkilllist (UUGlobalFileList); |
1338 | UUkilllist (UUGlobalFileList); |
1339 | UUGlobalFileList = NULL; |
1339 | UUGlobalFileList = NULL; |
1340 | |
1340 | |
1341 | _FP_free (uusavepath); |
1341 | FP_free (uusavepath); |
1342 | _FP_free (uuencodeext); |
1342 | FP_free (uuencodeext); |
1343 | _FP_free (sstate.source); |
1343 | FP_free (sstate.source); |
1344 | |
1344 | |
1345 | uusavepath = NULL; |
1345 | uusavepath = NULL; |
1346 | uuencodeext = NULL; |
1346 | uuencodeext = NULL; |
1347 | |
1347 | |
1348 | UUkillheaders (&localenv); |
1348 | UUkillheaders (&localenv); |
… | |
… | |
1351 | memset (&sstate, 0, sizeof (scanstate)); |
1351 | memset (&sstate, 0, sizeof (scanstate)); |
1352 | |
1352 | |
1353 | while (mssdepth) { |
1353 | while (mssdepth) { |
1354 | mssdepth--; |
1354 | mssdepth--; |
1355 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1355 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1356 | _FP_free (multistack[mssdepth].source); |
1356 | FP_free (multistack[mssdepth].source); |
1357 | } |
1357 | } |
1358 | |
1358 | |
1359 | /* |
1359 | /* |
1360 | * clean up the malloc'ed stuff |
1360 | * clean up the malloc'ed stuff |
1361 | */ |
1361 | */ |