… | |
… | |
79 | #include <uudeview.h> |
79 | #include <uudeview.h> |
80 | #include <uuint.h> |
80 | #include <uuint.h> |
81 | #include <fptools.h> |
81 | #include <fptools.h> |
82 | #include <uustring.h> |
82 | #include <uustring.h> |
83 | |
83 | |
84 | char * uulib_id = "$Id: uulib.c,v 1.4 2001/06/12 09:56:11 root Exp $"; |
84 | char * uulib_id = "$Id: uulib.c,v 1.4.2.5 2004/04/18 19:55:46 root Exp $"; |
85 | |
85 | |
86 | #ifdef SYSTEM_WINDLL |
86 | #ifdef SYSTEM_WINDLL |
87 | BOOL _export WINAPI |
87 | BOOL _export WINAPI |
88 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
88 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
89 | LPVOID lpCmdLine) |
89 | LPVOID lpCmdLine) |
… | |
… | |
112 | |
112 | |
113 | /* |
113 | /* |
114 | * Callback functions and their opaque arguments |
114 | * Callback functions and their opaque arguments |
115 | */ |
115 | */ |
116 | |
116 | |
117 | void (*uu_MsgCallback) (void *, char *, int) = NULL; |
117 | void (*uu_MsgCallback) _ANSI_ARGS_((void *, char *, int)) = NULL; |
118 | int (*uu_BusyCallback) (void *, uuprogress *) = NULL; |
118 | int (*uu_BusyCallback) _ANSI_ARGS_((void *, uuprogress *)) = NULL; |
119 | int (*uu_FileCallback) (void *, char *, char *, int) = NULL; |
119 | int (*uu_FileCallback) _ANSI_ARGS_((void *, char *, char *, int)) = NULL; |
120 | char * (*uu_FNameFilter) (void *, char *) = NULL; |
120 | char * (*uu_FNameFilter) _ANSI_ARGS_((void *, char *)) = NULL; |
121 | |
121 | |
122 | void *uu_MsgCBArg = NULL; |
122 | void *uu_MsgCBArg = NULL; |
123 | void *uu_BusyCBArg = NULL; |
123 | void *uu_BusyCBArg = NULL; |
124 | void *uu_FileCBArg = NULL; |
124 | void *uu_FileCBArg = NULL; |
125 | void *uu_FFCBArg = NULL; |
125 | void *uu_FFCBArg = NULL; |
… | |
… | |
231 | { &uucheck_lastname, 256 }, /* from uucheck.c */ |
231 | { &uucheck_lastname, 256 }, /* from uucheck.c */ |
232 | { &uucheck_tempname, 256 }, |
232 | { &uucheck_tempname, 256 }, |
233 | { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */ |
233 | { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */ |
234 | { &uuestr_otemp, 1024 }, |
234 | { &uuestr_otemp, 1024 }, |
235 | { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */ |
235 | { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */ |
236 | { &uuncdl_fulline, 256+4 }, /* from uunconc.c:UUDecodeLine(). +4 is for leftover parts */ |
236 | { &uuncdl_fulline, 300 }, /* from uunconc.c:UUDecodeLine() */ |
237 | { &uuncdp_oline, 4*257 }, /* from uunconc.c:UUDecodePart() */ |
237 | { &uuncdp_oline, 1200 }, /* from uunconc.c:UUDecodePart() */ |
238 | { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */ |
238 | { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */ |
239 | { &uunconc_UUxlen, 64 * sizeof (int) }, |
239 | { &uunconc_UUxlen, 64 * sizeof (int) }, |
240 | { &uunconc_B64xlat, 256 * sizeof (int) }, |
240 | { &uunconc_B64xlat, 256 * sizeof (int) }, |
241 | { &uunconc_XXxlat, 256 * sizeof (int) }, |
241 | { &uunconc_XXxlat, 256 * sizeof (int) }, |
242 | { &uunconc_BHxlat, 256 * sizeof (int) }, |
242 | { &uunconc_BHxlat, 256 * sizeof (int) }, |
243 | { &uunconc_save, 3*256 }, /* from uunconc.c:decoding buffer */ |
243 | { &uunconc_save, 3*300 }, /* from uunconc.c:decoding buffer */ |
244 | { &uuscan_shlline, 1024 }, /* from uuscan.c:ScanHeaderLine() */ |
244 | { &uuscan_shlline, 1024 }, /* from uuscan.c:ScanHeaderLine() */ |
|
|
245 | { &uuscan_shlline2, 1024 }, /* from uuscan.c:ScanHeaderLine() */ |
245 | { &uuscan_pvvalue, 256 }, /* from uuscan.c:ParseValue() */ |
246 | { &uuscan_pvvalue, 300 }, /* from uuscan.c:ParseValue() */ |
246 | { &uuscan_phtext, 256 }, /* from uuscan.c:ParseHeader() */ |
247 | { &uuscan_phtext, 300 }, /* from uuscan.c:ParseHeader() */ |
247 | { &uuscan_sdline, 256 }, /* from uuscan.c:ScanData() */ |
248 | { &uuscan_sdline, 300 }, /* from uuscan.c:ScanData() */ |
248 | { &uuscan_sdbhds1, 256 }, |
249 | { &uuscan_sdbhds1, 300 }, |
249 | { &uuscan_sdbhds2, 256 }, |
250 | { &uuscan_sdbhds2, 300 }, |
250 | { &uuscan_spline, 256 }, /* from uuscan.c:ScanPart() */ |
251 | { &uuscan_spline, 300 }, /* from uuscan.c:ScanPart() */ |
251 | { &uuutil_bhwtmp, 256 }, /* from uuutil.c:UUbhwrite() */ |
252 | { &uuutil_bhwtmp, 300 }, /* from uuutil.c:UUbhwrite() */ |
252 | { NULL, 0 } |
253 | { NULL, 0 } |
253 | }; |
254 | }; |
254 | |
255 | |
255 | /* |
256 | /* |
256 | * Handle the printing of messages. Works like printf. |
257 | * Handle the printing of messages. Works like printf. |
… | |
… | |
390 | /* |
391 | /* |
391 | * oops. we may not print a message here, because we need these |
392 | * oops. we may not print a message here, because we need these |
392 | * areas (uulib_msgstring) in UUMessage() |
393 | * areas (uulib_msgstring) in UUMessage() |
393 | */ |
394 | */ |
394 | for (aiter=toallocate; aiter->ptr; aiter++) { |
395 | for (aiter=toallocate; aiter->ptr; aiter++) { |
395 | FP_free (*(aiter->ptr)); |
396 | _FP_free (*(aiter->ptr)); |
396 | } |
397 | } |
397 | return UURET_NOMEM; |
398 | return UURET_NOMEM; |
398 | } |
399 | } |
399 | } |
400 | } |
400 | |
401 | |
… | |
… | |
416 | { |
417 | { |
417 | int result; |
418 | int result; |
418 | |
419 | |
419 | switch (option) { |
420 | switch (option) { |
420 | case UUOPT_VERSION: |
421 | case UUOPT_VERSION: |
421 | FP_strncpy (cvalue, uulibversion, clength); |
422 | _FP_strncpy (cvalue, uulibversion, clength); |
422 | result = 0; |
423 | result = 0; |
423 | break; |
424 | break; |
424 | case UUOPT_FAST: |
425 | case UUOPT_FAST: |
425 | if (ivalue) *ivalue = uu_fast_scanning; |
426 | if (ivalue) *ivalue = uu_fast_scanning; |
426 | result = uu_fast_scanning; |
427 | result = uu_fast_scanning; |
… | |
… | |
456 | case UUOPT_OVERWRITE: |
457 | case UUOPT_OVERWRITE: |
457 | if (ivalue) *ivalue = uu_overwrite; |
458 | if (ivalue) *ivalue = uu_overwrite; |
458 | result = uu_overwrite; |
459 | result = uu_overwrite; |
459 | break; |
460 | break; |
460 | case UUOPT_SAVEPATH: |
461 | case UUOPT_SAVEPATH: |
461 | FP_strncpy (cvalue, uusavepath, clength); |
462 | _FP_strncpy (cvalue, uusavepath, clength); |
462 | result = 0; |
463 | result = 0; |
463 | break; |
464 | break; |
464 | case UUOPT_PROGRESS: |
465 | case UUOPT_PROGRESS: |
465 | if (clength==sizeof(uuprogress)) { |
466 | if (clength==sizeof(uuprogress)) { |
466 | memcpy (cvalue, &progress, sizeof (uuprogress)); |
467 | memcpy (cvalue, &progress, sizeof (uuprogress)); |
… | |
… | |
484 | case UUOPT_TINYB64: |
485 | case UUOPT_TINYB64: |
485 | if (ivalue) *ivalue = uu_tinyb64; |
486 | if (ivalue) *ivalue = uu_tinyb64; |
486 | result = uu_tinyb64; |
487 | result = uu_tinyb64; |
487 | break; |
488 | break; |
488 | case UUOPT_ENCEXT: |
489 | case UUOPT_ENCEXT: |
489 | FP_strncpy (cvalue, uuencodeext, clength); |
490 | _FP_strncpy (cvalue, uuencodeext, clength); |
490 | result = 0; |
491 | result = 0; |
491 | break; |
492 | break; |
492 | case UUOPT_REMOVE: |
493 | case UUOPT_REMOVE: |
493 | if (ivalue) *ivalue = uu_remove_input; |
494 | if (ivalue) *ivalue = uu_remove_input; |
494 | result = uu_remove_input; |
495 | result = uu_remove_input; |
… | |
… | |
530 | break; |
531 | break; |
531 | case UUOPT_OVERWRITE: |
532 | case UUOPT_OVERWRITE: |
532 | uu_overwrite = ivalue; |
533 | uu_overwrite = ivalue; |
533 | break; |
534 | break; |
534 | case UUOPT_SAVEPATH: |
535 | case UUOPT_SAVEPATH: |
535 | FP_free (uusavepath); |
536 | _FP_free (uusavepath); |
536 | uusavepath = FP_strdup (cvalue); |
537 | uusavepath = _FP_strdup (cvalue); |
537 | break; |
538 | break; |
538 | case UUOPT_IGNMODE: |
539 | case UUOPT_IGNMODE: |
539 | uu_ignmode = ivalue; |
540 | uu_ignmode = ivalue; |
540 | break; |
541 | break; |
541 | case UUOPT_USETEXT: |
542 | case UUOPT_USETEXT: |
… | |
… | |
546 | break; |
547 | break; |
547 | case UUOPT_TINYB64: |
548 | case UUOPT_TINYB64: |
548 | uu_tinyb64 = ivalue; |
549 | uu_tinyb64 = ivalue; |
549 | break; |
550 | break; |
550 | case UUOPT_ENCEXT: |
551 | case UUOPT_ENCEXT: |
551 | FP_free (uuencodeext); |
552 | _FP_free (uuencodeext); |
552 | uuencodeext = FP_strdup (cvalue); |
553 | uuencodeext = _FP_strdup (cvalue); |
553 | break; |
554 | break; |
554 | case UUOPT_REMOVE: |
555 | case UUOPT_REMOVE: |
555 | uu_remove_input = ivalue; |
556 | uu_remove_input = ivalue; |
556 | break; |
557 | break; |
557 | case UUOPT_MOREMIME: |
558 | case UUOPT_MOREMIME: |
… | |
… | |
573 | * Set the various Callback functions |
574 | * Set the various Callback functions |
574 | */ |
575 | */ |
575 | |
576 | |
576 | int UUEXPORT |
577 | int UUEXPORT |
577 | UUSetMsgCallback (void *opaque, |
578 | UUSetMsgCallback (void *opaque, |
578 | void (*func) (void *, char *, int)) |
579 | void (*func) _ANSI_ARGS_((void *, char *, int))) |
579 | { |
580 | { |
580 | uu_MsgCallback = func; |
581 | uu_MsgCallback = func; |
581 | uu_MsgCBArg = opaque; |
582 | uu_MsgCBArg = opaque; |
582 | |
583 | |
583 | return UURET_OK; |
584 | return UURET_OK; |
584 | } |
585 | } |
585 | |
586 | |
586 | int UUEXPORT |
587 | int UUEXPORT |
587 | UUSetBusyCallback (void *opaque, |
588 | UUSetBusyCallback (void *opaque, |
588 | int (*func) (void *, uuprogress *), |
589 | int (*func) _ANSI_ARGS_((void *, uuprogress *)), |
589 | long msecs) |
590 | long msecs) |
590 | { |
591 | { |
591 | uu_BusyCallback = func; |
592 | uu_BusyCallback = func; |
592 | uu_BusyCBArg = opaque; |
593 | uu_BusyCBArg = opaque; |
593 | uu_busy_msecs = msecs; |
594 | uu_busy_msecs = msecs; |
… | |
… | |
595 | return UURET_OK; |
596 | return UURET_OK; |
596 | } |
597 | } |
597 | |
598 | |
598 | int UUEXPORT |
599 | int UUEXPORT |
599 | UUSetFileCallback (void *opaque, |
600 | UUSetFileCallback (void *opaque, |
600 | int (*func) (void *, char *, char *, int)) |
601 | int (*func) _ANSI_ARGS_((void *, char *, char *, int))) |
601 | { |
602 | { |
602 | uu_FileCallback = func; |
603 | uu_FileCallback = func; |
603 | uu_FileCBArg = opaque; |
604 | uu_FileCBArg = opaque; |
604 | |
605 | |
605 | return UURET_OK; |
606 | return UURET_OK; |
606 | } |
607 | } |
607 | |
608 | |
608 | int UUEXPORT |
609 | int UUEXPORT |
609 | UUSetFNameFilter (void *opaque, |
610 | UUSetFNameFilter (void *opaque, |
610 | char * (*func) (void *, char *)) |
611 | char * (*func) _ANSI_ARGS_((void *, char *))) |
611 | { |
612 | { |
612 | uu_FNameFilter = func; |
613 | uu_FNameFilter = func; |
613 | uu_FFCBArg = opaque; |
614 | uu_FFCBArg = opaque; |
614 | |
615 | |
615 | return UURET_OK; |
616 | return UURET_OK; |
… | |
… | |
651 | * Load a File. We call ScanPart repeatedly until at EOF and |
652 | * Load a File. We call ScanPart repeatedly until at EOF and |
652 | * add the parts to UUGlobalFileList |
653 | * add the parts to UUGlobalFileList |
653 | */ |
654 | */ |
654 | |
655 | |
655 | int UUEXPORT |
656 | int UUEXPORT |
|
|
657 | UULoadFile (char *filename, char *fileid, int delflag) |
|
|
658 | { |
|
|
659 | return UULoadFileWithPartNo(filename, fileid, delflag, -1); |
|
|
660 | } |
|
|
661 | |
|
|
662 | int UUEXPORT |
656 | UULoadFile (char *filename, char *fileid, int delflag, int *partcount) |
663 | UULoadFileWithPartNo (char *filename, char *fileid, int delflag, int partno) |
657 | { |
664 | { |
658 | int res, sr; |
665 | int res, sr, count=0; |
659 | struct stat finfo; |
666 | struct stat finfo; |
660 | fileread *loaded; |
667 | fileread *loaded; |
661 | uufile *fload; |
668 | uufile *fload; |
662 | itbd *killem; |
669 | itbd *killem; |
663 | FILE *datei; |
670 | FILE *datei; |
664 | |
|
|
665 | int _count; |
|
|
666 | if (!partcount) |
|
|
667 | partcount = &_count; |
|
|
668 | |
|
|
669 | *partcount = 0; |
|
|
670 | |
671 | |
671 | if ((datei = fopen (filename, "rb")) == NULL) { |
672 | if ((datei = fopen (filename, "rb")) == NULL) { |
672 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
673 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
673 | uustring (S_NOT_OPEN_SOURCE), |
674 | uustring (S_NOT_OPEN_SOURCE), |
674 | filename, strerror (uu_errno = errno)); |
675 | filename, strerror (uu_errno = errno)); |
… | |
… | |
690 | if (delflag && fileid==NULL) { |
691 | if (delflag && fileid==NULL) { |
691 | if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) { |
692 | if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) { |
692 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
693 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
693 | uustring (S_OUT_OF_MEMORY), sizeof (itbd)); |
694 | uustring (S_OUT_OF_MEMORY), sizeof (itbd)); |
694 | } |
695 | } |
695 | else if ((killem->fname = FP_strdup (filename)) == NULL) { |
696 | else if ((killem->fname = _FP_strdup (filename)) == NULL) { |
696 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
697 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
697 | uustring (S_OUT_OF_MEMORY), strlen(filename)+1); |
698 | uustring (S_OUT_OF_MEMORY), strlen(filename)+1); |
698 | FP_free (killem); |
699 | _FP_free (killem); |
699 | } |
700 | } |
700 | else { |
701 | else { |
701 | killem->NEXT = ftodel; |
702 | killem->NEXT = ftodel; |
702 | ftodel = killem; |
703 | ftodel = killem; |
703 | } |
704 | } |
… | |
… | |
707 | progress.partno = 0; |
708 | progress.partno = 0; |
708 | progress.numparts = 1; |
709 | progress.numparts = 1; |
709 | progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1); |
710 | progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1); |
710 | progress.percent = 0; |
711 | progress.percent = 0; |
711 | progress.foffset = 0; |
712 | progress.foffset = 0; |
712 | FP_strncpy (progress.curfile, |
713 | _FP_strncpy (progress.curfile, |
713 | (strlen(filename)>255)? |
714 | (strlen(filename)>255)? |
714 | (filename+strlen(filename)-255):filename, |
715 | (filename+strlen(filename)-255):filename, |
715 | 256); |
716 | 256); |
716 | progress.action = UUACT_SCANNING; |
717 | progress.action = UUACT_SCANNING; |
717 | |
718 | |
… | |
… | |
729 | ungetc (res, datei); |
730 | ungetc (res, datei); |
730 | |
731 | |
731 | if ((loaded = ScanPart (datei, fileid, &sr)) == NULL) { |
732 | if ((loaded = ScanPart (datei, fileid, &sr)) == NULL) { |
732 | if (sr != UURET_NODATA && sr != UURET_OK && sr != UURET_CONT) { |
733 | if (sr != UURET_NODATA && sr != UURET_OK && sr != UURET_CONT) { |
733 | UUkillfread (loaded); |
734 | UUkillfread (loaded); |
734 | if (sr != UURET_CANCEL) |
735 | if (sr != UURET_CANCEL) { |
735 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
736 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
736 | uustring (S_READ_ERROR), filename, |
737 | uustring (S_READ_ERROR), filename, |
737 | strerror (uu_errno)); |
738 | strerror (uu_errno)); |
738 | |
739 | } |
739 | UUCheckGlobalList (); |
740 | UUCheckGlobalList (); |
740 | progress.action = 0; |
741 | progress.action = 0; |
741 | fclose (datei); |
742 | fclose (datei); |
742 | return sr; |
743 | return sr; |
743 | } |
744 | } |
… | |
… | |
751 | UUCheckGlobalList (); |
752 | UUCheckGlobalList (); |
752 | progress.action = 0; |
753 | progress.action = 0; |
753 | fclose (datei); |
754 | fclose (datei); |
754 | return UURET_IOERR; |
755 | return UURET_IOERR; |
755 | } |
756 | } |
|
|
757 | |
|
|
758 | if (partno != -1) |
|
|
759 | loaded->partno = partno; |
756 | |
760 | |
757 | if ((loaded->uudet == QP_ENCODED || loaded->uudet == PT_ENCODED) && |
761 | if ((loaded->uudet == QP_ENCODED || loaded->uudet == PT_ENCODED) && |
758 | (loaded->filename == NULL || *(loaded->filename) == '\0') && |
762 | (loaded->filename == NULL || *(loaded->filename) == '\0') && |
759 | !uu_handletext && (loaded->flags&FL_PARTIAL)==0) { |
763 | !uu_handletext && (loaded->flags&FL_PARTIAL)==0) { |
760 | /* |
764 | /* |
… | |
… | |
827 | /* |
831 | /* |
828 | * if in fast mode, we don't look any further, because we're told |
832 | * if in fast mode, we don't look any further, because we're told |
829 | * that each source file holds at most one encoded part |
833 | * that each source file holds at most one encoded part |
830 | */ |
834 | */ |
831 | |
835 | |
832 | if (loaded->uudet) |
|
|
833 | (*partcount)++; |
|
|
834 | |
|
|
835 | if (uu_fast_scanning && sr != UURET_CONT) |
836 | if (uu_fast_scanning && sr != UURET_CONT) |
836 | break; |
837 | break; |
|
|
838 | |
|
|
839 | if (loaded->uudet) |
|
|
840 | count++; |
|
|
841 | } |
|
|
842 | if (ferror (datei)) { |
|
|
843 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
|
|
844 | uustring (S_READ_ERROR), filename, |
|
|
845 | strerror (uu_errno = errno)); |
|
|
846 | UUCheckGlobalList (); |
|
|
847 | progress.action = 0; |
|
|
848 | fclose (datei); |
|
|
849 | return UURET_IOERR; |
837 | } |
850 | } |
838 | fclose (datei); |
851 | fclose (datei); |
839 | |
852 | |
840 | if (!uu_fast_scanning && *partcount == 0) |
853 | if (!uu_fast_scanning && count==0) { |
841 | UUMessage (uulib_id, __LINE__, UUMSG_NOTE, |
854 | UUMessage (uulib_id, __LINE__, UUMSG_NOTE, |
842 | uustring (S_NO_DATA_FOUND), filename); |
855 | uustring (S_NO_DATA_FOUND), filename); |
|
|
856 | } |
843 | |
857 | |
844 | progress.action = 0; |
858 | progress.action = 0; |
845 | UUCheckGlobalList (); |
859 | UUCheckGlobalList (); |
846 | |
860 | |
847 | return UURET_OK; |
861 | return UURET_OK; |
… | |
… | |
939 | thefile->binfile, strerror (uu_errno = errno)); |
953 | thefile->binfile, strerror (uu_errno = errno)); |
940 | fclose (source); |
954 | fclose (source); |
941 | return UURET_IOERR; |
955 | return UURET_IOERR; |
942 | } |
956 | } |
943 | |
957 | |
944 | /* try rename() shortcut first */ |
|
|
945 | if (!rename (thefile->binfile, uugen_fnbuffer)) |
|
|
946 | { |
|
|
947 | mode_t mask = 0000; /* there is a slight window here anyway */ |
|
|
948 | #if HAVE_UMASK |
|
|
949 | mask = umask (0022); umask (mask); |
|
|
950 | #endif |
|
|
951 | fclose (source); |
|
|
952 | #if HAVE_CHMOD |
|
|
953 | chmod (uugen_fnbuffer, thefile->mode & ~mask); |
|
|
954 | #endif |
|
|
955 | goto skip_copy; |
|
|
956 | } |
|
|
957 | |
|
|
958 | progress.action = 0; |
958 | progress.action = 0; |
959 | FP_strncpy (progress.curfile, |
959 | _FP_strncpy (progress.curfile, |
960 | (strlen(uugen_fnbuffer)>255)? |
960 | (strlen(uugen_fnbuffer)>255)? |
961 | (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer, |
961 | (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer, |
962 | 256); |
962 | 256); |
963 | progress.partno = 0; |
963 | progress.partno = 0; |
964 | progress.numparts = 1; |
964 | progress.numparts = 1; |
… | |
… | |
1021 | unlink (uugen_fnbuffer); |
1021 | unlink (uugen_fnbuffer); |
1022 | return UURET_IOERR; |
1022 | return UURET_IOERR; |
1023 | } |
1023 | } |
1024 | } |
1024 | } |
1025 | |
1025 | |
1026 | fclose (target); |
|
|
1027 | fclose (source); |
1026 | fclose (source); |
|
|
1027 | if (fclose (target)) { |
|
|
1028 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
|
|
1029 | uustring (S_WR_ERR_TARGET), |
|
|
1030 | uugen_fnbuffer, strerror (uu_errno = errno)); |
|
|
1031 | unlink (uugen_fnbuffer); |
|
|
1032 | return UURET_IOERR; |
|
|
1033 | } |
1028 | |
1034 | |
1029 | /* |
1035 | /* |
1030 | * after a successful decoding run, we delete the temporary file |
1036 | * after a successful decoding run, we delete the temporary file |
1031 | */ |
1037 | */ |
1032 | |
1038 | |
… | |
… | |
1034 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1040 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1035 | uustring (S_TMP_NOT_REMOVED), |
1041 | uustring (S_TMP_NOT_REMOVED), |
1036 | thefile->binfile, |
1042 | thefile->binfile, |
1037 | strerror (uu_errno = errno)); |
1043 | strerror (uu_errno = errno)); |
1038 | } |
1044 | } |
1039 | |
|
|
1040 | skip_copy: |
|
|
1041 | FP_free (thefile->binfile); |
1045 | _FP_free (thefile->binfile); |
1042 | thefile->binfile = NULL; |
1046 | thefile->binfile = NULL; |
1043 | thefile->state &= ~UUFILE_TMPFILE; |
1047 | thefile->state &= ~UUFILE_TMPFILE; |
1044 | thefile->state |= UUFILE_DECODED; |
1048 | thefile->state |= UUFILE_DECODED; |
1045 | progress.action = 0; |
1049 | progress.action = 0; |
1046 | |
1050 | |
… | |
… | |
1052 | * If the function returns non-zero, we break and don't send any more |
1056 | * If the function returns non-zero, we break and don't send any more |
1053 | */ |
1057 | */ |
1054 | |
1058 | |
1055 | int UUEXPORT |
1059 | int UUEXPORT |
1056 | UUInfoFile (uulist *thefile, void *opaque, |
1060 | UUInfoFile (uulist *thefile, void *opaque, |
1057 | int (*func) (void *, char *)) |
1061 | int (*func) _ANSI_ARGS_((void *, char *))) |
1058 | { |
1062 | { |
1059 | int errflag=0, res, bhflag=0, dd; |
1063 | int errflag=0, res, bhflag=0, dd; |
1060 | long maxpos; |
1064 | long maxpos; |
1061 | FILE *inpfile; |
1065 | FILE *inpfile; |
1062 | |
1066 | |
… | |
… | |
1085 | uustring (S_NOT_OPEN_FILE), |
1089 | uustring (S_NOT_OPEN_FILE), |
1086 | thefile->thisfile->data->sfname, |
1090 | thefile->thisfile->data->sfname, |
1087 | strerror (uu_errno=errno)); |
1091 | strerror (uu_errno=errno)); |
1088 | return UURET_IOERR; |
1092 | return UURET_IOERR; |
1089 | } |
1093 | } |
1090 | FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024); |
1094 | _FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024); |
1091 | } |
1095 | } |
1092 | |
1096 | |
1093 | /* |
1097 | /* |
1094 | * seek to beginning of info |
1098 | * seek to beginning of info |
1095 | */ |
1099 | */ |
… | |
… | |
1097 | fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET); |
1101 | fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET); |
1098 | maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length; |
1102 | maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length; |
1099 | |
1103 | |
1100 | while (!feof (inpfile) && |
1104 | while (!feof (inpfile) && |
1101 | (uu_fast_scanning || ftell(inpfile) < maxpos)) { |
1105 | (uu_fast_scanning || ftell(inpfile) < maxpos)) { |
1102 | if (FP_fgets (uugen_inbuffer, 511, inpfile) == NULL) |
1106 | if (_FP_fgets (uugen_inbuffer, 511, inpfile) == NULL) |
1103 | break; |
1107 | break; |
1104 | uugen_inbuffer[511] = '\0'; |
1108 | uugen_inbuffer[511] = '\0'; |
1105 | |
1109 | |
1106 | if (ferror (inpfile)) |
1110 | if (ferror (inpfile)) |
1107 | break; |
1111 | break; |
… | |
… | |
1113 | else if (thefile->uudet == BH_ENCODED && bhflag) |
1117 | else if (thefile->uudet == BH_ENCODED && bhflag) |
1114 | break; |
1118 | break; |
1115 | else if ((thefile->uudet == UU_ENCODED || thefile->uudet == XX_ENCODED) && |
1119 | else if ((thefile->uudet == UU_ENCODED || thefile->uudet == XX_ENCODED) && |
1116 | strncmp (uugen_inbuffer, "begin ", 6) == 0) |
1120 | strncmp (uugen_inbuffer, "begin ", 6) == 0) |
1117 | break; |
1121 | break; |
|
|
1122 | else if (thefile->uudet == YENC_ENCODED && |
|
|
1123 | strncmp (uugen_inbuffer, "=ybegin ", 8) == 0) |
|
|
1124 | break; |
1118 | |
1125 | |
1119 | if ((*func) (opaque, uugen_inbuffer)) |
1126 | if ((*func) (opaque, uugen_inbuffer)) |
1120 | break; |
1127 | break; |
1121 | } |
1128 | } |
1122 | |
1129 | |
… | |
… | |
1148 | if (thefile == NULL) |
1155 | if (thefile == NULL) |
1149 | return UURET_ILLVAL; |
1156 | return UURET_ILLVAL; |
1150 | |
1157 | |
1151 | oldname = thefile->filename; |
1158 | oldname = thefile->filename; |
1152 | |
1159 | |
1153 | if ((thefile->filename = FP_strdup (newname)) == NULL) { |
1160 | if ((thefile->filename = _FP_strdup (newname)) == NULL) { |
1154 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1161 | UUMessage (uulib_id, __LINE__, UUMSG_ERROR, |
1155 | uustring (S_NOT_RENAME), |
1162 | uustring (S_NOT_RENAME), |
1156 | oldname, newname); |
1163 | oldname, newname); |
1157 | thefile->filename = oldname; |
1164 | thefile->filename = oldname; |
1158 | return UURET_NOMEM; |
1165 | return UURET_NOMEM; |
1159 | } |
1166 | } |
1160 | FP_free (oldname); |
1167 | _FP_free (oldname); |
1161 | return UURET_OK; |
1168 | return UURET_OK; |
1162 | } |
1169 | } |
1163 | |
1170 | |
1164 | int UUEXPORT |
1171 | int UUEXPORT |
1165 | UURemoveTemp (uulist *thefile) |
1172 | UURemoveTemp (uulist *thefile) |
… | |
… | |
1172 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1179 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1173 | uustring (S_TMP_NOT_REMOVED), |
1180 | uustring (S_TMP_NOT_REMOVED), |
1174 | thefile->binfile, |
1181 | thefile->binfile, |
1175 | strerror (uu_errno = errno)); |
1182 | strerror (uu_errno = errno)); |
1176 | } |
1183 | } |
1177 | FP_free (thefile->binfile); |
1184 | _FP_free (thefile->binfile); |
1178 | thefile->binfile = NULL; |
1185 | thefile->binfile = NULL; |
1179 | thefile->state &= ~UUFILE_TMPFILE; |
1186 | thefile->state &= ~UUFILE_TMPFILE; |
1180 | } |
1187 | } |
1181 | return UURET_OK; |
1188 | return UURET_OK; |
1182 | } |
1189 | } |
… | |
… | |
1197 | if (unlink (iter->fname)) { |
1204 | if (unlink (iter->fname)) { |
1198 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1205 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1199 | uustring (S_TMP_NOT_REMOVED), |
1206 | uustring (S_TMP_NOT_REMOVED), |
1200 | iter->fname, strerror (uu_errno = errno)); |
1207 | iter->fname, strerror (uu_errno = errno)); |
1201 | } |
1208 | } |
1202 | FP_free (iter->fname); |
1209 | _FP_free (iter->fname); |
1203 | ptr = iter; |
1210 | ptr = iter; |
1204 | iter = iter->NEXT; |
1211 | iter = iter->NEXT; |
1205 | FP_free (ptr); |
1212 | _FP_free (ptr); |
1206 | } |
1213 | } |
1207 | |
1214 | |
1208 | ftodel = NULL; |
1215 | ftodel = NULL; |
1209 | |
1216 | |
1210 | /* |
1217 | /* |
… | |
… | |
1232 | } |
1239 | } |
1233 | |
1240 | |
1234 | UUkilllist (UUGlobalFileList); |
1241 | UUkilllist (UUGlobalFileList); |
1235 | UUGlobalFileList = NULL; |
1242 | UUGlobalFileList = NULL; |
1236 | |
1243 | |
1237 | FP_free (uusavepath); |
1244 | _FP_free (uusavepath); |
1238 | FP_free (uuencodeext); |
1245 | _FP_free (uuencodeext); |
1239 | FP_free (sstate.source); |
1246 | _FP_free (sstate.source); |
1240 | |
1247 | |
1241 | uusavepath = NULL; |
1248 | uusavepath = NULL; |
1242 | uuencodeext = NULL; |
1249 | uuencodeext = NULL; |
1243 | |
1250 | |
1244 | UUkillheaders (&localenv); |
1251 | UUkillheaders (&localenv); |
… | |
… | |
1247 | memset (&sstate, 0, sizeof (scanstate)); |
1254 | memset (&sstate, 0, sizeof (scanstate)); |
1248 | |
1255 | |
1249 | while (mssdepth) { |
1256 | while (mssdepth) { |
1250 | mssdepth--; |
1257 | mssdepth--; |
1251 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1258 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1252 | FP_free (multistack[mssdepth].source); |
1259 | _FP_free (multistack[mssdepth].source); |
1253 | } |
1260 | } |
1254 | |
1261 | |
1255 | /* |
1262 | /* |
1256 | * clean up the malloc'ed stuff |
1263 | * clean up the malloc'ed stuff |
1257 | */ |
1264 | */ |
1258 | |
1265 | |
1259 | for (aiter=toallocate; aiter->ptr; aiter++) { |
1266 | for (aiter=toallocate; aiter->ptr; aiter++) { |
1260 | FP_free (*(aiter->ptr)); |
1267 | _FP_free (*(aiter->ptr)); |
1261 | *(aiter->ptr) = NULL; |
1268 | *(aiter->ptr) = NULL; |
1262 | } |
1269 | } |
1263 | |
1270 | |
1264 | return UURET_OK; |
1271 | return UURET_OK; |
1265 | } |
1272 | } |