"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "compfile.c" between
afio-2.5.1.tgz and afio-2.5.2.tgz

About: Afio is an archiver & backup program with builtin compression (generates cpio-format archives).

compfile.c  (afio-2.5.1.tgz):compfile.c  (afio-2.5.2.tgz)
/* afio file compresssion code */ /* afio file compresssion code */
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/signal.h> #include <sys/signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "patchlevel.h" #include "patchlevel.h"
#include "afio.h" #include "afio.h"
int matchcompext(char *); int matchcompext(char *);
skipping to change at line 102 skipping to change at line 103
void memwrite(char *buf, int count) void memwrite(char *buf, int count)
{ {
char *oldbank; char *oldbank;
if(memerror) return; if(memerror) return;
oldbank=membank; oldbank=membank;
/* RWWH: don't increase by linear amount! grow exponentially! */ /* RWWH: don't increase by linear amount! grow exponentially! */
if (memsize+count>=allocsize) { if (memsize+count>=allocsize) {
allocsize=1.25*(memsize+count); allocsize=1.25*(memsize+count);
membank=(char *)realloc(membank,allocsize); if(allocsize/1024L/1024L > 2000)
{
/* safety: to avoid possible errors due to use of 32 bit int
and size_t types here and there, prevent membank going over 2GB if
compression programm actually expands filesize.
Note that -M is capped at 1.5GB anyway.
*/
membank=NULL; /* simulate realloc running out of memory */
}
else
{
membank=(char *)realloc(membank,allocsize);
}
if(membank==NULL) if(membank==NULL)
{ {
warn_nocount("Memory","Low on virtual memory, zipping twice instead."); warn_nocount("Memory","Low on virtual memory, zipping twice instead.");
/* The free() both works and is necessary. I can't recall what /* The free() both works and is necessary. I can't recall what
manpage documents this. */ manpage documents this. */
free(oldbank); free(oldbank);
memerror=1; memerror=1;
allocsize=0; allocsize=0;
return; return;
} }
skipping to change at line 226 skipping to change at line 239
void void
compressfile (int *fdp, char *name, reg Stat *asb, int *cratio) { compressfile (int *fdp, char *name, reg Stat *asb, int *cratio) {
int compout; int compout;
char *tmpcomp; char *tmpcomp;
Stat asb2; Stat asb2;
int zipfd; int zipfd;
ssize_t len; ssize_t len;
char buf[40960]; char buf[40960];
off_t ziplen; off_t ziplen;
int namelen,usemem; int usemem;
if (cratio) if (cratio)
*cratio = 100; *cratio = 100;
/* We need to mark the file as being suitable or not for decompression on /* We need to mark the file as being suitable or not for decompression on
reading the archive. This is done by adding a .z extension. reading the archive. This is done by adding a .z extension.
There is a problem with this: a file that is not suitable for There is a problem with this: a file that is not suitable for
compression may already have such an extension. compression may already have such an extension.
Since this is a regular file, we can use the Since this is a regular file, we can use the
skipping to change at line 258 skipping to change at line 271
see filenames with the bit 0 and not ending in .z. Such files see filenames with the bit 0 and not ending in .z. Such files
have a compressed version larger than the original.) have a compressed version larger than the original.)
In pre-2.4.4 versions, files with size 0 do not have the bit In pre-2.4.4 versions, files with size 0 do not have the bit
set to 1. set to 1.
*/ */
/* indicate unsuitable for compression, may change it later */ /* indicate unsuitable for compression, may change it later */
asb->sb_rdev |= RDEV_NOTCOMPR; asb->sb_rdev |= RDEV_NOTCOMPR;
namelen = strlen (name);
/* Hard link handling code will break if we do compression on the /* Hard link handling code will break if we do compression on the
file, so try to compress only if no links or hard link handling. file, so try to compress only if no links or hard link handling.
Note that if forceZflag==1 than also lflag==1 was set, so this Note that if forceZflag==1 than also lflag==1 was set, so this
test will never return false. test will never return false.
Also only try to compress if not already compressed, Also only try to compress if not already compressed,
or length is >= threshold, or <= maxsizetocompress, or length is >= threshold, or <= maxsizetocompress,
but always try if we force compression but always try if we force compression
*/ */
skipping to change at line 284 skipping to change at line 296
) )
|| forceZflag || forceZflag
) )
) )
{ {
/* make sure compress could put on the .Z */ /* make sure compress could put on the .Z */
if ((tmpcomp = strrchr (name, '/')) != NULL) if ((tmpcomp = strrchr (name, '/')) != NULL)
tmpcomp++; tmpcomp++;
else else
tmpcomp = name; tmpcomp = name;
#ifdef NAME_MAX
if (strlen (tmpcomp) + 2 > NAME_MAX)
#else
#ifdef MAXNAMLEN /* BSD otherwise should be sysV (FFS on sysV?) */ #ifdef MAXNAMLEN /* BSD otherwise should be sysV (FFS on sysV?) */
if (strlen (tmpcomp) + 2 > MAXNAMLEN) if (strlen (tmpcomp) + 2 > MAXNAMLEN)
#else #else
if (strlen (tmpcomp) + 2 > DIRSIZ) if (strlen (tmpcomp) + 2 > DIRSIZ)
#endif #endif /* MAXNAMLEN */
#endif /* NAME_MAX */
{ {
#ifndef LONGZFILE #ifndef LONGZFILE
VOID warn (name, " is too long to tack on .z"); VOID warn (name, " is too long to tack on .z");
return; return;
#endif #endif
} }
/* fprintf(stderr,"---nam: %s, len: %d ziplen: ",name,asb->sb_size); */ /* fprintf(stderr,"---nam: %s, len: %d ziplen: ",name,asb->sb_size); */
usemem=1; usemem=1;
 End of changes. 6 change blocks. 
4 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)