bzip2.c (146294) | bzip2.c (147666) |
---|---|
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 | 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 $ */ |
|
102 103 104/*----------------------------------------------------*/ 105/*--- and now for something much more pleasant :-) ---*/ 106/*----------------------------------------------------*/ 107 108/*---------------------------------------------*/ 109/*-- --- 197 unchanged lines hidden (view full) --- 307static void outOfMemory ( void ) NORETURN; 308static void configError ( void ) NORETURN; 309static void crcError ( void ) NORETURN; 310static void cleanUpAndFail ( Int32 ) NORETURN; 311static void compressedStreamEOF ( void ) NORETURN; 312 313static void copyFileName ( Char*, Char* ); 314static void* myMalloc ( Int32 ); | 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 ); |
|
315 316 317 318/*---------------------------------------------------*/ 319/*--- An implementation of 64-bit ints. Sigh. ---*/ 320/*--- Roll on widespread deployment of ANSI C9X ! ---*/ 321/*---------------------------------------------------*/ 322 --- 129 unchanged lines hidden (view full) --- 452 &nbytes_in_lo32, &nbytes_in_hi32, 453 &nbytes_out_lo32, &nbytes_out_hi32 ); 454 if (bzerr != BZ_OK) goto errhandler; 455 456 if (ferror(zStream)) goto errhandler_io; 457 ret = fflush ( zStream ); 458 if (ret == EOF) goto errhandler_io; 459 if (zStream != stdout) { | 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; |
|
460 ret = fclose ( zStream ); 461 outputHandleJustInCase = NULL; 462 if (ret == EOF) goto errhandler_io; 463 } 464 outputHandleJustInCase = NULL; 465 if (ferror(stream)) goto errhandler_io; 466 ret = fclose ( stream ); 467 if (ret == EOF) goto errhandler_io; --- 96 unchanged lines hidden (view full) --- 564 BZ2_bzReadClose ( &bzerr, bzf ); 565 if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); 566 567 if (nUnused == 0 && myfeof(zStream)) break; 568 } 569 570 closeok: 571 if (ferror(zStream)) 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 } |
|
572 ret = fclose ( zStream ); 573 if (ret == EOF) goto errhandler_io; 574 575 if (ferror(stream)) goto errhandler_io; 576 ret = fflush ( stream ); 577 if (ret != 0) goto errhandler_io; 578 if (stream != stdout) { 579 ret = fclose ( stream ); --- 544 unchanged lines hidden (view full) --- 1124 /* Note use of stat here, not lstat. */ 1125 retVal = MY_STAT( srcName, &fileMetaInfo ); 1126 ERROR_IF_NOT_ZERO ( retVal ); 1127# endif 1128} 1129 1130 1131static | 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 |
1132void applySavedMetaInfoToOutputFile ( Char *dstName ) | 1144void applySavedTimeInfoToOutputFile ( Char *dstName ) |
1133{ 1134# if BZ_UNIX 1135 IntNative retVal; 1136 struct utimbuf uTimBuf; 1137 1138 uTimBuf.actime = fileMetaInfo.st_atime; 1139 uTimBuf.modtime = fileMetaInfo.st_mtime; 1140 | 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 |
1141 retVal = chmod ( dstName, fileMetaInfo.st_mode ); 1142 ERROR_IF_NOT_ZERO ( retVal ); 1143 | |
1144 retVal = utime ( dstName, &uTimBuf ); 1145 ERROR_IF_NOT_ZERO ( retVal ); | 1153 retVal = utime ( dstName, &uTimBuf ); 1154 ERROR_IF_NOT_ZERO ( retVal ); |
1155# endif 1156} |
|
1146 | 1157 |
1147 retVal = chown ( dstName, fileMetaInfo.st_uid, fileMetaInfo.st_gid ); | 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 ); |
1148 /* chown() will in many cases return with EPERM, which can 1149 be safely ignored. 1150 */ | 1169 /* chown() will in many cases return with EPERM, which can 1170 be safely ignored. 1171 */ |
1172 return 0; |
|
1151# endif 1152} 1153 1154 1155/*---------------------------------------------*/ 1156static 1157Bool containsDubiousChars ( Char* name ) 1158{ --- 206 unchanged lines hidden (view full) --- 1365 /*--- Now the input and output handles are sane. Do the Biz. ---*/ 1366 outputHandleJustInCase = outStr; 1367 deleteOutputOnInterrupt = True; 1368 compressStream ( inStr, outStr ); 1369 outputHandleJustInCase = NULL; 1370 1371 /*--- If there was an I/O error, we won't get here. ---*/ 1372 if ( srcMode == SM_F2F ) { | 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 ) { |
1373 applySavedMetaInfoToOutputFile ( outName ); | 1395 applySavedTimeInfoToOutputFile ( outName ); |
1374 deleteOutputOnInterrupt = False; 1375 if ( !keepInputFiles ) { 1376 IntNative retVal = remove ( inName ); 1377 ERROR_IF_NOT_ZERO ( retVal ); 1378 } 1379 } 1380 1381 deleteOutputOnInterrupt = False; --- 161 unchanged lines hidden (view full) --- 1543 outputHandleJustInCase = outStr; 1544 deleteOutputOnInterrupt = True; 1545 magicNumberOK = uncompressStream ( inStr, outStr ); 1546 outputHandleJustInCase = NULL; 1547 1548 /*--- If there was an I/O error, we won't get here. ---*/ 1549 if ( magicNumberOK ) { 1550 if ( srcMode == SM_F2F ) { | 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 ) { |
1551 applySavedMetaInfoToOutputFile ( outName ); | 1573 applySavedTimeInfoToOutputFile ( outName ); |
1552 deleteOutputOnInterrupt = False; 1553 if ( !keepInputFiles ) { 1554 IntNative retVal = remove ( inName ); 1555 ERROR_IF_NOT_ZERO ( retVal ); 1556 } 1557 } 1558 } else { 1559 unzFailsExist = True; --- 548 unchanged lines hidden --- | 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 --- |