1 2/*-----------------------------------------------------------*/ 3/*--- A block-sorting, lossless compressor bzip2.c ---*/ 4/*-----------------------------------------------------------*/ 5 6/*-- 7 This file is a part of bzip2 and/or libbzip2, a program and 8 library for lossless, block-sorting data compression. --- 85 unchanged lines hidden (view full) --- 94 95 PATENTS: 96 To the best of my knowledge, bzip2/libbzip2 does not use any 97 patented algorithms. However, I do not have the resources 98 available to carry out a full patent search. Therefore I cannot 99 give any guarantee of the above statement. 100--*/ 101 |
102/* $FreeBSD: head/contrib/bzip2/bzip2.c 147666 2005-06-29 21:36:49Z simon $ */ |
103 104 105/*----------------------------------------------------*/ 106/*--- and now for something much more pleasant :-) ---*/ 107/*----------------------------------------------------*/ 108 109/*---------------------------------------------*/ 110/*-- --- 197 unchanged lines hidden (view full) --- 308static void outOfMemory ( void ) NORETURN; 309static void configError ( void ) NORETURN; 310static void crcError ( void ) NORETURN; 311static void cleanUpAndFail ( Int32 ) NORETURN; 312static void compressedStreamEOF ( void ) NORETURN; 313 314static void copyFileName ( Char*, Char* ); 315static void* myMalloc ( Int32 ); |
316static int applySavedFileAttrToOutputFile ( int fd ); |
317 318 319 320/*---------------------------------------------------*/ 321/*--- An implementation of 64-bit ints. Sigh. ---*/ 322/*--- Roll on widespread deployment of ANSI C9X ! ---*/ 323/*---------------------------------------------------*/ 324 --- 129 unchanged lines hidden (view full) --- 454 &nbytes_in_lo32, &nbytes_in_hi32, 455 &nbytes_out_lo32, &nbytes_out_hi32 ); 456 if (bzerr != BZ_OK) goto errhandler; 457 458 if (ferror(zStream)) goto errhandler_io; 459 ret = fflush ( zStream ); 460 if (ret == EOF) goto errhandler_io; 461 if (zStream != stdout) { |
462 int fd = fileno ( zStream ); 463 if (fd < 0) goto errhandler_io; 464 ret = applySavedFileAttrToOutputFile ( fd ); 465 if (ret != 0) goto errhandler_io; |
466 ret = fclose ( zStream ); 467 outputHandleJustInCase = NULL; 468 if (ret == EOF) goto errhandler_io; 469 } 470 outputHandleJustInCase = NULL; 471 if (ferror(stream)) goto errhandler_io; 472 ret = fclose ( stream ); 473 if (ret == EOF) goto errhandler_io; --- 96 unchanged lines hidden (view full) --- 570 BZ2_bzReadClose ( &bzerr, bzf ); 571 if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); 572 573 if (nUnused == 0 && myfeof(zStream)) break; 574 } 575 576 closeok: 577 if (ferror(zStream)) goto errhandler_io; |
578 if ( stream != stdout) { 579 int fd = fileno ( stream ); 580 if (fd < 0) goto errhandler_io; 581 ret = applySavedFileAttrToOutputFile ( fd ); 582 if (ret != 0) goto errhandler_io; 583 } |
584 ret = fclose ( zStream ); 585 if (ret == EOF) goto errhandler_io; 586 587 if (ferror(stream)) goto errhandler_io; 588 ret = fflush ( stream ); 589 if (ret != 0) goto errhandler_io; 590 if (stream != stdout) { 591 ret = fclose ( stream ); --- 544 unchanged lines hidden (view full) --- 1136 /* Note use of stat here, not lstat. */ 1137 retVal = MY_STAT( srcName, &fileMetaInfo ); 1138 ERROR_IF_NOT_ZERO ( retVal ); 1139# endif 1140} 1141 1142 1143static |
1144void applySavedTimeInfoToOutputFile ( Char *dstName ) |
1145{ 1146# if BZ_UNIX 1147 IntNative retVal; 1148 struct utimbuf uTimBuf; 1149 1150 uTimBuf.actime = fileMetaInfo.st_atime; 1151 uTimBuf.modtime = fileMetaInfo.st_mtime; 1152 |
1153 retVal = utime ( dstName, &uTimBuf ); 1154 ERROR_IF_NOT_ZERO ( retVal ); |
1155# endif 1156} |
1157 |
1158static 1159int applySavedFileAttrToOutputFile ( int fd ) 1160{ 1161# if BZ_UNIX 1162 IntNative retVal; 1163 1164 retVal = fchmod ( fd, fileMetaInfo.st_mode ); 1165 if (retVal != 0) 1166 return retVal; 1167 1168 (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid ); |
1169 /* chown() will in many cases return with EPERM, which can 1170 be safely ignored. 1171 */ |
1172 return 0; |
1173# endif 1174} 1175 1176 1177/*---------------------------------------------*/ 1178static 1179Bool containsDubiousChars ( Char* name ) 1180{ --- 206 unchanged lines hidden (view full) --- 1387 /*--- Now the input and output handles are sane. Do the Biz. ---*/ 1388 outputHandleJustInCase = outStr; 1389 deleteOutputOnInterrupt = True; 1390 compressStream ( inStr, outStr ); 1391 outputHandleJustInCase = NULL; 1392 1393 /*--- If there was an I/O error, we won't get here. ---*/ 1394 if ( srcMode == SM_F2F ) { |
1395 applySavedTimeInfoToOutputFile ( outName ); |
1396 deleteOutputOnInterrupt = False; 1397 if ( !keepInputFiles ) { 1398 IntNative retVal = remove ( inName ); 1399 ERROR_IF_NOT_ZERO ( retVal ); 1400 } 1401 } 1402 1403 deleteOutputOnInterrupt = False; --- 161 unchanged lines hidden (view full) --- 1565 outputHandleJustInCase = outStr; 1566 deleteOutputOnInterrupt = True; 1567 magicNumberOK = uncompressStream ( inStr, outStr ); 1568 outputHandleJustInCase = NULL; 1569 1570 /*--- If there was an I/O error, we won't get here. ---*/ 1571 if ( magicNumberOK ) { 1572 if ( srcMode == SM_F2F ) { |
1573 applySavedTimeInfoToOutputFile ( outName ); |
1574 deleteOutputOnInterrupt = False; 1575 if ( !keepInputFiles ) { 1576 IntNative retVal = remove ( inName ); 1577 ERROR_IF_NOT_ZERO ( retVal ); 1578 } 1579 } 1580 } else { 1581 unzFailsExist = True; --- 548 unchanged lines hidden --- |