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

Comparing Convert-UUlib/uulib/uulib.c (file contents):
Revision 1.4.2.5 by root, Sun Apr 18 19:55:46 2004 UTC vs.
Revision 1.30 by root, Sat Sep 24 10:55:43 2022 UTC

31#endif 31#endif
32 32
33#include <sys/types.h> 33#include <sys/types.h>
34#include <sys/stat.h> 34#include <sys/stat.h>
35#include <stdio.h> 35#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38#include <string.h>
39#include <time.h>
40#include <errno.h>
36 41
37#ifdef HAVE_FCNTL_H 42#ifdef HAVE_FCNTL_H
38#include <fcntl.h> 43#include <fcntl.h>
39#endif 44#endif
40
41#ifdef STDC_HEADERS
42#include <stdlib.h>
43#include <stdarg.h>
44#include <string.h>
45#else
46#ifdef HAVE_STDARG_H
47#include <stdarg.h>
48#else
49#ifdef HAVE_VARARGS_H
50#include <varargs.h>
51#endif
52#endif
53#endif
54
55#ifdef HAVE_UNISTD_H 45#ifdef HAVE_UNISTD_H
56#include <unistd.h> 46#include <unistd.h>
57#endif 47#endif
58 48
59#ifdef TIME_WITH_SYS_TIME 49#ifdef HAVE_SYS_TIME_H
60# include <sys/time.h> 50# include <sys/time.h>
61# include <time.h>
62#else
63# ifdef HAVE_SYS_TIME_H
64# include <sys/time.h>
65# else
66# include <time.h>
67# endif
68#endif
69
70#ifdef HAVE_ERRNO_H
71#include <errno.h>
72#endif 51#endif
73 52
74/* to get open() in Windows */ 53/* to get open() in Windows */
75#ifdef HAVE_IO_H 54#ifdef HAVE_IO_H
76#include <io.h> 55#include <io.h>
79#include <uudeview.h> 58#include <uudeview.h>
80#include <uuint.h> 59#include <uuint.h>
81#include <fptools.h> 60#include <fptools.h>
82#include <uustring.h> 61#include <uustring.h>
83 62
84char * uulib_id = "$Id: uulib.c,v 1.4.2.5 2004/04/18 19:55:46 root Exp $"; 63#include "safealloc.c"
85 64
86#ifdef SYSTEM_WINDLL 65#ifdef SYSTEM_WINDLL
87BOOL _export WINAPI 66BOOL _export WINAPI
88DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, 67DllEntryPoint (HINSTANCE hInstance, DWORD seginfo,
89 LPVOID lpCmdLine) 68 LPVOID lpCmdLine)
90{ 69{
91 /* Don't do anything, so just return true */ 70 /* Don't do anything, so just return true */
92 return TRUE; 71 return TRUE;
112 91
113/* 92/*
114 * Callback functions and their opaque arguments 93 * Callback functions and their opaque arguments
115 */ 94 */
116 95
117void (*uu_MsgCallback) _ANSI_ARGS_((void *, char *, int)) = NULL; 96void (*uu_MsgCallback) (void *, char *, int) = NULL;
118int (*uu_BusyCallback) _ANSI_ARGS_((void *, uuprogress *)) = NULL; 97int (*uu_BusyCallback) (void *, uuprogress *) = NULL;
119int (*uu_FileCallback) _ANSI_ARGS_((void *, char *, char *, int)) = NULL; 98int (*uu_FileCallback) (void *, char *, char *, int) = NULL;
120char * (*uu_FNameFilter) _ANSI_ARGS_((void *, char *)) = NULL; 99char * (*uu_FNameFilter) (void *, char *) = NULL;
121 100char * (*uu_FileNameCallback)(void *, char *, char *);
101;
122void *uu_MsgCBArg = NULL; 102void *uu_MsgCBArg = NULL;
123void *uu_BusyCBArg = NULL; 103void *uu_BusyCBArg = NULL;
124void *uu_FileCBArg = NULL; 104void *uu_FileCBArg = NULL;
125void *uu_FFCBArg = NULL; 105void *uu_FFCBArg = NULL;
106void *uu_FNCBArg;
107
108int uu_autocheck = 1; /* call UUCheckGlobaList after every part */
109
110/* I/O buffer sizes */
111int uu_rbuf = 0;
112int uu_wbuf = 0;
126 113
127/* 114/*
128 * Global variables 115 * Global variables
129 */ 116 */
130 117
141int uu_handletext = 0; /* do we want text/plain messages */ 128int uu_handletext = 0; /* do we want text/plain messages */
142int uu_usepreamble = 0; /* do we want Mime preambles/epilogues */ 129int uu_usepreamble = 0; /* do we want Mime preambles/epilogues */
143int uu_tinyb64 = 0; /* detect short B64 outside of MIME */ 130int uu_tinyb64 = 0; /* detect short B64 outside of MIME */
144int uu_remove_input = 0; /* remove input files after decoding */ 131int uu_remove_input = 0; /* remove input files after decoding */
145int uu_more_mime = 0; /* strictly adhere to MIME headers */ 132int uu_more_mime = 0; /* strictly adhere to MIME headers */
133int uu_dotdot = 0; /* dot-unescaping has not yet been done */
146 134
147headercount hlcount = { 135headercount hlcount = {
148 3, /* restarting after a MIME body */ 136 3, /* restarting after a MIME body */
149 2, /* after useful data in freestyle mode */ 137 2, /* after useful data in freestyle mode */
150 1 /* after useful data and an empty line */ 138 1 /* after useful data and an empty line */
224 char **ptr; 212 char **ptr;
225 size_t size; 213 size_t size;
226} allomap; 214} allomap;
227 215
228static allomap toallocate[] = { 216static allomap toallocate[] = {
229 { &uugen_fnbuffer, 1024 }, /* generic filename buffer */ 217 { &uugen_fnbuffer, 4096 }, /* generic filename buffer */
230 { &uugen_inbuffer, 1024 }, /* generic input data buffer */ 218 { &uugen_inbuffer, 1024 }, /* generic input data buffer */
231 { &uucheck_lastname, 256 }, /* from uucheck.c */ 219 { &uucheck_lastname, 256 }, /* from uucheck.c */
232 { &uucheck_tempname, 256 }, 220 { &uucheck_tempname, 256 },
233 { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */ 221 { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */
234 { &uuestr_otemp, 1024 }, 222 { &uuestr_otemp, 1024 },
235 { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */ 223 { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */
236 { &uuncdl_fulline, 300 }, /* from uunconc.c:UUDecodeLine() */ 224 { &uuncdl_fulline, 1201 }, /* from uunconc.c:UUDecodeLine() */
237 { &uuncdp_oline, 1200 }, /* from uunconc.c:UUDecodePart() */ 225 { &uuncdp_oline, 3600 }, /* from uunconc.c:UUDecodePart() */
238 { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */ 226 { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */
239 { &uunconc_UUxlen, 64 * sizeof (int) }, 227 { &uunconc_UUxlen, 64 * sizeof (int) },
240 { &uunconc_B64xlat, 256 * sizeof (int) }, 228 { &uunconc_B64xlat, 256 * sizeof (int) },
241 { &uunconc_XXxlat, 256 * sizeof (int) }, 229 { &uunconc_XXxlat, 256 * sizeof (int) },
242 { &uunconc_BHxlat, 256 * sizeof (int) }, 230 { &uunconc_BHxlat, 256 * sizeof (int) },
243 { &uunconc_save, 3*300 }, /* from uunconc.c:decoding buffer */ 231 { &uunconc_save, 3*1200 }, /* from uunconc.c:decoding buffer */
244 { &uuscan_shlline, 1024 }, /* from uuscan.c:ScanHeaderLine() */ 232 { &uuscan_shlline, 1024 }, /* from uuscan.c:ScanHeaderLine() */
245 { &uuscan_shlline2, 1024 }, /* from uuscan.c:ScanHeaderLine() */ 233 { &uuscan_shlline2, 1024 }, /* from uuscan.c:ScanHeaderLine() */
246 { &uuscan_pvvalue, 300 }, /* from uuscan.c:ParseValue() */ 234 { &uuscan_pvvalue, 300 }, /* from uuscan.c:ParseValue() */
247 { &uuscan_phtext, 300 }, /* from uuscan.c:ParseHeader() */ 235 { &uuscan_phtext, 300 }, /* from uuscan.c:ParseHeader() */
248 { &uuscan_sdline, 300 }, /* from uuscan.c:ScanData() */ 236 { &uuscan_sdline, 1025 }, /* from uuscan.c:ScanData(), +1 for UURepairData */
249 { &uuscan_sdbhds1, 300 }, 237 { &uuscan_sdbhds1, 1300 }, /* 1024 for line in UUScan + 256 potential overhead UUDecodeLine */
250 { &uuscan_sdbhds2, 300 }, 238 { &uuscan_sdbhds2, 1300 }, /* 1024 for line in UUScan + 256 potential overhead UUDecodeLine */
251 { &uuscan_spline, 300 }, /* from uuscan.c:ScanPart() */ 239 { &uuscan_spline, 1024 }, /* from uuscan.c:UUScanPart() */
252 { &uuutil_bhwtmp, 300 }, /* from uuutil.c:UUbhwrite() */ 240 { &uuutil_bhwtmp, 300 }, /* from uuutil.c:UUbhwrite() */
253 { NULL, 0 } 241 { NULL, 0 }
254}; 242};
255 243
256/* 244/*
257 * Handle the printing of messages. Works like printf. 245 * Handle the printing of messages. Works like printf.
258 */ 246 */
259 247
260#if defined(STDC_HEADERS) || defined(HAVE_STDARG_H)
261int 248int
262UUMessage (char *file, int line, int level, char *format, ...) 249UUMessage_ (const char *file, int line_level, const char *format, ...)
263#else
264int
265UUMessage (va_alist)
266 va_dcl
267#endif
268{ 250{
269 char *msgptr; 251 int msgofs;
270#if defined(STDC_HEADERS) || defined(HAVE_STDARG_H) 252 int line = line_level >> 4;
253 int level = line_level & 0x000f;
254
271 va_list ap; 255 va_list ap;
272
273 va_start (ap, format); 256 va_start (ap, format);
274#else
275 char *file, *format;
276 int line, level;
277 va_list ap;
278
279 va_start (ap);
280 file = va_arg (ap, char *);
281 line = va_arg (ap, int);
282 level = va_arg (ap, int);
283 format = va_arg (ap, char *);
284#endif
285 257
286 if (uu_debug) { 258 if (uu_debug) {
287 sprintf (uulib_msgstring, "%s(%d): %s", file, line, msgnames[level]); 259 snprintf (uulib_msgstring, 1024, "%s(%d): %s", file, line, msgnames[level]);
288 msgptr = uulib_msgstring + strlen (uulib_msgstring); 260 msgofs = strlen (uulib_msgstring);
289 } 261 }
290 else { 262 else {
291 sprintf (uulib_msgstring, "%s", msgnames[level]); 263 snprintf (uulib_msgstring, 1024, "%s", msgnames[level]);
292 msgptr = uulib_msgstring + strlen (uulib_msgstring); 264 msgofs = strlen (uulib_msgstring);
293 } 265 }
294 266
295 if (uu_MsgCallback && (level>UUMSG_NOTE || uu_verbose)) { 267 if (uu_MsgCallback && (level>UUMSG_NOTE || uu_verbose)) {
296 vsprintf (msgptr, format, ap); 268 vsnprintf (uulib_msgstring + msgofs, 1024 - msgofs, format, ap);
297 269
298 (*uu_MsgCallback) (uu_MsgCBArg, uulib_msgstring, level); 270 (*uu_MsgCallback) (uu_MsgCBArg, uulib_msgstring, level);
299 } 271 }
300 272
301 va_end (ap); 273 va_end (ap);
385 357
386 for (aiter=toallocate; aiter->ptr; aiter++) 358 for (aiter=toallocate; aiter->ptr; aiter++)
387 *(aiter->ptr) = NULL; 359 *(aiter->ptr) = NULL;
388 360
389 for (aiter=toallocate; aiter->ptr; aiter++) { 361 for (aiter=toallocate; aiter->ptr; aiter++) {
390 if ((*(aiter->ptr) = (char *) malloc (aiter->size)) == NULL) { 362 if ((*(aiter->ptr) = (char *) safe_alloc (aiter->size)) == NULL) {
391 /* 363 /*
392 * oops. we may not print a message here, because we need these 364 * oops. we may not print a message here, because we need these
393 * areas (uulib_msgstring) in UUMessage() 365 * areas (uulib_msgstring) in UUMessage()
394 */ 366 */
395 for (aiter=toallocate; aiter->ptr; aiter++) { 367 for (aiter=toallocate; aiter->ptr; aiter++) {
396 _FP_free (*(aiter->ptr)); 368 safe_free (*(aiter->ptr), aiter->size);
397 } 369 }
398 return UURET_NOMEM; 370 return UURET_NOMEM;
399 } 371 }
400 } 372 }
401 373
416UUGetOption (int option, int *ivalue, char *cvalue, int clength) 388UUGetOption (int option, int *ivalue, char *cvalue, int clength)
417{ 389{
418 int result; 390 int result;
419 391
420 switch (option) { 392 switch (option) {
393 case UUOPT_RBUF:
394 *ivalue = uu_rbuf;
395 result = 0;
396 break;
397 case UUOPT_WBUF:
398 *ivalue = uu_wbuf;
399 result = 0;
400 break;
421 case UUOPT_VERSION: 401 case UUOPT_VERSION:
422 _FP_strncpy (cvalue, uulibversion, clength); 402 FP_strncpy (cvalue, uulibversion, clength);
423 result = 0; 403 result = 0;
424 break; 404 break;
425 case UUOPT_FAST: 405 case UUOPT_FAST:
426 if (ivalue) *ivalue = uu_fast_scanning; 406 if (ivalue) *ivalue = uu_fast_scanning;
427 result = uu_fast_scanning; 407 result = uu_fast_scanning;
457 case UUOPT_OVERWRITE: 437 case UUOPT_OVERWRITE:
458 if (ivalue) *ivalue = uu_overwrite; 438 if (ivalue) *ivalue = uu_overwrite;
459 result = uu_overwrite; 439 result = uu_overwrite;
460 break; 440 break;
461 case UUOPT_SAVEPATH: 441 case UUOPT_SAVEPATH:
462 _FP_strncpy (cvalue, uusavepath, clength); 442 FP_strncpy (cvalue, uusavepath, clength);
463 result = 0; 443 result = 0;
464 break; 444 break;
465 case UUOPT_PROGRESS: 445 case UUOPT_PROGRESS:
466 if (clength==sizeof(uuprogress)) { 446 if (clength==sizeof(uuprogress)) {
467 memcpy (cvalue, &progress, sizeof (uuprogress)); 447 memcpy (cvalue, &progress, sizeof (uuprogress));
485 case UUOPT_TINYB64: 465 case UUOPT_TINYB64:
486 if (ivalue) *ivalue = uu_tinyb64; 466 if (ivalue) *ivalue = uu_tinyb64;
487 result = uu_tinyb64; 467 result = uu_tinyb64;
488 break; 468 break;
489 case UUOPT_ENCEXT: 469 case UUOPT_ENCEXT:
490 _FP_strncpy (cvalue, uuencodeext, clength); 470 FP_strncpy (cvalue, uuencodeext, clength);
491 result = 0; 471 result = 0;
492 break; 472 break;
493 case UUOPT_REMOVE: 473 case UUOPT_REMOVE:
494 if (ivalue) *ivalue = uu_remove_input; 474 if (ivalue) *ivalue = uu_remove_input;
495 result = uu_remove_input; 475 result = uu_remove_input;
496 break; 476 break;
497 case UUOPT_MOREMIME: 477 case UUOPT_MOREMIME:
498 if (ivalue) *ivalue = uu_more_mime; 478 if (ivalue) *ivalue = uu_more_mime;
499 result = uu_more_mime; 479 result = uu_more_mime;
500 break; 480 break;
481 case UUOPT_DOTDOT:
482 if (ivalue) *ivalue = uu_dotdot;
483 result = uu_dotdot;
484 break;
485 case UUOPT_AUTOCHECK:
486 if (ivalue) *ivalue = uu_autocheck;
487 result = uu_autocheck;
488 break;
501 default: 489 default:
502 return -1; 490 return -1;
503 } 491 }
504 return result; 492 return result;
505} 493}
506 494
507int UUEXPORT 495int UUEXPORT
508UUSetOption (int option, int ivalue, char *cvalue) 496UUSetOption (int option, int ivalue, char *cvalue)
509{ 497{
510 switch (option) { 498 switch (option) {
499 case UUOPT_RBUF:
500 uu_rbuf = ivalue;
501 break;
502 case UUOPT_WBUF:
503 uu_wbuf = ivalue;
504 break;
511 case UUOPT_FAST: 505 case UUOPT_FAST:
512 uu_fast_scanning = ivalue; 506 uu_fast_scanning = ivalue;
513 break; 507 break;
514 case UUOPT_DUMBNESS: 508 case UUOPT_DUMBNESS:
515 uu_dumbness = ivalue; 509 uu_dumbness = ivalue;
531 break; 525 break;
532 case UUOPT_OVERWRITE: 526 case UUOPT_OVERWRITE:
533 uu_overwrite = ivalue; 527 uu_overwrite = ivalue;
534 break; 528 break;
535 case UUOPT_SAVEPATH: 529 case UUOPT_SAVEPATH:
536 _FP_free (uusavepath); 530 FP_free (uusavepath);
537 uusavepath = _FP_strdup (cvalue); 531 uusavepath = FP_strdup (cvalue);
538 break; 532 break;
539 case UUOPT_IGNMODE: 533 case UUOPT_IGNMODE:
540 uu_ignmode = ivalue; 534 uu_ignmode = ivalue;
541 break; 535 break;
542 case UUOPT_USETEXT: 536 case UUOPT_USETEXT:
547 break; 541 break;
548 case UUOPT_TINYB64: 542 case UUOPT_TINYB64:
549 uu_tinyb64 = ivalue; 543 uu_tinyb64 = ivalue;
550 break; 544 break;
551 case UUOPT_ENCEXT: 545 case UUOPT_ENCEXT:
552 _FP_free (uuencodeext); 546 FP_free (uuencodeext);
553 uuencodeext = _FP_strdup (cvalue); 547 uuencodeext = FP_strdup (cvalue);
554 break; 548 break;
555 case UUOPT_REMOVE: 549 case UUOPT_REMOVE:
556 uu_remove_input = ivalue; 550 uu_remove_input = ivalue;
557 break; 551 break;
558 case UUOPT_MOREMIME: 552 case UUOPT_MOREMIME:
559 uu_more_mime = ivalue; 553 uu_more_mime = ivalue;
560 break; 554 break;
555 case UUOPT_DOTDOT:
556 uu_dotdot = ivalue;
557 break;
558 case UUOPT_AUTOCHECK:
559 uu_autocheck = ivalue;
560 break;
561 default: 561 default:
562 return UURET_ILLVAL; 562 return UURET_ILLVAL;
563 } 563 }
564 return UURET_OK; 564 return UURET_OK;
565} 565}
573/* 573/*
574 * Set the various Callback functions 574 * Set the various Callback functions
575 */ 575 */
576 576
577int UUEXPORT 577int UUEXPORT
578UUSetMsgCallback (void *opaque, 578UUSetMsgCallback (void *opaque,
579 void (*func) _ANSI_ARGS_((void *, char *, int))) 579 void (*func) (void *, char *, int))
580{ 580{
581 uu_MsgCallback = func; 581 uu_MsgCallback = func;
582 uu_MsgCBArg = opaque; 582 uu_MsgCBArg = opaque;
583 583
584 return UURET_OK; 584 return UURET_OK;
585} 585}
586 586
587int UUEXPORT 587int UUEXPORT
588UUSetBusyCallback (void *opaque, 588UUSetBusyCallback (void *opaque,
589 int (*func) _ANSI_ARGS_((void *, uuprogress *)), 589 int (*func) (void *, uuprogress *),
590 long msecs) 590 long msecs)
591{ 591{
592 uu_BusyCallback = func; 592 uu_BusyCallback = func;
593 uu_BusyCBArg = opaque; 593 uu_BusyCBArg = opaque;
594 uu_busy_msecs = msecs; 594 uu_busy_msecs = msecs;
596 return UURET_OK; 596 return UURET_OK;
597} 597}
598 598
599int UUEXPORT 599int UUEXPORT
600UUSetFileCallback (void *opaque, 600UUSetFileCallback (void *opaque,
601 int (*func) _ANSI_ARGS_((void *, char *, char *, int))) 601 int (*func) (void *, char *, char *, int))
602{ 602{
603 uu_FileCallback = func; 603 uu_FileCallback = func;
604 uu_FileCBArg = opaque; 604 uu_FileCBArg = opaque;
605 605
606 return UURET_OK; 606 return UURET_OK;
607} 607}
608 608
609int UUEXPORT 609int UUEXPORT
610UUSetFNameFilter (void *opaque, 610UUSetFNameFilter (void *opaque,
611 char * (*func) _ANSI_ARGS_((void *, char *))) 611 char * (*func) (void *, char *))
612{ 612{
613 uu_FNameFilter = func; 613 uu_FNameFilter = func;
614 uu_FFCBArg = opaque; 614 uu_FFCBArg = opaque;
615
616 return UURET_OK;
617}
618
619int UUEXPORT
620UUSetFileNameCallback (void *opaque,
621 char * (*func) (void *, char *, char *))
622{
623 uu_FileNameCallback = func;
624 uu_FNCBArg = opaque;
615 625
616 return UURET_OK; 626 return UURET_OK;
617} 627}
618 628
619/* 629/*
647 657
648 return fname; 658 return fname;
649} 659}
650 660
651/* 661/*
652 * Load a File. We call ScanPart repeatedly until at EOF and 662 * Load a File. We call UUScanPart repeatedly until at EOF and
653 * add the parts to UUGlobalFileList 663 * add the parts to UUGlobalFileList
654 */ 664 */
655 665
656int UUEXPORT 666int UUEXPORT
657UULoadFile (char *filename, char *fileid, int delflag) 667UULoadFile (char *filename, char *fileid, int delflag, int *partcount)
658{ 668{
659 return UULoadFileWithPartNo(filename, fileid, delflag, -1); 669 return UULoadFileWithPartNo(filename, fileid, delflag, -1, partcount);
660} 670}
661 671
662int UUEXPORT 672int UUEXPORT
663UULoadFileWithPartNo (char *filename, char *fileid, int delflag, int partno) 673UULoadFileWithPartNo (char *filename, char *fileid, int delflag, int partno, int *partcount)
664{ 674{
665 int res, sr, count=0; 675 int res, sr;
666 struct stat finfo; 676 struct stat finfo;
667 fileread *loaded; 677 fileread *loaded;
668 uufile *fload; 678 uufile *fload;
669 itbd *killem; 679 itbd *killem;
670 FILE *datei; 680 FILE *datei;
681 void *datei_buf;
682
683 int _count;
684 if (!partcount)
685 partcount = &_count;
686
687 *partcount = 0;
671 688
672 if ((datei = fopen (filename, "rb")) == NULL) { 689 if ((datei = fopen (filename, "rb")) == NULL) {
673 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 690 UUMessage (UUMSG_ERROR,
674 uustring (S_NOT_OPEN_SOURCE), 691 uustring (S_NOT_OPEN_SOURCE),
675 filename, strerror (uu_errno = errno)); 692 filename, strerror (uu_errno = errno));
676 return UURET_IOERR; 693 return UURET_IOERR;
677 } 694 }
695 UUSETBUF (datei, datei_buf, uu_rbuf);
696 FP_flockfile (datei);
678 697
679 if (fstat (fileno(datei), &finfo) == -1) { 698 if (fstat (fileno(datei), &finfo) == -1) {
680 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 699 UUMessage (UUMSG_ERROR,
681 uustring (S_NOT_STAT_FILE), 700 uustring (S_NOT_STAT_FILE),
682 filename, strerror (uu_errno = errno)); 701 filename, strerror (uu_errno = errno));
683 fclose (datei); 702 fclose (datei);
703 UUCLRBUF (uu_rbuf, datei_buf);
684 return UURET_IOERR; 704 return UURET_IOERR;
685 } 705 }
686 706
687 /* 707 /*
688 * schedule for destruction 708 * schedule for destruction
689 */ 709 */
690 710
691 if (delflag && fileid==NULL) { 711 if (delflag && fileid==NULL) {
692 if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) { 712 if ((killem = (itbd *) malloc (sizeof (itbd))) == NULL) {
693 UUMessage (uulib_id, __LINE__, UUMSG_WARNING, 713 UUMessage (UUMSG_WARNING, uustring (S_OUT_OF_MEMORY), sizeof (itbd));
694 uustring (S_OUT_OF_MEMORY), sizeof (itbd));
695 } 714 }
696 else if ((killem->fname = _FP_strdup (filename)) == NULL) { 715 else if ((killem->fname = FP_strdup (filename)) == NULL) {
697 UUMessage (uulib_id, __LINE__, UUMSG_WARNING, 716 UUMessage (UUMSG_WARNING, uustring (S_OUT_OF_MEMORY), strlen(filename)+1);
698 uustring (S_OUT_OF_MEMORY), strlen(filename)+1);
699 _FP_free (killem); 717 FP_free (killem);
700 } 718 }
701 else { 719 else {
702 killem->NEXT = ftodel; 720 killem->NEXT = ftodel;
703 ftodel = killem; 721 ftodel = killem;
704 } 722 }
708 progress.partno = 0; 726 progress.partno = 0;
709 progress.numparts = 1; 727 progress.numparts = 1;
710 progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1); 728 progress.fsize = (long) ((finfo.st_size>0)?finfo.st_size:-1);
711 progress.percent = 0; 729 progress.percent = 0;
712 progress.foffset = 0; 730 progress.foffset = 0;
713 _FP_strncpy (progress.curfile, 731 FP_strncpy (progress.curfile,
714 (strlen(filename)>255)? 732 (strlen(filename)>255)?
715 (filename+strlen(filename)-255):filename, 733 (filename+strlen(filename)-255):filename,
716 256); 734 256);
717 progress.action = UUACT_SCANNING; 735 progress.action = UUACT_SCANNING;
718 736
719 if (fileid == NULL) 737 if (fileid == NULL)
720 fileid = filename; 738 fileid = filename;
721 739
722 while (!feof (datei) && !ferror (datei)) { 740 while (!FP_feof (datei) && !ferror (datei)) {
723 /* 741 /*
724 * Peek file, or some systems won't detect EOF 742 * Peek file, or some systems won't detect EOF
725 */ 743 */
726 res = fgetc (datei); 744 res = FP_getc (datei);
727 if (feof (datei) || ferror (datei)) 745 if (FP_feof (datei) || ferror (datei))
728 break; 746 break;
729 else 747 else
730 ungetc (res, datei); 748 ungetc (res, datei);
731 749
732 if ((loaded = ScanPart (datei, fileid, &sr)) == NULL) { 750 if ((loaded = UUScanPart (datei, fileid, &sr)) == NULL) {
733 if (sr != UURET_NODATA && sr != UURET_OK && sr != UURET_CONT) { 751 if (sr != UURET_NODATA && sr != UURET_OK && sr != UURET_CONT) {
734 UUkillfread (loaded); 752 UUkillfread (loaded);
735 if (sr != UURET_CANCEL) { 753 if (sr != UURET_CANCEL)
736 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 754 UUMessage (UUMSG_ERROR,
737 uustring (S_READ_ERROR), filename, 755 uustring (S_READ_ERROR), filename,
738 strerror (uu_errno)); 756 strerror (uu_errno));
739 } 757
740 UUCheckGlobalList (); 758 if (uu_autocheck) UUCheckGlobalList ();
741 progress.action = 0; 759 progress.action = 0;
742 fclose (datei); 760 fclose (datei);
761 UUCLRBUF (uu_rbuf, datei_buf);
743 return sr; 762 return sr;
744 } 763 }
745 continue; 764 continue;
746 } 765 }
747 766
748 if (ferror (datei)) { 767 if (ferror (datei)) {
749 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 768 UUMessage (UUMSG_ERROR,
750 uustring (S_READ_ERROR), filename, 769 uustring (S_READ_ERROR), filename,
751 strerror (uu_errno = errno)); 770 strerror (uu_errno = errno));
752 UUCheckGlobalList (); 771 if (uu_autocheck) UUCheckGlobalList ();
753 progress.action = 0; 772 progress.action = 0;
754 fclose (datei); 773 fclose (datei);
774 UUCLRBUF (uu_rbuf, datei_buf);
755 return UURET_IOERR; 775 return UURET_IOERR;
756 } 776 }
757 777
758 if (partno != -1) 778 if (partno != -1)
759 loaded->partno = partno; 779 loaded->partno = partno;
777 */ 797 */
778 UUkillfread (loaded); 798 UUkillfread (loaded);
779 if (uu_fast_scanning && sr != UURET_CONT) break; 799 if (uu_fast_scanning && sr != UURET_CONT) break;
780 continue; 800 continue;
781 } 801 }
782 802
783 if ((fload = UUPreProcessPart (loaded, &res)) == NULL) { 803 if ((fload = UUPreProcessPart (loaded, &res)) == NULL) {
784 /* 804 /*
785 * no useful data found 805 * no useful data found
786 */ 806 */
787 if (res != UURET_NODATA) { 807 if (res != UURET_NODATA) {
788 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 808 UUMessage (UUMSG_ERROR,
789 uustring (S_READ_ERROR), filename, 809 uustring (S_READ_ERROR), filename,
790 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res)); 810 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res));
791 } 811 }
792 UUkillfread (loaded); 812 UUkillfread (loaded);
793 if (uu_fast_scanning && sr != UURET_CONT) break; 813 if (uu_fast_scanning && sr != UURET_CONT) break;
796 816
797 if ((loaded->subject && *(loaded->subject)) || 817 if ((loaded->subject && *(loaded->subject)) ||
798 (loaded->mimeid && *(loaded->mimeid)) || 818 (loaded->mimeid && *(loaded->mimeid)) ||
799 (loaded->filename&& *(loaded->filename))|| 819 (loaded->filename&& *(loaded->filename))||
800 (loaded->uudet)) { 820 (loaded->uudet)) {
801 UUMessage (uulib_id, __LINE__, UUMSG_MESSAGE, 821 UUMessage (UUMSG_MESSAGE,
802 uustring (S_LOADED_PART), 822 uustring (S_LOADED_PART),
803 filename, 823 filename,
804 (loaded->subject) ? loaded->subject : "", 824 (loaded->subject) ? loaded->subject : "",
805 (fload->subfname) ? fload->subfname : "", 825 (fload->subfname) ? fload->subfname : "",
806 (loaded->filename) ? loaded->filename : "", 826 (loaded->filename) ? loaded->filename : "",
807 fload->partno, 827 fload->partno,
808 (loaded->begin) ? "begin" : "", 828 (loaded->begin) ? "begin" : "",
809 (loaded->end) ? "end" : "", 829 (loaded->end) ? "end" : "",
810 codenames[loaded->uudet]); 830 codenames[loaded->uudet]);
811 } 831 }
812 832
813 if ((res = UUInsertPartToList (fload))) { 833 if ((res = UUInsertPartToList (fload))) {
814 /* 834 /*
815 * couldn't use the data 835 * couldn't use the data
816 */ 836 */
817 UUkillfile (fload); 837 UUkillfile (fload);
818 838
819 if (res != UURET_NODATA) { 839 if (res != UURET_NODATA) {
820 UUCheckGlobalList (); 840 if (uu_autocheck) UUCheckGlobalList ();
821 progress.action = 0; 841 progress.action = 0;
822 fclose (datei); 842 fclose (datei);
843 UUCLRBUF (uu_rbuf, datei_buf);
823 return res; 844 return res;
824 } 845 }
825 if (uu_fast_scanning && sr != UURET_CONT) 846 if (uu_fast_scanning && sr != UURET_CONT)
826 break; 847 break;
827 848
831 /* 852 /*
832 * if in fast mode, we don't look any further, because we're told 853 * if in fast mode, we don't look any further, because we're told
833 * that each source file holds at most one encoded part 854 * that each source file holds at most one encoded part
834 */ 855 */
835 856
857 if (loaded->uudet)
858 (*partcount)++;
859
836 if (uu_fast_scanning && sr != UURET_CONT) 860 if (uu_fast_scanning && sr != UURET_CONT)
837 break; 861 break;
838
839 if (loaded->uudet)
840 count++;
841 } 862 }
863
842 if (ferror (datei)) { 864 if (ferror (datei)) {
843 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 865 UUMessage (UUMSG_ERROR,
844 uustring (S_READ_ERROR), filename, 866 uustring (S_READ_ERROR), filename,
845 strerror (uu_errno = errno)); 867 strerror (uu_errno = errno));
846 UUCheckGlobalList (); 868 if (uu_autocheck) UUCheckGlobalList ();
847 progress.action = 0; 869 progress.action = 0;
848 fclose (datei); 870 fclose (datei);
871 UUCLRBUF (uu_rbuf, datei_buf);
849 return UURET_IOERR; 872 return UURET_IOERR;
850 } 873 }
874
851 fclose (datei); 875 fclose (datei);
876 UUCLRBUF (uu_rbuf, datei_buf);
852 877
853 if (!uu_fast_scanning && count==0) { 878 if (!uu_fast_scanning && *partcount == 0)
854 UUMessage (uulib_id, __LINE__, UUMSG_NOTE, 879 UUMessage (UUMSG_NOTE, uustring (S_NO_DATA_FOUND), filename);
855 uustring (S_NO_DATA_FOUND), filename);
856 }
857 880
858 progress.action = 0; 881 progress.action = 0;
859 UUCheckGlobalList (); 882 if (uu_autocheck) UUCheckGlobalList ();
860 883
861 return UURET_OK; 884 return UURET_OK;
862} 885}
863 886
864/* 887/*
877 900
878int UUEXPORT 901int UUEXPORT
879UUDecodeFile (uulist *thefile, char *destname) 902UUDecodeFile (uulist *thefile, char *destname)
880{ 903{
881 FILE *target, *source; 904 FILE *target, *source;
905 void *target_buf, *source_buf;
882 struct stat finfo; 906 struct stat finfo;
883 int fildes, res; 907 int fildes, res;
884 size_t bytes; 908 size_t bytes;
885 909
886 if (thefile == NULL) 910 if (thefile == NULL)
889 if ((res = UUDecode (thefile)) != UURET_OK) 913 if ((res = UUDecode (thefile)) != UURET_OK)
890 if (res != UURET_NOEND || !uu_desperate) 914 if (res != UURET_NOEND || !uu_desperate)
891 return res; 915 return res;
892 916
893 if (thefile->binfile == NULL) { 917 if (thefile->binfile == NULL) {
894 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 918 UUMessage (UUMSG_ERROR, uustring (S_NO_BIN_FILE));
895 uustring (S_NO_BIN_FILE));
896 return UURET_IOERR; 919 return UURET_IOERR;
897 } 920 }
898 921
899 if ((source = fopen (thefile->binfile, "rb")) == NULL) { 922 if ((source = fopen (thefile->binfile, "rb")) == NULL) {
900 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 923 UUMessage (UUMSG_ERROR,
901 uustring (S_NOT_OPEN_FILE), 924 uustring (S_NOT_OPEN_FILE),
902 thefile->binfile, strerror (uu_errno = errno)); 925 thefile->binfile, strerror (uu_errno = errno));
903 return UURET_IOERR; 926 return UURET_IOERR;
904 } 927 }
928 UUSETBUF (source, source_buf, uu_rbuf);
929 FP_flockfile (source);
905 930
906 /* 931 /*
907 * for system security, strip setuid/setgid bits from mode 932 * for system security, strip setuid/setgid bits from mode
908 */ 933 */
909 934
910 if ((thefile->mode & 0777) != thefile->mode) { 935 if ((thefile->mode & 0777) != thefile->mode) {
911 UUMessage (uulib_id, __LINE__, UUMSG_NOTE, 936 UUMessage (UUMSG_NOTE,
912 uustring (S_STRIPPED_SETUID), 937 uustring (S_STRIPPED_SETUID),
913 destname, (int)thefile->mode); 938 destname, (int)thefile->mode);
914 thefile->mode &= 0777; 939 thefile->mode &= 0777;
915 } 940 }
916 941
917 /* 942 /*
918 * Determine the name of the target file according to the rules: 943 * Determine the name of the target file according to the rules:
919 * 944 *
920 * IF (destname!=NULL) THEN filename=destname; 945 * IF (destname!=NULL) THEN filename=destname;
921 * ELSE 946 * ELSE
922 * filename = thefile->filename 947 * filename = thefile->filename
923 * IF (FilenameFilter!=NULL) THEN filename=FilenameFilter(filename); 948 * IF (FilenameFilter!=NULL) THEN filename=FilenameFilter(filename);
924 * filename = SaveFilePath + filename 949 * filename = SaveFilePath + filename
926 */ 951 */
927 952
928 if (destname) 953 if (destname)
929 strcpy (uugen_fnbuffer, destname); 954 strcpy (uugen_fnbuffer, destname);
930 else { 955 else {
956 char *fname = UUFNameFilter (thefile->filename ? thefile->filename : "unknown.xxx");
931 sprintf (uugen_fnbuffer, "%s%s", 957 sprintf (uugen_fnbuffer, "%.1024s%.3071s",
932 (uusavepath)?uusavepath:"", 958 uusavepath ? uusavepath : "",
933 UUFNameFilter ((thefile->filename)? 959 fname ? fname : "unknown.xxx");
934 thefile->filename:"unknown.xxx"));
935 } 960 }
936 961
937 /* 962 /*
938 * if we don't want to overwrite existing files, check if it's there 963 * if we don't want to overwrite existing files, check if it's there
939 */ 964 */
940 965
941 if (!uu_overwrite) { 966 if (!uu_overwrite) {
942 if (stat (uugen_fnbuffer, &finfo) == 0) { 967 if (stat (uugen_fnbuffer, &finfo) == 0) {
943 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 968 UUMessage (UUMSG_ERROR, uustring (S_TARGET_EXISTS), uugen_fnbuffer);
944 uustring (S_TARGET_EXISTS), uugen_fnbuffer);
945 fclose (source); 969 fclose (source);
970 UUCLRBUF (uu_rbuf, source_buf);
946 return UURET_EXISTS; 971 return UURET_EXISTS;
947 } 972 }
948 } 973 }
949 974
950 if (fstat (fileno(source), &finfo) == -1) { 975 if (fstat (fileno(source), &finfo) == -1) {
951 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 976 UUMessage (UUMSG_ERROR,
952 uustring (S_NOT_STAT_FILE), 977 uustring (S_NOT_STAT_FILE),
953 thefile->binfile, strerror (uu_errno = errno)); 978 thefile->binfile, strerror (uu_errno = errno));
954 fclose (source); 979 fclose (source);
980 UUCLRBUF (uu_rbuf, source_buf);
955 return UURET_IOERR; 981 return UURET_IOERR;
956 } 982 }
957 983
984 /* try rename() shortcut first */
985 if (!rename (thefile->binfile, uugen_fnbuffer))
986 {
987 mode_t mask = 0000; /* there is a slight window here anyway */
988#if HAVE_UMASK
989 mask = umask (0022); umask (mask);
990#endif
991 fclose (source);
992 UUCLRBUF (uu_rbuf, source_buf);
993#if HAVE_CHMOD
994 chmod (uugen_fnbuffer, thefile->mode & ~mask);
995#endif
996 goto skip_copy;
997 }
998
958 progress.action = 0; 999 progress.action = 0;
959 _FP_strncpy (progress.curfile, 1000 FP_strncpy (progress.curfile,
960 (strlen(uugen_fnbuffer)>255)? 1001 (strlen(uugen_fnbuffer)>255)?
961 (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer, 1002 (uugen_fnbuffer+strlen(uugen_fnbuffer)-255):uugen_fnbuffer,
962 256); 1003 256);
963 progress.partno = 0; 1004 progress.partno = 0;
964 progress.numparts = 1; 1005 progress.numparts = 1;
969 1010
970 if ((fildes = open (uugen_fnbuffer, 1011 if ((fildes = open (uugen_fnbuffer,
971 O_WRONLY | O_CREAT | O_BINARY | O_TRUNC, 1012 O_WRONLY | O_CREAT | O_BINARY | O_TRUNC,
972 (uu_ignmode)?0666:thefile->mode)) == -1) { 1013 (uu_ignmode)?0666:thefile->mode)) == -1) {
973 progress.action = 0; 1014 progress.action = 0;
974 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1015 UUMessage (UUMSG_ERROR,
975 uustring (S_NOT_OPEN_TARGET), 1016 uustring (S_NOT_OPEN_TARGET),
976 uugen_fnbuffer, strerror (uu_errno = errno)); 1017 uugen_fnbuffer, strerror (uu_errno = errno));
977 fclose (source); 1018 fclose (source);
1019 UUCLRBUF (uu_rbuf, source_buf);
978 return UURET_IOERR; 1020 return UURET_IOERR;
979 } 1021 }
980 1022
981 if ((target = fdopen (fildes, "wb")) == NULL) { 1023 if ((target = fdopen (fildes, "wb")) == NULL) {
982 progress.action = 0; 1024 progress.action = 0;
983 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1025 UUMessage (UUMSG_ERROR,
984 uustring (S_IO_ERR_TARGET), 1026 uustring (S_IO_ERR_TARGET),
985 uugen_fnbuffer, strerror (uu_errno = errno)); 1027 uugen_fnbuffer, strerror (uu_errno = errno));
986 fclose (source); 1028 fclose (source);
1029 UUCLRBUF (uu_rbuf, source_buf);
987 close (fildes); 1030 close (fildes);
988 return UURET_IOERR; 1031 return UURET_IOERR;
989 } 1032 }
1033 UUSETBUF (target, target_buf, uu_wbuf);
1034 FP_flockfile (target);
990 1035
991 while (!feof (source)) { 1036 while (!FP_feof (source)) {
992 1037
993 if (UUBUSYPOLL(ftell(source),progress.fsize)) { 1038 if (UUBUSYPOLL(ftell(source),progress.fsize)) {
994 UUMessage (uulib_id, __LINE__, UUMSG_NOTE, 1039 UUMessage (UUMSG_NOTE, uustring (S_DECODE_CANCEL));
995 uustring (S_DECODE_CANCEL));
996 fclose (source); 1040 fclose (source);
1041 UUCLRBUF (uu_rbuf, source_buf);
997 fclose (target); 1042 fclose (target);
1043 UUCLRBUF (uu_wbuf, target_buf);
998 unlink (uugen_fnbuffer); 1044 unlink (uugen_fnbuffer);
999 return UURET_CANCEL; 1045 return UURET_CANCEL;
1000 } 1046 }
1001 1047
1002 bytes = fread (uugen_inbuffer, 1, 1024, source); 1048 bytes = fread (uugen_inbuffer, 1, 1024, source);
1003 1049
1004 if (ferror (source) || (bytes == 0 && !feof (source))) { 1050 if (ferror (source) || (bytes == 0 && !FP_feof (source))) {
1005 progress.action = 0; 1051 progress.action = 0;
1006 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1052 UUMessage (UUMSG_ERROR,
1007 uustring (S_READ_ERROR), 1053 uustring (S_READ_ERROR),
1008 thefile->binfile, strerror (uu_errno = errno)); 1054 thefile->binfile, strerror (uu_errno = errno));
1009 fclose (source); 1055 fclose (source);
1056 UUCLRBUF (uu_rbuf, source_buf);
1010 fclose (target); 1057 fclose (target);
1058 UUCLRBUF (uu_wbuf, target_buf);
1011 unlink (uugen_fnbuffer); 1059 unlink (uugen_fnbuffer);
1012 return UURET_IOERR; 1060 return UURET_IOERR;
1013 } 1061 }
1014 if (fwrite (uugen_inbuffer, 1, bytes, target) != bytes) { 1062 if (fwrite (uugen_inbuffer, 1, bytes, target) != bytes) {
1015 progress.action = 0; 1063 progress.action = 0;
1016 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1064 UUMessage (UUMSG_ERROR,
1017 uustring (S_WR_ERR_TARGET), 1065 uustring (S_WR_ERR_TARGET),
1018 uugen_fnbuffer, strerror (uu_errno = errno)); 1066 uugen_fnbuffer, strerror (uu_errno = errno));
1019 fclose (source); 1067 fclose (source);
1068 UUCLRBUF (uu_rbuf, source_buf);
1020 fclose (target); 1069 fclose (target);
1070 UUCLRBUF (uu_wbuf, target_buf);
1021 unlink (uugen_fnbuffer); 1071 unlink (uugen_fnbuffer);
1022 return UURET_IOERR; 1072 return UURET_IOERR;
1023 } 1073 }
1024 } 1074 }
1025 1075
1026 fclose (source); 1076 fclose (source);
1077 UUCLRBUF (uu_rbuf, source_buf);
1027 if (fclose (target)) { 1078 if (fclose (target)) {
1028 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1079 UUCLRBUF (uu_wbuf, target_buf);
1080 UUMessage (UUMSG_ERROR,
1029 uustring (S_WR_ERR_TARGET), 1081 uustring (S_WR_ERR_TARGET),
1030 uugen_fnbuffer, strerror (uu_errno = errno)); 1082 uugen_fnbuffer, strerror (uu_errno = errno));
1031 unlink (uugen_fnbuffer); 1083 unlink (uugen_fnbuffer);
1032 return UURET_IOERR; 1084 return UURET_IOERR;
1033 } 1085 }
1086 UUCLRBUF (uu_wbuf, target_buf);
1034 1087
1035 /* 1088 /*
1036 * after a successful decoding run, we delete the temporary file 1089 * after a successful decoding run, we delete the temporary file
1037 */ 1090 */
1038 1091
1039 if (unlink (thefile->binfile)) { 1092 if (unlink (thefile->binfile)) {
1040 UUMessage (uulib_id, __LINE__, UUMSG_WARNING, 1093 UUMessage (UUMSG_WARNING,
1041 uustring (S_TMP_NOT_REMOVED), 1094 uustring (S_TMP_NOT_REMOVED),
1042 thefile->binfile, 1095 thefile->binfile,
1043 strerror (uu_errno = errno)); 1096 strerror (uu_errno = errno));
1044 } 1097 }
1098
1099skip_copy:
1045 _FP_free (thefile->binfile); 1100 FP_free (thefile->binfile);
1046 thefile->binfile = NULL; 1101 thefile->binfile = NULL;
1047 thefile->state &= ~UUFILE_TMPFILE; 1102 thefile->state &= ~UUFILE_TMPFILE;
1048 thefile->state |= UUFILE_DECODED; 1103 thefile->state |= UUFILE_DECODED;
1049 progress.action = 0; 1104 progress.action = 0;
1050 1105
1056 * If the function returns non-zero, we break and don't send any more 1111 * If the function returns non-zero, we break and don't send any more
1057 */ 1112 */
1058 1113
1059int UUEXPORT 1114int UUEXPORT
1060UUInfoFile (uulist *thefile, void *opaque, 1115UUInfoFile (uulist *thefile, void *opaque,
1061 int (*func) _ANSI_ARGS_((void *, char *))) 1116 int (*func) (void *, char *))
1062{ 1117{
1063 int errflag=0, res, bhflag=0, dd; 1118 int errflag=0, res, bhflag=0, dd;
1064 long maxpos; 1119 long maxpos;
1065 FILE *inpfile; 1120 FILE *inpfile;
1066 1121
1067 /* 1122 /*
1068 * We might need to ask our callback function to download the file 1123 * We might need to ask our callback function to download the file
1069 */ 1124 */
1070 1125
1071 if (uu_FileCallback) { 1126 if (uu_FileCallback) {
1072 if ((res = (*uu_FileCallback) (uu_FileCBArg, 1127 if ((res = (*uu_FileCallback) (uu_FileCBArg,
1073 thefile->thisfile->data->sfname, 1128 thefile->thisfile->data->sfname,
1074 uugen_fnbuffer, 1129 uugen_fnbuffer,
1075 1)) != UURET_OK) 1130 1)) != UURET_OK)
1076 return res; 1131 return res;
1077 if ((inpfile = fopen (uugen_fnbuffer, "rb")) == NULL) { 1132 if ((inpfile = fopen (uugen_fnbuffer, "rb")) == NULL) {
1078 (*uu_FileCallback) (uu_FileCBArg, thefile->thisfile->data->sfname, 1133 (*uu_FileCallback) (uu_FileCBArg, thefile->thisfile->data->sfname,
1079 uugen_fnbuffer, 0); 1134 uugen_fnbuffer, 0);
1080 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1135 UUMessage (UUMSG_ERROR,
1081 uustring (S_NOT_OPEN_FILE), uugen_fnbuffer, 1136 uustring (S_NOT_OPEN_FILE), uugen_fnbuffer,
1082 strerror (uu_errno = errno)); 1137 strerror (uu_errno = errno));
1083 return UURET_IOERR; 1138 return UURET_IOERR;
1084 } 1139 }
1085 } 1140 }
1086 else { 1141 else {
1087 if ((inpfile = fopen (thefile->thisfile->data->sfname, "rb")) == NULL) { 1142 if ((inpfile = fopen (thefile->thisfile->data->sfname, "rb")) == NULL) {
1088 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1143 UUMessage (UUMSG_ERROR,
1089 uustring (S_NOT_OPEN_FILE), 1144 uustring (S_NOT_OPEN_FILE),
1090 thefile->thisfile->data->sfname, 1145 thefile->thisfile->data->sfname,
1091 strerror (uu_errno=errno)); 1146 strerror (uu_errno=errno));
1092 return UURET_IOERR; 1147 return UURET_IOERR;
1093 } 1148 }
1094 _FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024); 1149 FP_strncpy (uugen_fnbuffer, thefile->thisfile->data->sfname, 1024);
1095 } 1150 }
1096 1151
1097 /* 1152 /*
1098 * seek to beginning of info 1153 * seek to beginning of info
1099 */ 1154 */
1100 1155
1101 fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET); 1156 fseek (inpfile, thefile->thisfile->data->startpos, SEEK_SET);
1102 maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length; 1157 maxpos = thefile->thisfile->data->startpos + thefile->thisfile->data->length;
1103 1158
1104 while (!feof (inpfile) && 1159 while (!FP_feof (inpfile) &&
1105 (uu_fast_scanning || ftell(inpfile) < maxpos)) { 1160 (uu_fast_scanning || ftell(inpfile) < maxpos)) {
1106 if (_FP_fgets (uugen_inbuffer, 511, inpfile) == NULL) 1161 if (FP_fgets (uugen_inbuffer, 511, inpfile) == NULL)
1107 break; 1162 break;
1108 uugen_inbuffer[511] = '\0'; 1163 uugen_inbuffer[511] = '\0';
1109 1164
1110 if (ferror (inpfile)) 1165 if (ferror (inpfile))
1111 break; 1166 break;
1126 if ((*func) (opaque, uugen_inbuffer)) 1181 if ((*func) (opaque, uugen_inbuffer))
1127 break; 1182 break;
1128 } 1183 }
1129 1184
1130 if (ferror (inpfile)) { 1185 if (ferror (inpfile)) {
1131 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1186 UUMessage (UUMSG_ERROR,
1132 uustring (S_READ_ERROR), 1187 uustring (S_READ_ERROR),
1133 uugen_fnbuffer, strerror (uu_errno = errno)); 1188 uugen_fnbuffer, strerror (uu_errno = errno));
1134 errflag = 1; 1189 errflag = 1;
1135 } 1190 }
1136 1191
1137 fclose (inpfile); 1192 fclose (inpfile);
1138 1193
1139 if (uu_FileCallback) 1194 if (uu_FileCallback)
1140 (*uu_FileCallback) (uu_FileCBArg, 1195 (*uu_FileCallback) (uu_FileCBArg,
1141 thefile->thisfile->data->sfname, 1196 thefile->thisfile->data->sfname,
1142 uugen_fnbuffer, 0); 1197 uugen_fnbuffer, 0);
1143 1198
1144 if (errflag) 1199 if (errflag)
1145 return UURET_IOERR; 1200 return UURET_IOERR;
1146 1201
1147 return UURET_OK; 1202 return UURET_OK;
1148} 1203}
1149 1204
1150int UUEXPORT 1205int UUEXPORT
1151UURenameFile (uulist *thefile, char *newname) 1206UURenameFile (uulist *thefile, char *newname)
1152{ 1207{
1153 char *oldname; 1208 char *oldname;
1154 1209
1155 if (thefile == NULL) 1210 if (thefile == NULL)
1156 return UURET_ILLVAL; 1211 return UURET_ILLVAL;
1157 1212
1158 oldname = thefile->filename; 1213 oldname = thefile->filename;
1159 1214
1160 if ((thefile->filename = _FP_strdup (newname)) == NULL) { 1215 if ((thefile->filename = FP_strdup (newname)) == NULL) {
1161 UUMessage (uulib_id, __LINE__, UUMSG_ERROR, 1216 UUMessage (UUMSG_ERROR, uustring (S_NOT_RENAME), oldname, newname);
1162 uustring (S_NOT_RENAME),
1163 oldname, newname);
1164 thefile->filename = oldname; 1217 thefile->filename = oldname;
1165 return UURET_NOMEM; 1218 return UURET_NOMEM;
1166 } 1219 }
1167 _FP_free (oldname); 1220 FP_free (oldname);
1168 return UURET_OK; 1221 return UURET_OK;
1169} 1222}
1170 1223
1171int UUEXPORT 1224int UUEXPORT
1172UURemoveTemp (uulist *thefile) 1225UURemoveTemp (uulist *thefile)
1174 if (thefile == NULL) 1227 if (thefile == NULL)
1175 return UURET_ILLVAL; 1228 return UURET_ILLVAL;
1176 1229
1177 if (thefile->binfile) { 1230 if (thefile->binfile) {
1178 if (unlink (thefile->binfile)) { 1231 if (unlink (thefile->binfile)) {
1179 UUMessage (uulib_id, __LINE__, UUMSG_WARNING, 1232 UUMessage (UUMSG_WARNING,
1180 uustring (S_TMP_NOT_REMOVED), 1233 uustring (S_TMP_NOT_REMOVED),
1181 thefile->binfile, 1234 thefile->binfile,
1182 strerror (uu_errno = errno)); 1235 strerror (uu_errno = errno));
1183 } 1236 }
1184 _FP_free (thefile->binfile); 1237 FP_free (thefile->binfile);
1185 thefile->binfile = NULL; 1238 thefile->binfile = NULL;
1186 thefile->state &= ~UUFILE_TMPFILE; 1239 thefile->state &= ~UUFILE_TMPFILE;
1187 } 1240 }
1188 return UURET_OK; 1241 return UURET_OK;
1189} 1242}
1200 * delete temporary input files (such as the copy of stdin) 1253 * delete temporary input files (such as the copy of stdin)
1201 */ 1254 */
1202 1255
1203 while (iter) { 1256 while (iter) {
1204 if (unlink (iter->fname)) { 1257 if (unlink (iter->fname)) {
1205 UUMessage (uulib_id, __LINE__, UUMSG_WARNING, 1258 UUMessage (UUMSG_WARNING,
1206 uustring (S_TMP_NOT_REMOVED), 1259 uustring (S_TMP_NOT_REMOVED),
1207 iter->fname, strerror (uu_errno = errno)); 1260 iter->fname, strerror (uu_errno = errno));
1208 } 1261 }
1209 _FP_free (iter->fname); 1262 FP_free (iter->fname);
1210 ptr = iter; 1263 ptr = iter;
1211 iter = iter->NEXT; 1264 iter = iter->NEXT;
1212 _FP_free (ptr); 1265 FP_free (ptr);
1213 } 1266 }
1214 1267
1215 ftodel = NULL; 1268 ftodel = NULL;
1216 1269
1217 /* 1270 /*
1239 } 1292 }
1240 1293
1241 UUkilllist (UUGlobalFileList); 1294 UUkilllist (UUGlobalFileList);
1242 UUGlobalFileList = NULL; 1295 UUGlobalFileList = NULL;
1243 1296
1244 _FP_free (uusavepath); 1297 FP_free (uusavepath);
1245 _FP_free (uuencodeext); 1298 FP_free (uuencodeext);
1246 _FP_free (sstate.source); 1299 FP_free (sstate.source);
1247 1300
1248 uusavepath = NULL; 1301 uusavepath = NULL;
1249 uuencodeext = NULL; 1302 uuencodeext = NULL;
1250 1303
1251 UUkillheaders (&localenv); 1304 UUkillheaders (&localenv);
1254 memset (&sstate, 0, sizeof (scanstate)); 1307 memset (&sstate, 0, sizeof (scanstate));
1255 1308
1256 while (mssdepth) { 1309 while (mssdepth) {
1257 mssdepth--; 1310 mssdepth--;
1258 UUkillheaders (&(multistack[mssdepth].envelope)); 1311 UUkillheaders (&(multistack[mssdepth].envelope));
1259 _FP_free (multistack[mssdepth].source); 1312 FP_free (multistack[mssdepth].source);
1260 } 1313 }
1261 1314
1262 /* 1315 /*
1263 * clean up the malloc'ed stuff 1316 * clean up the malloc'ed stuff
1264 */ 1317 */
1265 1318
1266 for (aiter=toallocate; aiter->ptr; aiter++) { 1319 for (aiter=toallocate; aiter->ptr; aiter++) {
1267 _FP_free (*(aiter->ptr)); 1320 safe_free (*(aiter->ptr), aiter->size);
1268 *(aiter->ptr) = NULL; 1321 *(aiter->ptr) = NULL;
1269 } 1322 }
1270 1323
1271 return UURET_OK; 1324 return UURET_OK;
1272} 1325}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines