From: syd@dsinc.DSI.COM (Syd Weinstein)
Subject: elm 2.4 Patch #2
Followup-To: poster
Summary: This is an official patch for elm 2.4 system.  Please apply it.
Priority: HIGH
Organization: Datacomp Systems, Inc., Huntingdon Valley, PA 19006
Date: Tue, 13 Oct 1992 14:22:42 GMT

Part 2 of a 2 part Patch - 'Easy' Mods following release problems.

Fix:	From rn, say "| patch -p -N -d DIR", where DIR is your elm source
	directory.  Outside of rn, say "cd DIR; patch -p -N <thisarticle".
	If you don't have the patch program, apply the following by hand,
	or get patch (version 2.0, latest patchlevel).

	After patching:
		sh Configure -d
		make
		make install

	If patch indicates that patchlevel is the wrong version, you may need
	to apply one or more previous patches, or the patch may already
	have been applied.  See the patchlevel.h file to find out what has or
	has not been applied.  In any event, don't continue with the patch.

	If you are missing previous patches they can be obtained from our:
	archive server.

	Syd Weinstein
	elm@DSI.COM

	The patches are available from the dsinc archive server
	Send the following message to archive-server@DSI.COM for
	a list of available patches:

	Subject: patch list
	send index elm

Index: hdrs/patchlevel.h
Prereq: 1
*** ../elm2.4/hdrs/patchlevel.h	Sat Oct  3 18:31:30 1992
--- hdrs/patchlevel.h	Sat Oct 10 22:07:22 1992
***************
*** 1 ****
! #define PATCHLEVEL 1
--- 1 ----
! #define PATCHLEVEL 2

Index: lib/ndbz.c
Prereq: 5.1
*** ../elm2.4/lib/ndbz.c	Sat Oct  3 18:42:27 1992
--- lib/ndbz.c	Sat Oct 10 21:47:11 1992
***************
*** 1,7 ****
! static char rcsid[] = "@(#)$Id: ndbz.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,7 ----
! static char rcsid[] = "@(#)$Id: ndbz.c,v 5.2 1992/10/11 01:46:35 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 13,18 ****
--- 13,23 ----
   *
   *******************************************************************************
   * $Log: ndbz.c,v $
+  * Revision 5.2  1992/10/11  01:46:35  syd
+  * change dbm name to dbz to avoid conflicts with partial call
+  * ins from shared librarys, and from mixing code with yp code.
+  * From: Syd via prompt from Jess Anderson
+  *
   * Revision 5.1  1992/10/03  22:41:36  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 148,158 ****
   * them completely (by defining the masks to 0).  We build pre-shifted
   * versions of the masks for efficiency.
   */
! #define	HASTAG(o)	((o)&db->dbm_taghere)
! #define	TAG(o)		((o)&db->dbm_tagbits)
! #define	NOTAG(o)	((o)&~db->dbm_tagboth)
! #define	CANTAG(o)	(((o)&db->dbm_tagboth) == 0)
! #define	MKTAG(v)	(((v)<<db->dbm_conf.tagshift)&db->dbm_tagbits)
  
  /*
   * A new, from-scratch database, not built as a rebuild of an old one,
--- 153,163 ----
   * them completely (by defining the masks to 0).  We build pre-shifted
   * versions of the masks for efficiency.
   */
! #define	HASTAG(o)	((o)&db->dbz_taghere)
! #define	TAG(o)		((o)&db->dbz_tagbits)
! #define	NOTAG(o)	((o)&~db->dbz_tagboth)
! #define	CANTAG(o)	(((o)&db->dbz_tagboth) == 0)
! #define	MKTAG(v)	(((v)<<db->dbz_conf.tagshift)&db->dbz_tagbits)
  
  /*
   * A new, from-scratch database, not built as a rebuild of an old one,
***************
*** 182,195 ****
   * For a program that makes many, many references to the database, it
   * is a large performance win to keep the table in core, if it will fit.
   * Note that this does hurt robustness in the event of crashes, and
!  * dbm_close() *must* be called to flush the in-core database to disk.
   * The code is prepared to deal with the possibility that there isn't
   * enough memory.  There *is* an assumption that a size_t is big enough
!  * to hold the size (in bytes) of one table, so dbm_open() tries to figure
   * out whether this is possible first.
   *
   * The preferred way to ask for an in-core table is to do dbzincore(1)
!  * before dbm_open().  The default is not to do it, although -DINCORE
   * overrides this for backward compatibility with old dbz.
   *
   * We keep only the first table in core.  This greatly simplifies the
--- 187,200 ----
   * For a program that makes many, many references to the database, it
   * is a large performance win to keep the table in core, if it will fit.
   * Note that this does hurt robustness in the event of crashes, and
!  * dbz_close() *must* be called to flush the in-core database to disk.
   * The code is prepared to deal with the possibility that there isn't
   * enough memory.  There *is* an assumption that a size_t is big enough
!  * to hold the size (in bytes) of one table, so dbz_open() tries to figure
   * out whether this is possible first.
   *
   * The preferred way to ask for an in-core table is to do dbzincore(1)
!  * before dbz_open().  The default is not to do it, although -DINCORE
   * overrides this for backward compatibility with old dbz.
   *
   * We keep only the first table in core.  This greatly simplifies the
***************
*** 214,228 ****
  
  /*
   * Arguably the searcher struct for a given routine ought to be local to
!  * it, but a dbm_fetch() is very often immediately followed by a dbm_store(), and
   * in some circumstances it is a useful performance win to remember where
!  * the dbm_fetch() completed.  So we use a global struct and remember whether
   * it is current.
   */
  
  /* byte-ordering stuff */
! #define	MAPIN(o)	((db->dbm_bytesame) ? (o) : bytemap((o), db->dbm_conf.bytemap, db->dbm_mybmap))
! #define	MAPOUT(o)	((db->dbm_bytesame) ? (o) : bytemap((o), db->dbm_mybmap, db->dbm_conf.bytemap))
  
  /* externals used */
  extern int atoi();
--- 219,233 ----
  
  /*
   * Arguably the searcher struct for a given routine ought to be local to
!  * it, but a dbz_fetch() is very often immediately followed by a dbz_store(), and
   * in some circumstances it is a useful performance win to remember where
!  * the dbz_fetch() completed.  So we use a global struct and remember whether
   * it is current.
   */
  
  /* byte-ordering stuff */
! #define	MAPIN(o)	((db->dbz_bytesame) ? (o) : bytemap((o), db->dbz_conf.bytemap, db->dbz_mybmap))
! #define	MAPOUT(o)	((db->dbz_bytesame) ? (o) : bytemap((o), db->dbz_mybmap, db->dbz_conf.bytemap))
  
  /* externals used */
  extern int atoi();
***************
*** 246,252 ****
  /*
   - dbz_fresh - set up a new database, no historical info
   */
! DBM *				/* NULL for failure, !NULL for success */
  dbz_fresh(name, size, fs, tagmask)
  char *name;			/* base name; .dir and .pag must exist */
  long size;			/* table size (0 means default) */
--- 251,257 ----
  /*
   - dbz_fresh - set up a new database, no historical info
   */
! DBZ *				/* NULL for failure, !NULL for success */
  dbz_fresh(name, size, fs, tagmask)
  char *name;			/* base name; .dir and .pag must exist */
  long size;			/* table size (0 means default) */
***************
*** 322,329 ****
  	} else
  		(void) fclose(f);
  
! 	/* and punt to dbm_open for the hard work */
! 	return(dbm_open(name, O_RDWR, 0));
  }
  
  /*
--- 327,334 ----
  	} else
  		(void) fclose(f);
  
! 	/* and punt to dbz_open for the hard work */
! 	return(dbz_open(name, O_RDWR, 0));
  }
  
  /*
***************
*** 388,394 ****
  /*
   - dbz_again - set up a new database to be a rebuild of an old one
   */
! DBM *				/* NULL for failure, !NULL for success */
  dbz_again(name, oldname)
  char *name;			/* base name; .dir and .pag must exist */
  char *oldname;			/* base name; all must exist */
--- 393,399 ----
  /*
   - dbz_again - set up a new database to be a rebuild of an old one
   */
! DBZ *				/* NULL for failure, !NULL for success */
  dbz_again(name, oldname)
  char *name;			/* base name; .dir and .pag must exist */
  char *oldname;			/* base name; all must exist */
***************
*** 467,495 ****
  	} else
  		(void) fclose(f);
  
! 	/* and let dbm_open do the work */
! 	return(dbm_open(name, O_RDWR, 0));
  }
  
  /*
!  - dbm_open - open a database, creating it (using defaults) if necessary
   *
   * We try to leave errno set plausibly, to the extent that underlying
!  * functions permit this, since many people consult it if dbm_open() fails.
   */
! DBM *				/* NULL for failure, !NULL for success */
! dbm_open(name, mode, flags)
  char *name;
  int mode, flags;
  {
  	register int i;
  	register size_t s;
! 	register DBM  *db;
  	register char *dirfname;
  	register char *pagfname;
  
! 	if ((db = (DBM *) calloc(sizeof(DBM), 1)) == NULL) {
! 		dprint(5, (debugfile, "dbm_open: no room for DBM structure\n"));
  		return(NULL);
  	}
  	/* open the .dir file */
--- 472,500 ----
  	} else
  		(void) fclose(f);
  
! 	/* and let dbz_open do the work */
! 	return(dbz_open(name, O_RDWR, 0));
  }
  
  /*
!  - dbz_open - open a database, creating it (using defaults) if necessary
   *
   * We try to leave errno set plausibly, to the extent that underlying
!  * functions permit this, since many people consult it if dbz_open() fails.
   */
! DBZ *				/* NULL for failure, !NULL for success */
! dbz_open(name, mode, flags)
  char *name;
  int mode, flags;
  {
  	register int i;
  	register size_t s;
! 	register DBZ  *db;
  	register char *dirfname;
  	register char *pagfname;
  
! 	if ((db = (DBZ *) calloc(sizeof(DBZ), 1)) == NULL) {
! 		dprint(5, (debugfile, "dbz_open: no room for DBZ structure\n"));
  		return(NULL);
  	}
  	/* open the .dir file */
***************
*** 498,510 ****
  		return(NULL);
  
  	if (mode == O_RDONLY) {
! 		db->dbm_dirf = fopen(dirfname, "r");
! 		db->dbm_dirronly = 1;
  	} else
! 		db->dbm_dirf = fopen(dirfname, "r+");
  	free(dirfname);
! 	if (db->dbm_dirf == NULL) {
! 		dprint(5, (debugfile, "dbm_open: can't open .dir file\n"));
  		return(NULL);
  	}
  
--- 503,515 ----
  		return(NULL);
  
  	if (mode == O_RDONLY) {
! 		db->dbz_dirf = fopen(dirfname, "r");
! 		db->dbz_dirronly = 1;
  	} else
! 		db->dbz_dirf = fopen(dirfname, "r+");
  	free(dirfname);
! 	if (db->dbz_dirf == NULL) {
! 		dprint(5, (debugfile, "dbz_open: can't open .dir file\n"));
  		return(NULL);
  	}
  
***************
*** 511,528 ****
  	/* open the .pag file */
  	pagfname = enstring(name, pag);
  	if (pagfname == NULL) {
! 		(void) fclose(db->dbm_dirf);
  		return(NULL);
  	}
  	if (mode == O_RDONLY) {
! 		db->dbm_pagf = fopen(pagfname, "rb");
! 		db->dbm_pagronly = 1;
  	} else
! 		db->dbm_pagf = fopen(pagfname, "r+b");
  
! 	if (db->dbm_pagf == NULL) {
! 		dprint(5, (debugfile, "dbm_open: .pag open failed\n"));
! 		(void) fclose(db->dbm_dirf);
  		free(pagfname);
  		return(NULL);
  	}
--- 516,533 ----
  	/* open the .pag file */
  	pagfname = enstring(name, pag);
  	if (pagfname == NULL) {
! 		(void) fclose(db->dbz_dirf);
  		return(NULL);
  	}
  	if (mode == O_RDONLY) {
! 		db->dbz_pagf = fopen(pagfname, "rb");
! 		db->dbz_pagronly = 1;
  	} else
! 		db->dbz_pagf = fopen(pagfname, "r+b");
  
! 	if (db->dbz_pagf == NULL) {
! 		dprint(5, (debugfile, "dbz_open: .pag open failed\n"));
! 		(void) fclose(db->dbz_dirf);
  		free(pagfname);
  		return(NULL);
  	}
***************
*** 533,603 ****
  	 * case, doing unbuffered i/o does not cure the problem, but does
  	 * enormously reduce its incidence.
  	 */
! 	(void) setbuf(db->dbm_pagf, (char *)NULL);
  #else
  #ifdef _IOFBF
! 	(void) setvbuf(db->dbm_pagf, (char *)db->dbm_pagbuf, _IOFBF, sizeof(db->dbm_pagbuf));
  #endif
  #endif
! 	db->dbm_pagpos = -1;
  	/* don't free pagfname, need it below */
  
  	/* open the base file */
! 	db->dbm_basef = fopen(name, "r");
! 	if (db->dbm_basef == NULL) {
! 		dprint(5, (debugfile, "dbm_open: basefile open failed\n"));
! 		db->dbm_basefname = enstring(name, "");
! 		if (db->dbm_basefname == NULL) {
! 			(void) fclose(db->dbm_pagf);
! 			(void) fclose(db->dbm_dirf);
  			free(pagfname);
  			return(NULL);
  		}
  	} else
! 		db->dbm_basefname = NULL;
  #ifdef _IOFBF
! 	if (db->dbm_basef != NULL)
! 		(void) setvbuf(db->dbm_basef, db->dbm_basebuf, _IOFBF, sizeof(db->dbm_basebuf));
  #endif
  
  	/* pick up configuration */
! 	if (getconf(db->dbm_dirf, db->dbm_pagf, &db->dbm_conf) < 0) {
! 		dprint(5, (debugfile, "dbm_open: getconf failure\n"));
! 		(void) fclose(db->dbm_basef);
! 		(void) fclose(db->dbm_pagf);
! 		(void) fclose(db->dbm_basef);
! 		(void) fclose(db->dbm_dirf);
  		free(pagfname);
  		errno = EDOM;	/* kind of a kludge, but very portable */
  		return(NULL);
  	}
! 	db->dbm_tagbits = db->dbm_conf.tagmask << db->dbm_conf.tagshift;
! 	db->dbm_taghere = db->dbm_conf.tagenb << db->dbm_conf.tagshift;
! 	db->dbm_tagboth = db->dbm_tagbits | db->dbm_taghere;
! 	mybytemap(db->dbm_mybmap);
! 	db->dbm_bytesame = 1;
  	for (i = 0; i < SOF; i++)
! 		if (db->dbm_mybmap[i] != db->dbm_conf.bytemap[i])
! 			db->dbm_bytesame = 0;
  
  	/* get first table into core, if it looks desirable and feasible */
! 	s = (size_t)db->dbm_conf.tsize * SOF;
! 	db->dbm_incore = default_incore;
! 	if (db->dbm_incore && (of_t)(s/SOF) == db->dbm_conf.tsize) {
! 		db->dbm_bufpagf = fopen(pagfname, (db->dbm_pagronly) ? "rb" : "r+b");
! 		if (db->dbm_bufpagf != NULL)
! 			db->dbm_corepag = getcore(db);
  	} else {
! 		db->dbm_bufpagf = NULL;
! 		db->dbm_corepag = NULL;
  	}
  	free(pagfname);
  
  	/* misc. setup */
  	crcinit();
! 	db->dbm_written = 0;
! 	db->dbm_prevp = FRESH;
! 	dprint(5, (debugfile, "dbm_open: succeeded\n"));
  	return(db);
  }
  
--- 538,608 ----
  	 * case, doing unbuffered i/o does not cure the problem, but does
  	 * enormously reduce its incidence.
  	 */
! 	(void) setbuf(db->dbz_pagf, (char *)NULL);
  #else
  #ifdef _IOFBF
! 	(void) setvbuf(db->dbz_pagf, (char *)db->dbz_pagbuf, _IOFBF, sizeof(db->dbz_pagbuf));
  #endif
  #endif
! 	db->dbz_pagpos = -1;
  	/* don't free pagfname, need it below */
  
  	/* open the base file */
! 	db->dbz_basef = fopen(name, "r");
! 	if (db->dbz_basef == NULL) {
! 		dprint(5, (debugfile, "dbz_open: basefile open failed\n"));
! 		db->dbz_basefname = enstring(name, "");
! 		if (db->dbz_basefname == NULL) {
! 			(void) fclose(db->dbz_pagf);
! 			(void) fclose(db->dbz_dirf);
  			free(pagfname);
  			return(NULL);
  		}
  	} else
! 		db->dbz_basefname = NULL;
  #ifdef _IOFBF
! 	if (db->dbz_basef != NULL)
! 		(void) setvbuf(db->dbz_basef, db->dbz_basebuf, _IOFBF, sizeof(db->dbz_basebuf));
  #endif
  
  	/* pick up configuration */
! 	if (getconf(db->dbz_dirf, db->dbz_pagf, &db->dbz_conf) < 0) {
! 		dprint(5, (debugfile, "dbz_open: getconf failure\n"));
! 		(void) fclose(db->dbz_basef);
! 		(void) fclose(db->dbz_pagf);
! 		(void) fclose(db->dbz_basef);
! 		(void) fclose(db->dbz_dirf);
  		free(pagfname);
  		errno = EDOM;	/* kind of a kludge, but very portable */
  		return(NULL);
  	}
! 	db->dbz_tagbits = db->dbz_conf.tagmask << db->dbz_conf.tagshift;
! 	db->dbz_taghere = db->dbz_conf.tagenb << db->dbz_conf.tagshift;
! 	db->dbz_tagboth = db->dbz_tagbits | db->dbz_taghere;
! 	mybytemap(db->dbz_mybmap);
! 	db->dbz_bytesame = 1;
  	for (i = 0; i < SOF; i++)
! 		if (db->dbz_mybmap[i] != db->dbz_conf.bytemap[i])
! 			db->dbz_bytesame = 0;
  
  	/* get first table into core, if it looks desirable and feasible */
! 	s = (size_t)db->dbz_conf.tsize * SOF;
! 	db->dbz_incore = default_incore;
! 	if (db->dbz_incore && (of_t)(s/SOF) == db->dbz_conf.tsize) {
! 		db->dbz_bufpagf = fopen(pagfname, (db->dbz_pagronly) ? "rb" : "r+b");
! 		if (db->dbz_bufpagf != NULL)
! 			db->dbz_corepag = getcore(db);
  	} else {
! 		db->dbz_bufpagf = NULL;
! 		db->dbz_corepag = NULL;
  	}
  	free(pagfname);
  
  	/* misc. setup */
  	crcinit();
! 	db->dbz_written = 0;
! 	db->dbz_prevp = FRESH;
! 	dprint(5, (debugfile, "dbz_open: succeeded\n"));
  	return(db);
  }
  
***************
*** 622,669 ****
  }
  
  /*
!  - dbm_close - close a database
   */
  int
! dbm_close(db)
! register DBM *db;
  {
  	register int ret = 0;
  
! 	if (db->dbm_pagf == NULL) {
! 		dprint(5, (debugfile, "dbm_close: not opened!\n"));
  		return(-1);
  	}
  
! 	if (fclose(db->dbm_pagf) == EOF) {
! 		dprint(5, (debugfile, "dbm_close: fclose(pagf) failed\n"));
  		ret = -1;
  	}
  	if (dbz_sync(db) < 0)
  		ret = -1;
! 	if (db->dbm_bufpagf != NULL && fclose(db->dbm_bufpagf) == EOF) {
! 		dprint(5, (debugfile, "dbm_close: fclose(bufpagf) failed\n"));
  		ret = -1;
  	}
! 	if (db->dbm_corepag != NULL)
! 		free((char *)db->dbm_corepag);
! 	db->dbm_corepag = NULL;
! 	if (fclose(db->dbm_basef) == EOF) {
! 		dprint(5, (debugfile, "dbm_close: fclose(basef) failed\n"));
  		ret = -1;
  	}
! 	if (db->dbm_basefname != NULL)
! 		free(db->dbm_basefname);
! 	db->dbm_basef = NULL;
! 	db->dbm_pagf = NULL;
! 	if (fclose(db->dbm_dirf) == EOF) {
! 		dprint(5, (debugfile, "dbm_close: fclose(dirf) failed\n"));
  		ret = -1;
  	}
  
  	free((char *) db);
  
! 	dprint(5, (debugfile, "dbm_close: %s\n", (ret == 0) ? "succeeded" : "failed"));
  	return(ret);
  }
  
--- 627,674 ----
  }
  
  /*
!  - dbz_close - close a database
   */
  int
! dbz_close(db)
! register DBZ *db;
  {
  	register int ret = 0;
  
! 	if (db->dbz_pagf == NULL) {
! 		dprint(5, (debugfile, "dbz_close: not opened!\n"));
  		return(-1);
  	}
  
! 	if (fclose(db->dbz_pagf) == EOF) {
! 		dprint(5, (debugfile, "dbz_close: fclose(pagf) failed\n"));
  		ret = -1;
  	}
  	if (dbz_sync(db) < 0)
  		ret = -1;
! 	if (db->dbz_bufpagf != NULL && fclose(db->dbz_bufpagf) == EOF) {
! 		dprint(5, (debugfile, "dbz_close: fclose(bufpagf) failed\n"));
  		ret = -1;
  	}
! 	if (db->dbz_corepag != NULL)
! 		free((char *)db->dbz_corepag);
! 	db->dbz_corepag = NULL;
! 	if (fclose(db->dbz_basef) == EOF) {
! 		dprint(5, (debugfile, "dbz_close: fclose(basef) failed\n"));
  		ret = -1;
  	}
! 	if (db->dbz_basefname != NULL)
! 		free(db->dbz_basefname);
! 	db->dbz_basef = NULL;
! 	db->dbz_pagf = NULL;
! 	if (fclose(db->dbz_dirf) == EOF) {
! 		dprint(5, (debugfile, "dbz_close: fclose(dirf) failed\n"));
  		ret = -1;
  	}
  
  	free((char *) db);
  
! 	dprint(5, (debugfile, "dbz_close: %s\n", (ret == 0) ? "succeeded" : "failed"));
  	return(ret);
  }
  
***************
*** 672,696 ****
   */
  int
  dbz_sync(db)
! register DBM *db;
  {
  	register int ret = 0;
  
! 	if (db->dbm_pagf == NULL) {
  		dprint(5, (debugfile, "dbzsync: not opened!\n"));
  		return(-1);
  	}
! 	if (!db->dbm_written)
  		return(0);
  
! 	if (db->dbm_corepag != NULL) {
  		if (putcore(db) < 0) {
  			dprint(5, (debugfile, "dbzsync: putcore failed\n"));
  			ret = -1;
  		}
  	}
! 	if (!db->dbm_conf.olddbz)
! 		if (putconf(db->dbm_dirf, &db->dbm_conf) < 0)
  			ret = -1;
  
  	dprint(5, (debugfile, "dbzsync: %s\n", (ret == 0) ? "succeeded" : "failed"));
--- 677,701 ----
   */
  int
  dbz_sync(db)
! register DBZ *db;
  {
  	register int ret = 0;
  
! 	if (db->dbz_pagf == NULL) {
  		dprint(5, (debugfile, "dbzsync: not opened!\n"));
  		return(-1);
  	}
! 	if (!db->dbz_written)
  		return(0);
  
! 	if (db->dbz_corepag != NULL) {
  		if (putcore(db) < 0) {
  			dprint(5, (debugfile, "dbzsync: putcore failed\n"));
  			ret = -1;
  		}
  	}
! 	if (!db->dbz_conf.olddbz)
! 		if (putconf(db->dbz_dirf, &db->dbz_conf) < 0)
  			ret = -1;
  
  	dprint(5, (debugfile, "dbzsync: %s\n", (ret == 0) ? "succeeded" : "failed"));
***************
*** 705,723 ****
   */
  int
  dbz_cancel(db)
! register DBM *db;
  {
! 	if (db->dbm_pagf == NULL) {
  		dprint(5, (debugfile, "dbz_cancel: not opened!\n"));
  		return(-1);
  	}
  
! 	db->dbm_written = 0;
  	return(0);
  }
  
  /*
!  - dbm_fetch - get an entry from the database
   *
   * Disgusting fine point, in the name of backward compatibility:  if the
   * last character of "key" is a NUL, that character is (effectively) not
--- 710,728 ----
   */
  int
  dbz_cancel(db)
! register DBZ *db;
  {
! 	if (db->dbz_pagf == NULL) {
  		dprint(5, (debugfile, "dbz_cancel: not opened!\n"));
  		return(-1);
  	}
  
! 	db->dbz_written = 0;
  	return(0);
  }
  
  /*
!  - dbz_fetch - get an entry from the database
   *
   * Disgusting fine point, in the name of backward compatibility:  if the
   * last character of "key" is a NUL, that character is (effectively) not
***************
*** 724,731 ****
   * part of the comparison against the stored keys.
   */
  datum				/* dptr NULL, dsize 0 means failure */
! dbm_fetch(db, key)
! register DBM *db;
  datum key;
  {
  	char buffer[DBZMAXKEY + 1];
--- 729,736 ----
   * part of the comparison against the stored keys.
   */
  datum				/* dptr NULL, dsize 0 means failure */
! dbz_fetch(db, key)
! register DBZ *db;
  datum key;
  {
  	char buffer[DBZMAXKEY + 1];
***************
*** 735,744 ****
  	register size_t cmplen;
  	register char *sepp;
  
! 	dprint(5, (debugfile, "dbm_fetch: (%s)\n", key.dptr));
  	output.dptr = NULL;
  	output.dsize = 0;
! 	db->dbm_prevp = FRESH;
  
  	/* Key is supposed to be less than DBZMAXKEY */
  	keysize = key.dsize;
--- 740,749 ----
  	register size_t cmplen;
  	register char *sepp;
  
! 	dprint(5, (debugfile, "dbz_fetch: (%s)\n", key.dptr));
  	output.dptr = NULL;
  	output.dsize = 0;
! 	db->dbz_prevp = FRESH;
  
  	/* Key is supposed to be less than DBZMAXKEY */
  	keysize = key.dsize;
***************
*** 747,763 ****
  		dprint(5, (debugfile, "keysize is %d - truncated to %d\n", key.dsize, DBZMAXKEY));
  	}
  
! 	if (db->dbm_pagf == NULL) {
! 		dprint(5, (debugfile, "dbm_fetch: database not open!\n"));
  		return(output);
! 	} else if (db->dbm_basef == NULL) {	/* basef didn't exist yet */
! 		db->dbm_basef = latebase(db);
! 		if (db->dbm_basef == NULL)
  			return(output);
  	}
  
  	cmplen = keysize;
! 	sepp = &db->dbm_conf.fieldsep;
  	if (key.dptr[keysize-1] == '\0') {
  		cmplen--;
  		sepp = &buffer[keysize-1];
--- 752,768 ----
  		dprint(5, (debugfile, "keysize is %d - truncated to %d\n", key.dsize, DBZMAXKEY));
  	}
  
! 	if (db->dbz_pagf == NULL) {
! 		dprint(5, (debugfile, "dbz_fetch: database not open!\n"));
  		return(output);
! 	} else if (db->dbz_basef == NULL) {	/* basef didn't exist yet */
! 		db->dbz_basef = latebase(db);
! 		if (db->dbz_basef == NULL)
  			return(output);
  	}
  
  	cmplen = keysize;
! 	sepp = &db->dbz_conf.fieldsep;
  	if (key.dptr[keysize-1] == '\0') {
  		cmplen--;
  		sepp = &buffer[keysize-1];
***************
*** 767,798 ****
  		dprint(5, (debugfile, "got 0x%lx\n", key_ptr));
  
  		/* fetch the key */
! 		if (fseek(db->dbm_basef, key_ptr, SEEK_SET) != 0) {
! 			dprint(5, (debugfile, "dbm_fetch: seek failed\n"));
  			return(output);
  		}
! 		if (fread(buffer, 1, keysize, db->dbm_basef) != keysize) {
! 			dprint(5, (debugfile, "dbm_fetch: read failed\n"));
  			return(output);
  		}
  
  		/* try it */
  		buffer[keysize] = '\0';		/* terminated for DEBUG */
! 		dprint(5, (debugfile, "dbm_fetch: buffer (%s) looking for (%s) size = %d\n", 
  						buffer, key.dptr, keysize));
  		if (bcmp(key.dptr, buffer, cmplen) == 0 &&
! 				(*sepp == db->dbm_conf.fieldsep || *sepp == '\0')) {
  			/* we found it */
  			output.dptr = (char *)&key_ptr;
  			output.dsize = SOF;
! 			dprint(5, (debugfile, "dbm_fetch: successful\n"));
  			return(output);
  		}
  	}
  
  	/* we didn't find it */
! 	dprint(5, (debugfile, "dbm_fetch: failed\n"));
! 	db->dbm_prevp = &db->dbm_srch;			/* remember where we stopped */
  	return(output);
  }
  
--- 772,803 ----
  		dprint(5, (debugfile, "got 0x%lx\n", key_ptr));
  
  		/* fetch the key */
! 		if (fseek(db->dbz_basef, key_ptr, SEEK_SET) != 0) {
! 			dprint(5, (debugfile, "dbz_fetch: seek failed\n"));
  			return(output);
  		}
! 		if (fread(buffer, 1, keysize, db->dbz_basef) != keysize) {
! 			dprint(5, (debugfile, "dbz_fetch: read failed\n"));
  			return(output);
  		}
  
  		/* try it */
  		buffer[keysize] = '\0';		/* terminated for DEBUG */
! 		dprint(5, (debugfile, "dbz_fetch: buffer (%s) looking for (%s) size = %d\n", 
  						buffer, key.dptr, keysize));
  		if (bcmp(key.dptr, buffer, cmplen) == 0 &&
! 				(*sepp == db->dbz_conf.fieldsep || *sepp == '\0')) {
  			/* we found it */
  			output.dptr = (char *)&key_ptr;
  			output.dsize = SOF;
! 			dprint(5, (debugfile, "dbz_fetch: successful\n"));
  			return(output);
  		}
  	}
  
  	/* we didn't find it */
! 	dprint(5, (debugfile, "dbz_fetch: failed\n"));
! 	db->dbz_prevp = &db->dbz_srch;			/* remember where we stopped */
  	return(output);
  }
  
***************
*** 801,823 ****
   */
  static FILE *
  latebase(db)
! register DBM *db;
  {
  	register FILE *it;
  
! 	if (db->dbm_basefname == NULL) {
  		dprint(5, (debugfile, "latebase: name foulup\n"));
  		return(NULL);
  	}
! 	it = fopen(db->dbm_basefname, "r");
  	if (it == NULL) {
  		dprint(5, (debugfile, "latebase: still can't open base\n"));
  	} else {
  		dprint(5, (debugfile, "latebase: late open succeeded\n"));
! 		free(db->dbm_basefname);
! 		db->dbm_basefname = NULL;
  #ifdef _IOFBF
! 		(void) setvbuf(it, db->dbm_basebuf, _IOFBF, sizeof(db->dbm_basebuf));
  #endif
  	}
  	return(it);
--- 806,828 ----
   */
  static FILE *
  latebase(db)
! register DBZ *db;
  {
  	register FILE *it;
  
! 	if (db->dbz_basefname == NULL) {
  		dprint(5, (debugfile, "latebase: name foulup\n"));
  		return(NULL);
  	}
! 	it = fopen(db->dbz_basefname, "r");
  	if (it == NULL) {
  		dprint(5, (debugfile, "latebase: still can't open base\n"));
  	} else {
  		dprint(5, (debugfile, "latebase: late open succeeded\n"));
! 		free(db->dbz_basefname);
! 		db->dbz_basefname = NULL;
  #ifdef _IOFBF
! 		(void) setvbuf(it, db->dbz_basebuf, _IOFBF, sizeof(db->dbz_basebuf));
  #endif
  	}
  	return(it);
***************
*** 824,877 ****
  }
  
  /*
!  - dbm_store - add an entry to the database
   */
  int				/* 0 success, -1 failure */
! dbm_store(db, key, data)
! register DBM *db;
  datum key;
  datum data;
  {
  	of_t value;
  
! 	if (db->dbm_pagf == NULL) {
! 		dprint(5, (debugfile, "dbm_store: database not open!\n"));
  		return(-1);
! 	} else if (db->dbm_basef == NULL) {	/* basef didn't exist yet */
! 		db->dbm_basef = latebase(db);
! 		if (db->dbm_basef == NULL)
  			return(-1);
  	}
! 	if (db->dbm_pagronly) {
! 		dprint(5, (debugfile, "dbm_store: database open read-only\n"));
  		return(-1);
  	}
  	if (data.dsize != SOF) {
! 		dprint(5, (debugfile, "dbm_store: value size wrong (%d)\n", data.dsize));
  		return(-1);
  	}
  	if (key.dsize >= DBZMAXKEY) {
! 		dprint(5, (debugfile, "dbm_store: key size too big (%d)\n", key.dsize));
  		return(-1);
  	}
  
  	/* copy the value in to ensure alignment */
  	(void) bcopy(data.dptr, (char *)&value, SOF);
! 	dprint(5, (debugfile, "dbm_store: (%s, %ld)\n", key.dptr, (long)value));
  	if (!okayvalue(db, value)) {
! 		dprint(5, (debugfile, "dbm_store: reserved bit or overflow in 0x%lx\n", value));
  		return(-1);
  	}
  
  	/* find the place, exploiting previous search if possible */
! 	start(db, &key, db->dbm_prevp);
  	while (search(db) != NOTFOUND)
  		continue;
  
! 	db->dbm_prevp = FRESH;
! 	db->dbm_conf.used[0]++;
! 	dprint(5, (debugfile, "dbm_store: used count %ld\n", db->dbm_conf.used[0]));
! 	db->dbm_written = 1;
  	return(set(db, value));
  }
  
--- 829,882 ----
  }
  
  /*
!  - dbz_store - add an entry to the database
   */
  int				/* 0 success, -1 failure */
! dbz_store(db, key, data)
! register DBZ *db;
  datum key;
  datum data;
  {
  	of_t value;
  
! 	if (db->dbz_pagf == NULL) {
! 		dprint(5, (debugfile, "dbz_store: database not open!\n"));
  		return(-1);
! 	} else if (db->dbz_basef == NULL) {	/* basef didn't exist yet */
! 		db->dbz_basef = latebase(db);
! 		if (db->dbz_basef == NULL)
  			return(-1);
  	}
! 	if (db->dbz_pagronly) {
! 		dprint(5, (debugfile, "dbz_store: database open read-only\n"));
  		return(-1);
  	}
  	if (data.dsize != SOF) {
! 		dprint(5, (debugfile, "dbz_store: value size wrong (%d)\n", data.dsize));
  		return(-1);
  	}
  	if (key.dsize >= DBZMAXKEY) {
! 		dprint(5, (debugfile, "dbz_store: key size too big (%d)\n", key.dsize));
  		return(-1);
  	}
  
  	/* copy the value in to ensure alignment */
  	(void) bcopy(data.dptr, (char *)&value, SOF);
! 	dprint(5, (debugfile, "dbz_store: (%s, %ld)\n", key.dptr, (long)value));
  	if (!okayvalue(db, value)) {
! 		dprint(5, (debugfile, "dbz_store: reserved bit or overflow in 0x%lx\n", value));
  		return(-1);
  	}
  
  	/* find the place, exploiting previous search if possible */
! 	start(db, &key, db->dbz_prevp);
  	while (search(db) != NOTFOUND)
  		continue;
  
! 	db->dbz_prevp = FRESH;
! 	db->dbz_conf.used[0]++;
! 	dprint(5, (debugfile, "dbz_store: used count %ld\n", db->dbz_conf.used[0]));
! 	db->dbz_written = 1;
  	return(set(db, value));
  }
  
***************
*** 1041,1047 ****
   */
  static of_t *			/* pointer to copy, or NULL */
  getcore(db)
! register DBM *db;
  {
  	register of_t *p;
  	register size_t i;
--- 1046,1052 ----
   */
  static of_t *			/* pointer to copy, or NULL */
  getcore(db)
! register DBZ *db;
  {
  	register of_t *p;
  	register size_t i;
***************
*** 1048,1061 ****
  	register size_t nread;
  	register char *it;
  
! 	it = malloc((size_t)db->dbm_conf.tsize * SOF);
  	if (it == NULL) {
  		dprint(5, (debugfile, "getcore: malloc failed\n"));
  		return(NULL);
  	}
  
! 	nread = fread(it, SOF, (size_t)db->dbm_conf.tsize, db->dbm_bufpagf);
! 	if (ferror(db->dbm_bufpagf)) {
  		dprint(5, (debugfile, "getcore: read failed\n"));
  		free(it);
  		return(NULL);
--- 1053,1066 ----
  	register size_t nread;
  	register char *it;
  
! 	it = malloc((size_t)db->dbz_conf.tsize * SOF);
  	if (it == NULL) {
  		dprint(5, (debugfile, "getcore: malloc failed\n"));
  		return(NULL);
  	}
  
! 	nread = fread(it, SOF, (size_t)db->dbz_conf.tsize, db->dbz_bufpagf);
! 	if (ferror(db->dbz_bufpagf)) {
  		dprint(5, (debugfile, "getcore: read failed\n"));
  		free(it);
  		return(NULL);
***************
*** 1062,1068 ****
  	}
  
  	p = (of_t *)it + nread;
! 	i = (size_t)db->dbm_conf.tsize - nread;
  	while (i-- > 0)
  		*p++ = VACANT;
  	return((of_t *)it);
--- 1067,1073 ----
  	}
  
  	p = (of_t *)it + nread;
! 	i = (size_t)db->dbz_conf.tsize - nread;
  	while (i-- > 0)
  		*p++ = VACANT;
  	return((of_t *)it);
***************
*** 1073,1087 ****
   */
  static int			/* 0 okay, -1 fail */
  putcore(db)
! register DBM *db;
  {
! 	if (fseek(db->dbm_bufpagf, (of_t)0, SEEK_SET) != 0) {
  		dprint(5, (debugfile, "fseek failure in putcore\n"));
  		return(-1);
  	}
! 	(void) fwrite((char *)db->dbm_corepag, SOF, (size_t)db->dbm_conf.tsize, db->dbm_bufpagf);
! 	(void) fflush(db->dbm_bufpagf);
! 	return((ferror(db->dbm_bufpagf)) ? -1 : 0);
  }
  
  /*
--- 1078,1092 ----
   */
  static int			/* 0 okay, -1 fail */
  putcore(db)
! register DBZ *db;
  {
! 	if (fseek(db->dbz_bufpagf, (of_t)0, SEEK_SET) != 0) {
  		dprint(5, (debugfile, "fseek failure in putcore\n"));
  		return(-1);
  	}
! 	(void) fwrite((char *)db->dbz_corepag, SOF, (size_t)db->dbz_conf.tsize, db->dbz_bufpagf);
! 	(void) fflush(db->dbz_bufpagf);
! 	return((ferror(db->dbz_bufpagf)) ? -1 : 0);
  }
  
  /*
***************
*** 1089,1099 ****
   */
  static void
  start(db, kp, osp)
! register DBM *db;
  register datum *kp;
  register struct searcher *osp;		/* may be FRESH, i.e. NULL */
  {
! 	register struct searcher *sp = &db->dbm_srch;
  	register long h;
  
  	h = hash(kp->dptr, kp->dsize);
--- 1094,1104 ----
   */
  static void
  start(db, kp, osp)
! register DBZ *db;
  register datum *kp;
  register struct searcher *osp;		/* may be FRESH, i.e. NULL */
  {
! 	register struct searcher *sp = &db->dbz_srch;
  	register long h;
  
  	h = hash(kp->dptr, kp->dsize);
***************
*** 1103,1113 ****
  		dprint(5, (debugfile, "search restarted\n"));
  	} else {
  		sp->hash = h;
! 		sp->tag = MKTAG(h / db->dbm_conf.tsize);
  		dprint(5, (debugfile, "tag 0x%lx\n", sp->tag));
! 		sp->place = h % db->dbm_conf.tsize;
  		sp->tabno = 0;
! 		sp->run = (db->dbm_conf.olddbz) ? db->dbm_conf.tsize : MAXRUN;
  		sp->aborted = 0;
  	}
  	sp->seen = 0;
--- 1108,1118 ----
  		dprint(5, (debugfile, "search restarted\n"));
  	} else {
  		sp->hash = h;
! 		sp->tag = MKTAG(h / db->dbz_conf.tsize);
  		dprint(5, (debugfile, "tag 0x%lx\n", sp->tag));
! 		sp->place = h % db->dbz_conf.tsize;
  		sp->tabno = 0;
! 		sp->run = (db->dbz_conf.olddbz) ? db->dbz_conf.tsize : MAXRUN;
  		sp->aborted = 0;
  	}
  	sp->seen = 0;
***************
*** 1118,1126 ****
   */
  static of_t			/* NOTFOUND if we hit VACANT or error */
  search(db)
! register DBM *db;
  {
! 	register struct searcher *sp = &db->dbm_srch;
  	register of_t dest;
  	register of_t value;
  	of_t val;		/* buffer for value (can't fread register) */
--- 1123,1131 ----
   */
  static of_t			/* NOTFOUND if we hit VACANT or error */
  search(db)
! register DBZ *db;
  {
! 	register struct searcher *sp = &db->dbz_srch;
  	register of_t dest;
  	register of_t value;
  	of_t val;		/* buffer for value (can't fread register) */
***************
*** 1138,1144 ****
  				sp->tabno++;
  				sp->run = MAXRUN;
  			}
! 			place = (place+1)%db->dbm_conf.tsize + sp->tabno*db->dbm_conf.tsize;
  			sp->place = place;
  		} else
  			sp->seen = 1;	/* now looking at current location */
--- 1143,1149 ----
  				sp->tabno++;
  				sp->run = MAXRUN;
  			}
! 			place = (place+1)%db->dbz_conf.tsize + sp->tabno*db->dbz_conf.tsize;
  			sp->place = place;
  		} else
  			sp->seen = 1;	/* now looking at current location */
***************
*** 1145,1172 ****
  		dprint(5, (debugfile, "search @ %ld\n", place));
  
  		/* get the tagged value */
! 		if (db->dbm_corepag != NULL && place < db->dbm_conf.tsize) {
  			dprint(5, (debugfile, "search: in core\n"));
! 			value = MAPIN(db->dbm_corepag[place]);
  		} else {
  			/* seek, if necessary */
  			dest = place * SOF;
! 			if (db->dbm_pagpos != dest) {
! 				if (fseek(db->dbm_pagf, dest, SEEK_SET) != 0) {
  					dprint(5, (debugfile, "search: seek failed\n"));
! 					db->dbm_pagpos = -1;
  					sp->aborted = 1;
  					return(NOTFOUND);
  				}
! 				db->dbm_pagpos = dest;
  			}
  
  			/* read it */
! 			if (fread((char *)&val, sizeof(val), 1, db->dbm_pagf) == 1)
  				value = MAPIN(val);
! 			else if (ferror(db->dbm_pagf)) {
  				dprint(5, (debugfile, "search: read failed\n"));
! 				db->dbm_pagpos = -1;
  				sp->aborted = 1;
  				return(NOTFOUND);
  			} else
--- 1150,1177 ----
  		dprint(5, (debugfile, "search @ %ld\n", place));
  
  		/* get the tagged value */
! 		if (db->dbz_corepag != NULL && place < db->dbz_conf.tsize) {
  			dprint(5, (debugfile, "search: in core\n"));
! 			value = MAPIN(db->dbz_corepag[place]);
  		} else {
  			/* seek, if necessary */
  			dest = place * SOF;
! 			if (db->dbz_pagpos != dest) {
! 				if (fseek(db->dbz_pagf, dest, SEEK_SET) != 0) {
  					dprint(5, (debugfile, "search: seek failed\n"));
! 					db->dbz_pagpos = -1;
  					sp->aborted = 1;
  					return(NOTFOUND);
  				}
! 				db->dbz_pagpos = dest;
  			}
  
  			/* read it */
! 			if (fread((char *)&val, sizeof(val), 1, db->dbz_pagf) == 1)
  				value = MAPIN(val);
! 			else if (ferror(db->dbz_pagf)) {
  				dprint(5, (debugfile, "search: read failed\n"));
! 				db->dbz_pagpos = -1;
  				sp->aborted = 1;
  				return(NOTFOUND);
  			} else
***************
*** 1173,1179 ****
  				value = VACANT;
  
  			/* and finish up */
! 			db->dbm_pagpos += sizeof(val);
  		}
  
  		/* vacant slot is always cause to return */
--- 1178,1184 ----
  				value = VACANT;
  
  			/* and finish up */
! 			db->dbz_pagpos += sizeof(val);
  		}
  
  		/* vacant slot is always cause to return */
***************
*** 1188,1194 ****
  		if (!HASTAG(value)) {
  			dprint(5, (debugfile, "tagless\n"));
  			return(value);
! 		} else if (TAG(value) == sp->tag | db->dbm_taghere) {
  			dprint(5, (debugfile, "match\n"));
  			return(NOTAG(value));
  		} else {
--- 1193,1199 ----
  		if (!HASTAG(value)) {
  			dprint(5, (debugfile, "tagless\n"));
  			return(value);
! 		} else if (TAG(value) == sp->tag | db->dbz_taghere) {
  			dprint(5, (debugfile, "match\n"));
  			return(NOTAG(value));
  		} else {
***************
*** 1203,1209 ****
   */
  static int			/* predicate */
  okayvalue(db, value)
! register DBM *db;
  of_t value;
  {
  	if (HASTAG(value))
--- 1208,1214 ----
   */
  static int			/* predicate */
  okayvalue(db, value)
! register DBZ *db;
  of_t value;
  {
  	if (HASTAG(value))
***************
*** 1220,1229 ****
   */
  static int			/* 0 success, -1 failure */
  set(db, value)
! register DBM *db;
  of_t value;
  {
! 	register struct searcher *sp  = &db->dbm_srch;
  	register of_t place = sp->place;
  	register of_t v = value;
  
--- 1225,1234 ----
   */
  static int			/* 0 success, -1 failure */
  set(db, value)
! register DBZ *db;
  of_t value;
  {
! 	register struct searcher *sp  = &db->dbz_srch;
  	register of_t place = sp->place;
  	register of_t v = value;
  
***************
*** 1230,1237 ****
  	if (sp->aborted)
  		return(-1);
  
! 	if (CANTAG(v) && !db->dbm_conf.olddbz) {
! 		v |= sp->tag | db->dbm_taghere;
  		if (v != UNBIAS(VACANT))	/* BIAS(v) won't look VACANT */
  #ifdef OVERFLOW
  			if (v != LONG_MAX)	/* and it won't overflow */
--- 1235,1242 ----
  	if (sp->aborted)
  		return(-1);
  
! 	if (CANTAG(v) && !db->dbz_conf.olddbz) {
! 		v |= sp->tag | db->dbz_taghere;
  		if (v != UNBIAS(VACANT))	/* BIAS(v) won't look VACANT */
  #ifdef OVERFLOW
  			if (v != LONG_MAX)	/* and it won't overflow */
***************
*** 1243,1257 ****
  	value = MAPOUT(value);
  
  	/* If we have the index file in memory, use it */
! 	if (db->dbm_corepag != NULL && place < db->dbm_conf.tsize) {
! 		db->dbm_corepag[place] = value;
  		dprint(5, (debugfile, "set: incore\n"));
  		return(0);
  	}
  
  	/* seek to spot */
! 	db->dbm_pagpos = -1;		/* invalidate position memory */
! 	if (fseek(db->dbm_pagf, place * SOF, SEEK_SET) != 0) {
  		dprint(5, (debugfile, "set: seek failed\n"));
  		sp->aborted = 1;
  		return(-1);
--- 1248,1262 ----
  	value = MAPOUT(value);
  
  	/* If we have the index file in memory, use it */
! 	if (db->dbz_corepag != NULL && place < db->dbz_conf.tsize) {
! 		db->dbz_corepag[place] = value;
  		dprint(5, (debugfile, "set: incore\n"));
  		return(0);
  	}
  
  	/* seek to spot */
! 	db->dbz_pagpos = -1;		/* invalidate position memory */
! 	if (fseek(db->dbz_pagf, place * SOF, SEEK_SET) != 0) {
  		dprint(5, (debugfile, "set: seek failed\n"));
  		sp->aborted = 1;
  		return(-1);
***************
*** 1258,1270 ****
  	}
  
  	/* write in data */
! 	if (fwrite((char *)&value, SOF, 1, db->dbm_pagf) != 1) {
  		dprint(5, (debugfile, "set: write failed\n"));
  		sp->aborted = 1;
  		return(-1);
  	}
  	/* fflush improves robustness, and buffer re-use is rare anyway */
! 	if (fflush(db->dbm_pagf) == EOF) {
  		dprint(5, (debugfile, "set: fflush failed\n"));
  		sp->aborted = 1;
  		return(-1);
--- 1263,1275 ----
  	}
  
  	/* write in data */
! 	if (fwrite((char *)&value, SOF, 1, db->dbz_pagf) != 1) {
  		dprint(5, (debugfile, "set: write failed\n"));
  		sp->aborted = 1;
  		return(-1);
  	}
  	/* fflush improves robustness, and buffer re-use is rare anyway */
! 	if (fflush(db->dbz_pagf) == EOF) {
  		dprint(5, (debugfile, "set: fflush failed\n"));
  		sp->aborted = 1;
  		return(-1);

Index: src/alias.c
Prereq: 5.1
*** ../elm2.4/src/alias.c	Sat Oct  3 18:58:44 1992
--- src/alias.c	Sat Oct 10 21:47:12 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: alias.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: alias.c,v 5.5 1992/10/11 01:46:35 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.5 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,48 ----
   *
   *******************************************************************************
   * $Log: alias.c,v $
+  * Revision 5.5  1992/10/11  01:46:35  syd
+  * change dbm name to dbz to avoid conflicts with partial call
+  * ins from shared librarys, and from mixing code with yp code.
+  * From: Syd via prompt from Jess Anderson
+  *
+  * Revision 5.4  1992/10/11  01:21:17  syd
+  * 1. If firstname && lastname is null then copy aliasname into the
+  * personal name field (inside the ()'s) when creating an alias
+  * from the menu using the 'n' command.
+  *
+  * 2. Now if for some reason and alias has a null personal name field
+  * (the person hand edited aliases.text) the blank () is not printed
+  * as part of the address.  This actually cured another problem, where
+  * the To: field on the screen (when you hit 'm' on the alias menu)
+  * used to be blank, now the address shows up....
+  * From: "Robert L. Howard" <robert.howard@matd.gatech.edu>
+  *
+  * Revision 5.3  1992/10/11  01:07:52  syd
+  * get_return() assumes that message_count reflects the number of
+  * messages in the current folder, but the message_count it's seeing
+  * from the alias subsystem is actually the *alias* count.
+  * toggle the main state before and after calling get_return().
+  * From: cliff@sfn.ORG (R. Cliff Young)
+  *
+  * Revision 5.2  1992/10/11  00:59:39  syd
+  * Fix some compiler warnings that I receive compiling Elm on my SVR4
+  * machine.
+  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 48,53 ****
--- 77,83 ----
  
  char *get_alias_address(), *fixup_alias_name();
  char *error_description(), *get_parens();
+ void get_realnames();
  
  int  is_system=0;		/* system file updating?     */
  
***************
*** 55,61 ****
  
  int current_mail_message;
  int num_duplicates;
! DBM *system_hash = NULL, *user_hash = NULL;
  char *a_rev_alias_pad, *a_rev_alias_abr, *a_rev_alias_name,
  	*a_rev_full_pad, *a_full_abr, *a_rev_full_name,
  	*a_rev_text_pad, *a_text_abr, *a_rev_text_file,
--- 85,91 ----
  
  int current_mail_message;
  int num_duplicates;
! DBZ *system_hash = NULL, *user_hash = NULL;
  char *a_rev_alias_pad, *a_rev_alias_abr, *a_rev_alias_name,
  	*a_rev_full_pad, *a_full_abr, *a_rev_full_name,
  	*a_rev_text_pad, *a_text_abr, *a_rev_text_file,
***************
*** 159,167 ****
  	/* re-open system hash table.  If we can't, just return. */
  
  	if (system_hash != NULL)
! 	    dbm_close(system_hash);
  
! 	if ((system_hash = dbm_open(system_data_file, O_RDONLY, 0)) == NULL)
  	    return(0);
  
  	/* Remember hash file times. */
--- 189,197 ----
  	/* re-open system hash table.  If we can't, just return. */
  
  	if (system_hash != NULL)
! 	    dbz_close(system_hash);
  
! 	if ((system_hash = dbz_open(system_data_file, O_RDONLY, 0)) == NULL)
  	    return(0);
  
  	/* Remember hash file times. */
***************
*** 198,206 ****
  	/* Open user hash table.  If we can't, just return. */
  
  	if (user_hash != NULL)
! 	    dbm_close(user_hash);
  
! 	if ((user_hash = dbm_open(fname, O_RDONLY, 0)) == NULL)
  	    return(0);
  
  	/* Remember hash file times. */
--- 228,236 ----
  	/* Open user hash table.  If we can't, just return. */
  
  	if (user_hash != NULL)
! 	    dbz_close(user_hash);
  
! 	if ((user_hash = dbz_open(fname, O_RDONLY, 0)) == NULL)
  	    return(0);
  
  	/* Remember hash file times. */
***************
*** 460,466 ****
--- 490,498 ----
  	get_realnames(aliasname, firstname, lastname, comment, buffer);
  
  	/* grab the return address of this message */
+ 	main_state(); /* toggle main state so that message_count is right */
  	get_return(address1, current_mail_message-1);
+ 	main_state(); /* toggle main state back to alias mode */
  	strcpy(address1, strip_parens(address1));	/* remove parens! */
  
  	return(ask_accept(aliasname, firstname, lastname, comment, address1,
***************
*** 648,654 ****
  	}
  
  	if (user_hash != NULL) {
! 	    dbm_close(user_hash);
  	    user_hash = NULL;
  	}
  
--- 680,686 ----
  	}
  
  	if (user_hash != NULL) {
! 	    dbz_close(user_hash);
  	    user_hash = NULL;
  	}
  
***************
*** 1148,1156 ****
  	/* Read from user data file if it is open. */
  	if (user_hash != NULL) {
  	    dprint(6, (debugfile,
! 		      "About to read user data file = %d.\n", user_hash->dbm_basef));
! 	    lseek(user_hash->dbm_basef, 0L, 0);
! 	    while (get_one_alias(user_hash->dbm_basef, current)) {
  		dprint(8, (debugfile, "%d\t%s\t%s\n", current+1,
  				       aliases[current]->alias,
  				       aliases[current]->address));
--- 1180,1188 ----
  	/* Read from user data file if it is open. */
  	if (user_hash != NULL) {
  	    dprint(6, (debugfile,
! 		      "About to read user data file = %d.\n", user_hash->dbz_basef));
! 	    lseek(user_hash->dbz_basef, 0L, 0);
! 	    while (get_one_alias(user_hash->dbz_basef, current)) {
  		dprint(8, (debugfile, "%d\t%s\t%s\n", current+1,
  				       aliases[current]->alias,
  				       aliases[current]->address));
***************
*** 1163,1171 ****
  	/* Read from system data file if it is open. */
  	if (system_hash != NULL) {
  	    dprint(6, (debugfile,
! 		      "About to read system data file = %d.\n", system_hash->dbm_basef));
! 	    fseek(system_hash->dbm_basef, 0L, 0);
! 	    while (get_one_alias(system_hash->dbm_basef, current)) {
  		/* If an identical user alias is found, we may
  		 * not want to display it, so we had better mark it.
  		 */
--- 1195,1203 ----
  	/* Read from system data file if it is open. */
  	if (system_hash != NULL) {
  	    dprint(6, (debugfile,
! 		      "About to read system data file = %d.\n", system_hash->dbz_basef));
! 	    fseek(system_hash->dbz_basef, 0L, 0);
! 	    while (get_one_alias(system_hash->dbz_basef, current)) {
  		/* If an identical user alias is found, we may
  		 * not want to display it, so we had better mark it.
  		 */
***************
*** 1411,1417 ****
  
  }
  
! int
  get_realnames(aliasname, firstname, lastname, comment, buffer)
  char *aliasname, *firstname, *lastname, *comment, *buffer;
  {
--- 1443,1449 ----
  
  }
  
! void
  get_realnames(aliasname, firstname, lastname, comment, buffer)
  char *aliasname, *firstname, *lastname, *comment, *buffer;
  {
***************
*** 1421,1427 ****
  	PutLine0(LINES-2,0, buffer);
  	CleartoEOLN();
  	optionally_enter(lastname, LINES-2, strlen(buffer), FALSE, FALSE);
- 	if (strlen(lastname) == 0) strcpy(lastname, aliasname);  
  
  	sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesEnterFirstName,
  		"Enter first name for %s: "), aliasname);
--- 1453,1458 ----
***************
*** 1428,1433 ****
--- 1459,1468 ----
  	PutLine0(LINES-2,0, buffer);
  	CleartoEOLN();
  	optionally_enter(firstname, LINES-2, strlen(buffer), FALSE, FALSE);
+ 
+ 	if ((strlen(lastname) == 0) && (strlen(firstname) == 0)) {
+ 	    strcpy(lastname, aliasname);  
+ 	}
  
  	sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesEnterComment,
  		"Enter optional comment for %s: "), aliasname);

Index: src/aliaslib.c
Prereq: 5.1
*** ../elm2.4/src/aliaslib.c	Sat Oct  3 18:58:45 1992
--- src/aliaslib.c	Sat Oct 10 21:21:18 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: aliaslib.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: aliaslib.c,v 5.2 1992/10/11 01:21:17 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,31 ----
   *
   *******************************************************************************
   * $Log: aliaslib.c,v $
+  * Revision 5.2  1992/10/11  01:21:17  syd
+  * 1. If firstname && lastname is null then copy aliasname into the
+  * personal name field (inside the ()'s) when creating an alias
+  * from the menu using the 'n' command.
+  *
+  * 2. Now if for some reason and alias has a null personal name field
+  * (the person hand edited aliases.text) the blank () is not printed
+  * as part of the address.  This actually cured another problem, where
+  * the To: field on the screen (when you hit 'm' on the alias menu)
+  * used to be blank, now the address shows up....
+  * From: "Robert L. Howard" <robert.howard@matd.gatech.edu>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 102,109 ****
  	  if ( (loc = find_alias(name, USER)) >= 0 ) {
  	    match = aliases[loc];
  	    strcpy(abuf, match->address);
! 	    if ( match->type & PERSON )
                  sprintf(abuf+strlen(abuf), " (%s)", match->name);
  	    goto do_expand;
  	  }
  	}
--- 114,124 ----
  	  if ( (loc = find_alias(name, USER)) >= 0 ) {
  	    match = aliases[loc];
  	    strcpy(abuf, match->address);
! 	    if ( match->type & PERSON ) {
! 	      if (strlen(match->name) > 0) {
                  sprintf(abuf+strlen(abuf), " (%s)", match->name);
+ 	      }
+ 	    }
  	    goto do_expand;
  	  }
  	}
***************
*** 112,119 ****
  	  if ( (loc = find_alias(name, SYSTEM)) >= 0 ) {
  	    match = aliases[loc];
  	    strcpy(abuf, match->address);
! 	    if ( match->type & PERSON )
                  sprintf(abuf+strlen(abuf), " (%s)", match->name);
  	    sysalias = TRUE;
  	    goto do_expand;
  	  }
--- 127,137 ----
  	  if ( (loc = find_alias(name, SYSTEM)) >= 0 ) {
  	    match = aliases[loc];
  	    strcpy(abuf, match->address);
! 	    if ( match->type & PERSON ) {
! 	      if (strlen(match->name) > 0) {
                  sprintf(abuf+strlen(abuf), " (%s)", match->name);
+ 	      }
+ 	    }
  	    sysalias = TRUE;
  	    goto do_expand;
  	  }

Index: src/curses.c
Prereq: 5.1
*** ../elm2.4/src/curses.c	Sat Oct  3 18:58:48 1992
--- src/curses.c	Sat Oct 10 21:02:33 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: curses.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: curses.c,v 5.2 1992/10/11 01:02:05 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   * 			Copyright (c) 1988-1992 USENET Community Trust
   * 			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,23 ----
   *
   *******************************************************************************
   * $Log: curses.c,v $
+  * Revision 5.2  1992/10/11  01:02:05  syd
+  * Add AIX to those who dont define window size in termios.h
+  * From: Syd via note from Tom Kovar
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 37,43 ****
  
  #ifdef TERMIOS
  #  include <termios.h>
! # if __convex__
  #  include <sys/ioctl.h>	/* non-standard, for TIOCGWINSZ */
  # endif
  #else
--- 41,47 ----
  
  #ifdef TERMIOS
  #  include <termios.h>
! # if defined(__convex__) || defined(_AIX)
  #  include <sys/ioctl.h>	/* non-standard, for TIOCGWINSZ */
  # endif
  #else

Index: src/file.c
Prereq: 5.1
*** ../elm2.4/src/file.c	Sat Oct  3 18:58:53 1992
--- src/file.c	Sat Oct 10 20:59:40 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: file.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: file.c,v 5.2 1992/10/11 00:59:39 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,24 ----
   *
   *******************************************************************************
   * $Log: file.c,v $
+  * Revision 5.2  1992/10/11  00:59:39  syd
+  * Fix some compiler warnings that I receive compiling Elm on my SVR4
+  * machine.
+  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 44,49 ****
--- 49,56 ----
  char *strcpy(), *nameof();
  unsigned long sleep();
  
+ void save_message();
+ 
  static char copyhelp[VERY_LONG_STRING];
  static char savehelp[VERY_LONG_STRING];
  static char prev_fold[SLEN];           /* name of previous folder */
***************
*** 268,274 ****
  	return(1);
  }
  
! int
  save_message(number, filename, fd, pause, appending, silently, delete)
  int number, pause, appending, silently, delete;
  char *filename;
--- 275,281 ----
  	return(1);
  }
  
! void
  save_message(number, filename, fd, pause, appending, silently, delete)
  int number, pause, appending, silently, delete;
  char *filename;

Index: src/lock.c
Prereq: 5.1
*** ../elm2.4/src/lock.c	Sat Oct  3 18:59:01 1992
--- src/lock.c	Sun Oct 11 20:25:52 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: lock.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: lock.c,v 5.3 1992/10/12 00:25:52 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.3 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,28 ----
   *
   *******************************************************************************
   * $Log: lock.c,v $
+  * Revision 5.3  1992/10/12  00:25:52  syd
+  * Lock error codes (fcntl vs flock) were backwards
+  * From: howardl@wb3ffv.ampr.org (Howard Leadmon - WB3FFV)
+  *
+  * Revision 5.2  1992/10/11  00:52:11  syd
+  * Switch to wrapper for flock and fcntl locking.
+  * Change order to fcntl first, other order blocked.
+  * From: Jukka Ukkonen <ukkonen@csc.fi>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 24,39 ****
    
  **/
  
  #include "headers.h"
  #include "s_elm.h"
  #include <sys/types.h>
  #include <sys/stat.h>
! #ifdef USE_FLOCK_LOCKING
! #define SYSCALL_LOCKING
! #endif
  #ifdef USE_FCNTL_LOCKING
! #define SYSCALL_LOCKING
  #endif
  #ifdef SYSCALL_LOCKING
  #include <sys/file.h>
  #endif
--- 33,52 ----
    
  **/
  
+ 
  #include "headers.h"
  #include "s_elm.h"
  #include <sys/types.h>
  #include <sys/stat.h>
! 
  #ifdef USE_FCNTL_LOCKING
! # define SYSCALL_LOCKING
! #else
! # ifdef USE_FLOCK_LOCKING
! #   define SYSCALL_LOCKING
! # endif
  #endif
+ 
  #ifdef SYSCALL_LOCKING
  #include <sys/file.h>
  #endif
***************
*** 54,59 ****
--- 67,76 ----
  unsigned long sleep();
  #endif
  
+ #define	FLOCKING_OK	0
+ #define	FLOCKING_RETRY	1
+ #define	FLOCKING_FAIL	-1
+ 
  extern char *mk_lockname();
  
  static int  lock_state = OFF;
***************
*** 60,66 ****
  
  #ifdef	USE_DOTLOCK_LOCKING
  static char *lockfile=(char*)0;
! #endif
  
  static int flock_fd,	/* file descriptor for flocking mailbox itself */
  	   create_fd;	/* file descriptor for creating lock file */
--- 77,83 ----
  
  #ifdef	USE_DOTLOCK_LOCKING
  static char *lockfile=(char*)0;
! #endif  /* USE_DOTLOCK_LOCKING */
  
  static int flock_fd,	/* file descriptor for flocking mailbox itself */
  	   create_fd;	/* file descriptor for creating lock file */
***************
*** 69,74 ****
--- 86,176 ----
  static struct flock lock_info;
  #endif
  
+ int
+ Grab_the_file(flock_fd)
+ int flock_fd;
+ {
+     int	retcode	= FLOCKING_OK;
+ 
+     errno = 0;
+ 
+ #ifdef   USE_FCNTL_LOCKING
+     lock_info.l_type = F_WRLCK;
+     lock_info.l_whence = 0;
+     lock_info.l_start = 0;
+     lock_info.l_len = 0;
+ 
+     if (fcntl(flock_fd, F_SETLK, &lock_info)) {
+ 	return ((errno == EACCES) || (EAGAIN))
+ 		? FLOCKING_RETRY
+ 		: FLOCKING_FAIL ;
+     }
+ #endif
+ 
+ #ifdef	USE_FLOCK_LOCKING
+     if (flock (flock_fd, LOCK_NB | LOCK_EX)) {
+ 
+ 	retcode = ((errno == EWOULDBLOCK) || (errno == EAGAIN))
+ 		   ? FLOCKING_RETRY
+ 		   : FLOCKING_FAIL ;
+ 
+ #ifdef USE_FCNTL_LOCKING
+ 	lock_info.l_type = F_UNLCK;
+ 	lock_info.l_whence = 0;
+ 	lock_info.l_start = 0;
+ 	lock_info.l_len = 0;
+ 
+ 	/*
+ 	 *  Just unlock it because we did not succeed with the
+ 	 *  flock()-style locking. Never mind the return value.
+ 	 *  It was our own lock anyway if we ever got this far.
+ 	 */
+ 	fcntl (flock_fd, F_SETLK, &lock_info);
+ #endif
+ 	return retcode;
+     }
+ #endif
+ 
+     return FLOCKING_OK;
+ }
+ 
+ int
+ Release_the_file(flock_fd)
+ int flock_fd;
+ {
+     int	fcntlret = 0,
+ 	flockret = 0,
+ 	fcntlerr,
+ 	flockerr;
+ 
+ #ifdef	USE_FLOCK_LOCKING
+     errno = 0;
+     flockret = flock (flock_fd, LOCK_UN);
+     flockerr = errno;
+ #endif
+ 
+ #ifdef	USE_FCNTL_LOCKING
+     lock_info.l_type = F_UNLCK;
+     lock_info.l_whence = 0;
+     lock_info.l_start = 0;
+     lock_info.l_len = 0;
+ 
+     errno = 0;
+     fcntlret = fcntl (flock_fd, F_SETLK, &lock_info);
+     fcntlerr = errno;
+ #endif
+ 
+     if (fcntlret) {
+ 	errno = fcntlerr;
+ 	return fcntlret;
+     }
+     else if (flockret) {
+ 	errno = flockret;
+ 	return flockret;
+     }
+     return 0;
+ }
+ 
  lock(direction)
  int direction;
  {
***************
*** 91,101 ****
        **/
  
        register int create_iteration = 0,
! 		   flock_iteration;
        int kill_status;
        char pid_buffer[SHORT];
  
! #ifdef	USE_DOTLOCK_LOCKING		/* { USE_DOTLOCK_LOCKING	*/
        /* formulate lock file name */
        lockfile=mk_lockname(cur_folder);
  
--- 193,203 ----
        **/
  
        register int create_iteration = 0,
! 		   flock_iteration = 0;
        int kill_status;
        char pid_buffer[SHORT];
  
! #ifdef	USE_DOTLOCK_LOCKING		/* { USE_DOTLOCK_LOCKING  */
        /* formulate lock file name */
        lockfile=mk_lockname(cur_folder);
  
***************
*** 271,280 ****
  #ifdef SAVE_GROUP_MAILBOX_ID
        setgid(groupid);
  #endif
! #endif				/* } USE_DOTLOCK_LOCKING */
  				   
  #ifdef SYSCALL_LOCKING
!       /* Now we also need to lock the file with flock(2) or fcntl(2) */
  
        /* Open mail file separately for locking */
        if((flock_fd = open(cur_folder, O_RDWR)) < 0) {
--- 373,382 ----
  #ifdef SAVE_GROUP_MAILBOX_ID
        setgid(groupid);
  #endif
! #endif	/* } USE_DOTLOCK_LOCKING */
  				   
  #ifdef SYSCALL_LOCKING
!       /* Now we also need to lock the file with flock(2) */
  
        /* Open mail file separately for locking */
        if((flock_fd = open(cur_folder, O_RDWR)) < 0) {
***************
*** 292,320 ****
  	leave();
        }
  
- #ifdef USE_FCNTL_LOCKING
        /* try to assert lock MAX_ATTEMPTS times */
-       flock_iteration = 0;
        do {
  
! 	errno = 0;
! 	lock_info.l_type = F_WRLCK;
! 	lock_info.l_whence = 0;
! 	lock_info.l_start = 0;
! 	lock_info.l_len = 0;
! 	if(fcntl(flock_fd, F_SETLK, &lock_info) != -1)
! 	  break;
! 	else {
! 	  if(errno != EAGAIN && errno != EACCES)
! 	  {
! 
! 	    /* Creation of lock failed NOT because it already exists!!! */
  
! 	    dprint(1, (debugfile, 
! 		  "Error encountered attempting to fcntl lock %s\n", cur_folder));
! 	    dprint(1, (debugfile, "** %s **\n", error_description(errno)));
  	    MoveCursor(LINES, 0);
! 	    printf(catgets(elm_msg_cat, ElmSet, ElmLeaveErrorFlockMailbox,
  	 "\n\rError encountered while attempting to flock mailbox %s;\n\r"), 
  		  cur_folder);
  	    printf("** %s. **\n\r\n\r", error_description(errno));
--- 394,420 ----
  	leave();
        }
  
        /* try to assert lock MAX_ATTEMPTS times */
        do {
  
! 	switch (Grab_the_file (flock_fd)) {
  
! 	case	FLOCKING_OK:
! 	    goto    EXIT_RETRY_LOOP;
! 	    break;
! 
! 	case	FLOCKING_FAIL:
! 	    /*
! 	     *	Creation of lock failed
! 	     *	NOT because it already exists!!!
! 	     */
! 
! 	    dprint (1, (debugfile, 
! 			"Error encountered attempting to flock %s\n",
! 			cur_folder));
! 	    dprint (1, (debugfile, "** %s **\n", error_description(errno)));
  	    MoveCursor(LINES, 0);
! 	    printf (catgets(elm_msg_cat, ElmSet, ElmLeaveErrorFlockMailbox,
  	 "\n\rError encountered while attempting to flock mailbox %s;\n\r"), 
  		  cur_folder);
  	    printf("** %s. **\n\r\n\r", error_description(errno));
***************
*** 322,375 ****
  	    (void)unlink(lockfile);
  #endif /* USE_DOTLOCK_LOCKING */
  	    leave();
- 	  }
- 	}
- 	dprint(2, (debugfile,
- 	  "Mailbox '%s' already locked!  Waiting...(lock)\n", cur_folder));
- 	error1(catgets(elm_msg_cat, ElmSet, ElmLeaveWaitingToRead,
- 	  "Waiting to read mailbox while mail is being received: attempt #%d"),
- 	  flock_iteration);
- 	sleep(5);
-       } while (flock_iteration++ < MAX_ATTEMPTS);
- #endif  /* USE_FCNTL_LOCKING */
- 
- #ifdef USE_FLOCK_LOCKING
-       /* try to assert lock MAX_ATTEMPTS times */
-       flock_iteration = 0;
-       do {
- 
- 	errno = 0;
- 	if(flock(flock_fd, LOCK_NB | LOCK_EX) != -1)
- 	  break;
- 	else {
- 	  if(errno != EWOULDBLOCK && errno != EAGAIN)
- 	  {
  
! 	    /* Creation of lock failed NOT because it already exists!!! */
  
! 	    dprint(1, (debugfile, 
! 		  "Error encountered attempting to flock %s\n", cur_folder));
! 	    dprint(1, (debugfile, "** %s **\n", error_description(errno)));
! 	    MoveCursor(LINES, 0);
! 	    printf(catgets(elm_msg_cat, ElmSet, ElmLeaveErrorFlockMailbox,
! 	 "\n\rError encountered while attempting to flock mailbox %s;\n\r"), 
! 		  cur_folder);
! 	    printf("** %s. **\n\r\n\r", error_description(errno));
! #ifdef	USE_DOTLOCK_LOCKING
! 	    (void)unlink(lockfile);
! #endif /* USE_DOTLOCK_LOCKING */
! 	    leave();
! 	  }
  	}
- 	dprint(2, (debugfile,
- 	  "Mailbox '%s' already locked!  Waiting...(lock)\n", cur_folder));
- 	error1(catgets(elm_msg_cat, ElmSet, ElmLeaveWaitingToRead,
- 	  "Waiting to read mailbox while mail is being received: attempt #%d"),
- 	  flock_iteration);
- 	sleep(5);
        } while (flock_iteration++ < MAX_ATTEMPTS);
- #endif  /* USE_FLOCK_LOCKING */
  
        clear_error();
  
        if(errno != 0) {
--- 422,442 ----
  	    (void)unlink(lockfile);
  #endif /* USE_DOTLOCK_LOCKING */
  	    leave();
  
! 	    break;
  
! 	case	FLOCKING_RETRY:
! 	default:
! 	    dprint (2, (debugfile,
! 	      "Mailbox '%s' already locked!  Waiting...(lock)\n", cur_folder));
! 	    error1 (catgets(elm_msg_cat, ElmSet, ElmLeaveWaitingToRead,
! 			   "Waiting to read mailbox while mail is being received: attempt #%d"),
! 		    flock_iteration);
! 	    sleep(5);
  	}
        } while (flock_iteration++ < MAX_ATTEMPTS);
  
+ EXIT_RETRY_LOOP:
        clear_error();
  
        if(errno != 0) {
***************
*** 423,488 ****
  
  	int retcode = 0;
  
! #ifndef	USE_DOTLOCK_LOCKING
  	dprint(5,
! 	  (debugfile, "Lock (no dotlock) for file %s %s off.\n",
  	    cur_folder, (lock_state == ON ? "going" : "already")));
! #else   /* !USE_DOTLOCK_LOCKING */
  	dprint(5,
  	  (debugfile, "Lock %s for file %s %s off.\n",
   	    (*lockfile ? lockfile : "none"),
  	    cur_folder,
  	    (lock_state == ON ? "going" : "already")));
! #endif  /* !USE_DOTLOCK_LOCKING */
  
  	if(lock_state == ON) {
  
! #ifdef USE_FCNTL_LOCKING
! 	  lock_info.l_type = F_UNLCK;
! 	  lock_info.l_whence = 0;
! 	  lock_info.l_start = 0;
! 	  lock_info.l_len = 0;
! 		
! 	  if((retcode = fcntl(flock_fd, F_SETLK, &lock_info)) == -1)
! 		  {
! 	    dprint(1, (debugfile,
! 	      "Error %s\n\ttrying to unlock file %s (%s)\n", 
! 	      error_description(errno), cur_folder, "unlock"));
! 
! 	    /* try to force unlock by closing file */
! 	    if(close(flock_fd) == -1) {
! 	      dprint(1, (debugfile,
! 	  "Error %s\n\ttrying to force unlock file %s via close() (%s)\n", 
! 	      error_description(errno), cur_folder, "unlock"));
! 	      error1(catgets(elm_msg_cat, ElmSet, ElmLeaveCouldntUnlockOwnMailbox,
! 		"Couldn't unlock my own mailbox %s!"), cur_folder);
! 	      return(retcode);
! 	    }
! 	  }
! 	  (void)close(flock_fd);
! #endif
  
! #ifdef USE_FLOCK_LOCKING
! 	  if((retcode = flock(flock_fd, LOCK_UN)) == -1)
! 		  {
! 	    dprint(1, (debugfile,
! 	      "Error %s\n\ttrying to unlock file %s (%s)\n", 
! 	      error_description(errno), cur_folder, "unlock"));
  
! 	    /* try to force unlock by closing file */
! 	    if(close(flock_fd) == -1) {
! 	      dprint(1, (debugfile,
! 	  "Error %s\n\ttrying to force unlock file %s via close() (%s)\n", 
! 	      error_description(errno), cur_folder, "unlock"));
! 	      error1(catgets(elm_msg_cat, ElmSet, ElmLeaveCouldntUnlockOwnMailbox,
! 		"Couldn't unlock my own mailbox %s!"), cur_folder);
! 	      return(retcode);
  	    }
! 	  }
! 	  (void)close(flock_fd);
  #endif
! 
! #ifndef	USE_DOTLOCK_LOCKING	/* { !USE_DOTLOCK_LOCKING */
  	   lock_state = OFF;		/* indicate we don't have a lock on */
  #else
  #ifdef SAVE_GROUP_MAILBOX_ID
--- 490,532 ----
  
  	int retcode = 0;
  
! #ifndef USE_DOTLOCK_LOCKING
  	dprint(5,
! 	  (debugfile, "Lock (no .lock) for file %s %s off.\n",
  	    cur_folder, (lock_state == ON ? "going" : "already")));
! #else   /* USE_DOTLOCK_LOCKING */
  	dprint(5,
  	  (debugfile, "Lock %s for file %s %s off.\n",
   	    (*lockfile ? lockfile : "none"),
  	    cur_folder,
  	    (lock_state == ON ? "going" : "already")));
! #endif  /* USE_DOTLOCK_LOCKING */
  
  	if(lock_state == ON) {
  
! #ifdef SYSCALL_LOCKING
! 	    if (retcode = Release_the_file (flock_fd)) {
  
! 		dprint(1, (debugfile,
! 			   "Error %s\n\ttrying to unlock file %s (%s)\n", 
! 			   error_description(errno), cur_folder, "unlock"));
  
! 		/* try to force unlock by closing file */
! 		if (close (flock_fd) == -1) {
! 		    dprint (1, (debugfile,
! 	      "Error %s\n\ttrying to force unlock file %s via close() (%s)\n", 
! 				error_description(errno),
! 				cur_folder, "unlock"));
! 		    error1 (catgets (elm_msg_cat, ElmSet,
! 				     ElmLeaveCouldntUnlockOwnMailbox,
! 				     "Couldn't unlock my own mailbox %s!"),
! 				     cur_folder);
! 		    return(retcode);
! 		}
  	    }
! 	    (void)close(flock_fd);
  #endif
! #ifndef	USE_DOTLOCK_LOCKING	/* { USE_DOTLOCK_LOCKING */
  	   lock_state = OFF;		/* indicate we don't have a lock on */
  #else
  #ifdef SAVE_GROUP_MAILBOX_ID

Index: src/read_rc.c
Prereq: 5.1
*** ../elm2.4/src/read_rc.c	Sat Oct  3 18:59:12 1992
--- src/read_rc.c	Sat Oct 10 20:59:41 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: read_rc.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: read_rc.c,v 5.2 1992/10/11 00:59:39 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,24 ----
   *
   *******************************************************************************
   * $Log: read_rc.c,v $
+  * Revision 5.2  1992/10/11  00:59:39  syd
+  * Fix some compiler warnings that I receive compiling Elm on my SVR4
+  * machine.
+  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 435,441 ****
  
  
  do_rc(file, lcl)
! int file, lcl;
  {
  	static int prev_type = 0;
  	int x;
--- 440,447 ----
  
  
  do_rc(file, lcl)
! FILE *file;
! int lcl;
  {
  	static int prev_type = 0;
  	int x;
***************
*** 486,492 ****
   */
  
  do_set(file, word1, word2, lcl)
! int file, lcl;
  char *word1, *word2;
  {
  	register int x, y;
--- 492,499 ----
   */
  
  do_set(file, word1, word2, lcl)
! FILE *file;
! int lcl;
  char *word1, *word2;
  {
  	register int x, y;
***************
*** 509,515 ****
  	switch (save_info[x].flags & DT_MASK) {
  	    case DT_SYN:
  		return(do_set(file, SAVE_INFO_SYN(x), word2, lcl));
- 	    break;
  
  	    case DT_MLT:
  		y=0;
--- 516,521 ----
***************
*** 523,529 ****
  		    always_store = !always_store;
  		}
  		return(y); /* we shouldn't "or" the values into "y" */
- 		break;
  
  	    case DT_STR:
  		strcpy(SAVE_INFO_STR(x), word2);
--- 529,534 ----

Index: src/remail.c
Prereq: 5.1
*** ../elm2.4/src/remail.c	Sat Oct  3 18:59:13 1992
--- src/remail.c	Sat Oct 10 20:59:43 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: remail.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: remail.c,v 5.2 1992/10/11 00:59:39 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,24 ----
   *
   *******************************************************************************
   * $Log: remail.c,v $
+  * Revision 5.2  1992/10/11  00:59:39  syd
+  * Fix some compiler warnings that I receive compiling Elm on my SVR4
+  * machine.
+  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 23,29 ****
  /** For those cases when you want to have a message continue along
      to another person in such a way as they end up receiving it with
      the return address the person YOU received the mail from (does
!     this comment make any sense yet??)...
  
  **/
  
--- 28,34 ----
  /** For those cases when you want to have a message continue along
      to another person in such a way as they end up receiving it with
      the return address the person YOU received the mail from (does
!     this comment make any sense yet?)...
  
  **/
  

Index: src/reply.c
Prereq: 5.1
*** ../elm2.4/src/reply.c	Sat Oct  3 18:59:14 1992
--- src/reply.c	Sat Oct 10 21:26:16 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: reply.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: reply.c,v 5.2 1992/10/11 01:25:58 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,23 ----
   *
   *******************************************************************************
   * $Log: reply.c,v $
+  * Revision 5.2  1992/10/11  01:25:58  syd
+  * Add undefs of tolower so BSD macro isnt used from ctype.h
+  * From: Syd
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 28,33 ****
--- 32,41 ----
  #include "s_elm.h"
  #include <errno.h>
  #include <ctype.h>
+ 
+ #ifdef BSD
+ #undef        tolower
+ #endif
  
  #ifndef BSD
  #  include <sys/types.h>

Index: src/wildcards.c
Prereq: 5.1
*** ../elm2.4/src/wildcards.c	Sat Oct  3 18:59:23 1992
--- src/wildcards.c	Sat Oct 10 21:19:02 1992
***************
*** 1,8 ****
  
! static char rcsid[] = "@(#)$Id: wildcards.c,v 5.1 1992/10/03 22:58:40 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
--- 1,8 ----
  
! static char rcsid[] = "@(#)$Id: wildcards.c,v 5.2 1992/10/11 01:18:23 syd Exp $";
  
  /*******************************************************************************
!  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
   *
   *			Copyright (c) 1988-1992 USENET Community Trust
   *			Copyright (c) 1986,1987 Dave Taylor
***************
*** 14,19 ****
--- 14,24 ----
   *
   *******************************************************************************
   * $Log: wildcards.c,v $
+  * Revision 5.2  1992/10/11  01:18:23  syd
+  * Fix where a SHELL=sh would cause a segv due to no / in
+  * the shell name.
+  * From: Syd
+  *
   * Revision 5.1  1992/10/03  22:58:40  syd
   * Initial checkin as of 2.4 Release at PL0
   *
***************
*** 84,89 ****
--- 89,97 ----
  		{
  			if ( NULL != ( sh_name = rindex( user_shell, '/' ) ) )
  				sh_name++ ;
+ 			else
+ 				sh_name = user_shell;
+ 
  			for ( wptr = known_shells ; ( wptr->shell_name != NULL ) ; wptr++ )
  				if ( 0 == strcmp( wptr->shell_name, sh_name ) )
  					break ;

-- 
========================================================================
Sydney S. Weinstein, CDP, CCP          Elm Coordinator - Current 2.4PL02
Datacomp Systems, Inc.                 Projected 3.0 Release: ??? ?,1994
syd@DSI.COM or dsinc!syd      Voice: (215) 947-9900, FAX: (215) 938-0235
Newsgroups: comp.mail.elm