[comp.sources.bugs] ARC - fopen mode problem + fix

bin@rhesus.primate.wisc.edu (Brain in Neutral) (07/18/88)

Well, my system doesn't have fopen modes of "rb", "wb" or "w+b", so
I changed the fopen calls to use #define'd identifiers, and set the
values of them depending on whether BSD is set or not.  "r", "w" and "w+"
are used if it is, otherwise the values as distributed.  The patch
below makes the changes.

*** arc.c~	Mon Jul 18 09:52:51 1988
--- arc.c	Mon Jul 18 09:53:47 1988
***************
*** 361,367
  
  	if (*p) {		/* use name if one was given */
  		makefnam(p, ".CMD", buf);
! 		if (!(lf = fopen(buf, "r")))
  			abort("Cannot read list of files in %s", buf);
  	} else
  		lf = stdin;	/* else use standard input */

--- 361,367 -----
  
  	if (*p) {		/* use name if one was given */
  		makefnam(p, ".CMD", buf);
! 		if (!(lf = fopen(buf, RMODE)))
  			abort("Cannot read list of files in %s", buf);
  	} else
  		lf = stdin;	/* else use standard input */
*** arc.h~	Mon Jul 18 09:48:45 1988
--- arc.h	Mon Jul 18 10:03:58 1988
***************
*** 48,53
  #define	CUTOFF	sepchr[0]
  #endif
  
  /*  ARC - Archive utility - ARC Header
    
      Version 2.17, created on 04/22/87 at 13:09:43

--- 48,75 -----
  #define	CUTOFF	sepchr[0]
  #endif
  
+ # define	RMODE	"r"
+ # define	RBMOD	"rb"
+ # define	WMODE	"w"
+ # define	WBMODE	"wb"
+ # define	UMODE	"w+"
+ # define	UBMODE	"w+b"
+ 
+ # if	BSD
+ # undef	RMODE
+ # undef	RBMOD
+ # undef	WMODE
+ # undef	WBMODE
+ # undef	UMODE
+ # undef	UBMODE
+ # define	RMODE	"r"
+ # define	RBMOD	"r"
+ # define	WMODE	"w"
+ # define	WBMODE	"w"
+ # define	UMODE	"w+"
+ # define	UBMODE	"w+"
+ # endif
+ 
  /*  ARC - Archive utility - ARC Header
    
      Version 2.17, created on 04/22/87 at 13:09:43
*** arcadd.c~	Mon Jul 18 09:53:55 1988
--- arcadd.c	Mon Jul 18 09:54:17 1988
***************
*** 231,237
  	int             upd = 0;/* true if replacing an entry */
  
  #if	!MTS
! 	if (!(f = fopen(path, "rb")))
  #else
  	if (image)
  		f = fopen(path, "rb");

--- 231,237 -----
  	int             upd = 0;/* true if replacing an entry */
  
  #if	!MTS
! 	if (!(f = fopen(path, RBMODE)))
  #else
  	if (image)
  		f = fopen(path, RBMODE);
***************
*** 234,240
  	if (!(f = fopen(path, "rb")))
  #else
  	if (image)
! 		f = fopen(path, "rb");
  	else
  		f = fopen(path, "r");
  	if (!f)

--- 234,240 -----
  	if (!(f = fopen(path, RBMODE)))
  #else
  	if (image)
! 		f = fopen(path, RBMODE);
  	else
  		f = fopen(path, RMODE);
  	if (!f)
***************
*** 236,242
  	if (image)
  		f = fopen(path, "rb");
  	else
! 		f = fopen(path, "r");
  	if (!f)
  #endif
  	{

--- 236,242 -----
  	if (image)
  		f = fopen(path, RBMODE);
  	else
! 		f = fopen(path, RMODE);
  	if (!f)
  #endif
  	{
*** arccvt.c~	Mon Jul 18 09:54:35 1988
--- arccvt.c	Mon Jul 18 09:54:51 1988
***************
*** 95,101
  	long            starts, ftell();	/* where the file goes */
  	FILE           *tmp, *fopen();	/* temporary file */
  
! 	if (!(tmp = fopen(tempname, "w+b")))
  		abort("Unable to create temporary file %s", tempname);
  
  	if (note) {

--- 95,101 -----
  	long            starts, ftell();	/* where the file goes */
  	FILE           *tmp, *fopen();	/* temporary file */
  
! 	if (!(tmp = fopen(tempname, UBMODE)))
  		abort("Unable to create temporary file %s", tempname);
  
  	if (note) {
*** arcdos.c~	Mon Jul 18 09:59:28 1988
--- arcdos.c	Mon Jul 18 09:55:04 1988
***************
*** 155,161
  		int             ax, bx, cx, dx, si, di, ds, es;
  	}               reg;
  
! 	ff = fopen(f, "w+");	/* How else can I get a handle? */
  
  	reg.ax = 0x5701;	/* set date/time */
  	reg.bx = filehand(f);	/* file handle */

--- 155,161 -----
  		int             ax, bx, cx, dx, si, di, ds, es;
  	}               reg;
  
! 	ff = fopen(f, UMODE);	/* How else can I get a handle? */
  
  	reg.ax = 0x5701;	/* set date/time */
  	reg.bx = filehand(f);	/* file handle */
*** arcext.c~	Mon Jul 18 09:55:15 1988
--- arcext.c	Mon Jul 18 09:55:46 1988
***************
*** 135,141
  		printf("Extracting file: %s\n", fix);
  
  	if (warn && !overlay) {
! 		if (f = fopen(fix, "r")) {	/* see if it exists */
  				fclose(f);
  				printf("WARNING: File %s already exists!", fix);
  				fflush(stdout);

--- 135,141 -----
  		printf("Extracting file: %s\n", fix);
  
  	if (warn && !overlay) {
! 		if (f = fopen(fix, RMODE)) {	/* see if it exists */
  				fclose(f);
  				printf("WARNING: File %s already exists!", fix);
  				fflush(stdout);
***************
*** 155,161
  		}
  	}
  #if	!MTS
! 	if (!(f = fopen(fix, "wb")))
  #else
  	{
  		fortran         create();

--- 155,161 -----
  		}
  	}
  #if	!MTS
! 	if (!(f = fopen(fix, WBMODE)))
  #else
  	{
  		fortran         create();
***************
*** 175,181
  		create(c_name, &c_size, c_vol, &c_type);
  	}
  	if (image) {
! 		f = fopen(fix, "wb");
  	} else
  		f = fopen(fix, "w");
  	if (!f)

--- 175,181 -----
  		create(c_name, &c_size, c_vol, &c_type);
  	}
  	if (image) {
! 		f = fopen(fix, WBMODE);
  	} else
  		f = fopen(fix, WMODE);
  	if (!f)
***************
*** 177,183
  	if (image) {
  		f = fopen(fix, "wb");
  	} else
! 		f = fopen(fix, "w");
  	if (!f)
  #endif
  	{

--- 177,183 -----
  	if (image) {
  		f = fopen(fix, WBMODE);
  	} else
! 		f = fopen(fix, WMODE);
  	if (!f)
  #endif
  	{
*** arcmisc.c~	Mon Jul 18 09:55:56 1988
--- arcmisc.c	Mon Jul 18 09:56:22 1988
***************
*** 84,90
  	{
  		if (stat(oldnam, &oldstat))	/* different partition? */
  			return (-1);
! 		old = fopen(oldnam, "rb");
  		if (old == NULL)
  			return (-1);
  		new = fopen(newnam, "wb");

--- 84,90 -----
  	{
  		if (stat(oldnam, &oldstat))	/* different partition? */
  			return (-1);
! 		old = fopen(oldnam, RBMODE);
  		if (old == NULL)
  			return (-1);
  		new = fopen(newnam, WBMODE);
***************
*** 87,93
  		old = fopen(oldnam, "rb");
  		if (old == NULL)
  			return (-1);
! 		new = fopen(newnam, "wb");
  		if (new == NULL)
  			return (-1);
  		filecopy(old, new, oldstat.st_size);

--- 87,93 -----
  		old = fopen(oldnam, RBMODE);
  		if (old == NULL)
  			return (-1);
! 		new = fopen(newnam, WBMODE);
  		if (new == NULL)
  			return (-1);
  		filecopy(old, new, oldstat.st_size);
*** arcrun.c~	Mon Jul 18 09:56:31 1988
--- arcrun.c	Mon Jul 18 09:56:57 1988
***************
*** 118,124
  #endif
  
  	if (warn)
! 		if (tmp = fopen(buf, "r"))
  			abort("Temporary file %s already exists", buf);
  	if (!(tmp = fopen(buf, "wb")))
  		abort("Unable to create temporary file %s", buf);

--- 118,124 -----
  #endif
  
  	if (warn)
! 		if (tmp = fopen(buf, RMODE))
  			abort("Temporary file %s already exists", buf);
  	if (!(tmp = fopen(buf, WBMODE)))
  		abort("Unable to create temporary file %s", buf);
***************
*** 120,126
  	if (warn)
  		if (tmp = fopen(buf, "r"))
  			abort("Temporary file %s already exists", buf);
! 	if (!(tmp = fopen(buf, "wb")))
  		abort("Unable to create temporary file %s", buf);
  
  	if (note)

--- 120,126 -----
  	if (warn)
  		if (tmp = fopen(buf, RMODE))
  			abort("Temporary file %s already exists", buf);
! 	if (!(tmp = fopen(buf, WBMODE)))
  		abort("Unable to create temporary file %s", buf);
  
  	if (note)
*** arcsvc.c~	Mon Jul 18 09:57:04 1988
--- arcsvc.c	Mon Jul 18 09:57:26 1988
***************
*** 31,37
  {
  	FILE           *fopen();/* file opener */
  
! 	if (!(arc = fopen(arcname, "rb"))) {
  		if (chg) {
  			if (note)
  				printf("Creating new archive: %s\n", arcname);

--- 31,37 -----
  {
  	FILE           *fopen();/* file opener */
  
! 	if (!(arc = fopen(arcname, RBMODE))) {
  		if (chg) {
  			if (note)
  				printf("Creating new archive: %s\n", arcname);
***************
*** 53,59
  	}
  #endif
  	if (chg) {		/* if opening for changes */
! 		if (!(new = fopen(newname, "wb")))
  			abort("Cannot create archive copy: %s", newname);
  
  	changing = chg;		/* note if open for changes */

--- 53,59 -----
  	}
  #endif
  	if (chg) {		/* if opening for changes */
! 		if (!(new = fopen(newname, WBMODE)))
  			abort("Cannot create archive copy: %s", newname);
  
  	changing = chg;		/* note if open for changes */
*** marc.c~	Mon Jul 18 09:57:34 1988
--- marc.c	Mon Jul 18 09:58:04 1988
***************
*** 118,125
      upper(arcname); upper(srcname); upper(newname);
  #endif
  
!     arc = fopen(arcname,"rb");	       /* open the archives */
!     if(!(src=fopen(srcname,"rb")))
  	 abort("Cannot read source archive %s",srcname);
      if(!(new=fopen(newname,"wb")))
  	 abort("Cannot create new archive %s",newname);

--- 118,125 -----
      upper(arcname); upper(srcname); upper(newname);
  #endif
  
!     arc = fopen(arcname,RBMODE);	       /* open the archives */
!     if(!(src=fopen(srcname,RBMODE)))
  	 abort("Cannot read source archive %s",srcname);
      if(!(new=fopen(newname,WBMODE)))
  	 abort("Cannot create new archive %s",newname);
***************
*** 121,127
      arc = fopen(arcname,"rb");	       /* open the archives */
      if(!(src=fopen(srcname,"rb")))
  	 abort("Cannot read source archive %s",srcname);
!     if(!(new=fopen(newname,"wb")))
  	 abort("Cannot create new archive %s",newname);
  
      if(!arc)

--- 121,127 -----
      arc = fopen(arcname,RBMODE);	       /* open the archives */
      if(!(src=fopen(srcname,RBMODE)))
  	 abort("Cannot read source archive %s",srcname);
!     if(!(new=fopen(newname,WBMODE)))
  	 abort("Cannot create new archive %s",newname);
  
      if(!arc)
***************
*** 277,283
      if(*p)			       /* use name if one was given */
      {	 makefnam(p,".CMD",buf);
  	 upper(buf);
! 	 if(!(lf=fopen(buf,"r")))
  	      abort("Cannot read list of files in %s",buf);
      }
      else lf = stdin;		       /* else use standard input */

--- 277,283 -----
      if(*p)			       /* use name if one was given */
      {	 makefnam(p,".CMD",buf);
  	 upper(buf);
! 	 if(!(lf=fopen(buf,RMODE)))
  	      abort("Cannot read list of files in %s",buf);
      }
      else lf = stdin;		       /* else use standard input */