summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/src
diff options
context:
space:
mode:
authorgshapiro <gshapiro@FreeBSD.org>2002-02-17 22:51:21 +0000
committergshapiro <gshapiro@FreeBSD.org>2002-02-17 22:51:21 +0000
commitfe44899bd885df843dfa88bcb1946e3977beef06 (patch)
tree925d7161b7b7868559a2204d6bc4be8182153f6b /contrib/sendmail/src
parentf9b416a6c3a812faf3766993dfac38090a9b2376 (diff)
downloadFreeBSD-src-fe44899bd885df843dfa88bcb1946e3977beef06.zip
FreeBSD-src-fe44899bd885df843dfa88bcb1946e3977beef06.tar.gz
This commit was generated by cvs2svn to compensate for changes in r90809,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/sendmail/src')
-rw-r--r--contrib/sendmail/src/bf_portable.c525
-rw-r--r--contrib/sendmail/src/bf_portable.h46
-rw-r--r--contrib/sendmail/src/bf_torek.c831
-rw-r--r--contrib/sendmail/src/bf_torek.h42
-rw-r--r--contrib/sendmail/src/clock.c513
5 files changed, 0 insertions, 1957 deletions
diff --git a/contrib/sendmail/src/bf_portable.c b/contrib/sendmail/src/bf_portable.c
deleted file mode 100644
index f14077f..0000000
--- a/contrib/sendmail/src/bf_portable.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
- * All rights reserved.
- *
- * By using this file, you agree to the terms and conditions set
- * forth in the LICENSE file which can be found at the top level of
- * the sendmail distribution.
- *
- * Contributed by Exactis.com, Inc.
- *
- */
-
-#ifndef lint
-static char id[] = "@(#)$Id: bf_portable.c,v 8.25.4.6 2001/05/03 17:24:01 gshapiro Exp $";
-#endif /* ! lint */
-
-#if SFIO
-# include <sfio/stdio.h>
-#endif /* SFIO */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/uio.h>
-#include <errno.h>
-#if !SFIO
-# include <stdio.h>
-#endif /* !SFIO */
-#ifdef BF_STANDALONE
-# define sm_free free
-# define xalloc malloc
-#else /* BF_STANDALONE */
-# include "sendmail.h"
-#endif /* BF_STANDALONE */
-#include "bf_portable.h"
-#include "bf.h"
-
- /*
-** BFOPEN -- create a new buffered file
-**
-** Parameters:
-** filename -- the file's name
-** fmode -- what mode the file should be created as
-** bsize -- amount of buffer space to allocate (may be 0)
-** flags -- if running under sendmail, passed directly to safeopen
-**
-** Returns:
-** a FILE * which may then be used with stdio functions, or NULL
-** on failure. FILE * is opened for writing (mode "w+").
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** ENOMEM -- out of memory
-** ENOENT -- illegal empty filename specified
-** any value of errno specified by open()
-** any value of errno specified by fdopen()
-** any value of errno specified by funopen()
-*/
-
-#ifdef BF_STANDALONE
-# define OPEN(fn, omode, cmode, sff) open(fn, omode, cmode)
-#else /* BF_STANDALONE */
-# define OPEN(fn, omode, cmode, sff) safeopen(fn, omode, cmode, sff)
-#endif /* BF_STANDALONE */
-
-/* List of currently-open buffered files */
-struct bf *bflist = NULL;
-
-FILE *
-bfopen(filename, fmode, bsize, flags)
- char *filename;
- int fmode;
- size_t bsize;
- long flags;
-{
- struct bf *bfp;
- FILE *retval;
- int fd, l;
-
- fd = OPEN(filename, O_RDWR | O_CREAT | O_TRUNC, fmode, flags);
- if (fd == -1)
- {
- /* errno is set implicitly by open */
- return NULL;
- }
-
- retval = fdopen(fd, "w+");
-
- /* If failure, return immediately */
- if (retval == NULL)
- {
- /* errno is set implicitly by fdopen */
- return NULL;
- }
-
- /* Allocate memory */
- bfp = (struct bf *)xalloc(sizeof(struct bf));
- if (bfp == NULL)
- {
- (void) fclose(retval);
-
- /* don't care about errors */
- (void) unlink(filename);
- errno = ENOMEM;
- return NULL;
- }
- if (tTd(58, 8))
- dprintf("bfopen(%s): malloced %ld\n",
- filename, (long) sizeof(struct bf));
-
- l = strlen(filename) + 1;
- bfp->bf_filename = (char *)xalloc(l);
- if (bfp->bf_filename == NULL)
- {
- sm_free(bfp);
- (void) fclose(retval);
-
- /* don't care about errors */
- (void) unlink(filename);
- errno = ENOMEM;
- return NULL;
- }
- (void) strlcpy(bfp->bf_filename, filename, l);
-
- /* Fill in the other fields, then add it to the list */
- bfp->bf_key = retval;
- bfp->bf_committed = FALSE;
- bfp->bf_refcount = 1;
-
- bfinsert(bfp);
-
- /* Whew. Nothing bad happened. We're okay. */
- return retval;
-}
- /*
-** BFDUP -- increase refcount on buffered file
-**
-** Parameters:
-** fp -- FILE * to "duplicate"
-**
-** Returns:
-** fp with increased refcount
-*/
-
-FILE *
-bfdup(fp)
- FILE *fp;
-{
- struct bf *bfp;
-
- /* Get associated bf structure */
- bfp = bflookup(fp);
-
- if (bfp == NULL)
- return NULL;
-
- /* Increase the refcount */
- bfp->bf_refcount++;
-
- return fp;
-}
-
- /*
-** BFCOMMIT -- "commits" the buffered file
-**
-** Parameters:
-** fp -- FILE * to commit to disk
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** Forces the given FILE * to be written to disk if it is not
-** already, and ensures that it will be kept after closing. If
-** fp is not a buffered file, this is a no-op.
-**
-** Sets errno:
-** any value of errno specified by open()
-** any value of errno specified by write()
-** any value of errno specified by lseek()
-*/
-
-int
-bfcommit(fp)
- FILE *fp;
-{
- struct bf *bfp;
-
- /* Get associated bf structure */
- bfp = bflookup(fp);
-
- /* If called on a normal FILE *, noop */
- if (bfp != NULL)
- bfp->bf_committed = TRUE;
-
- return 0;
-}
-
- /*
-** BFREWIND -- rewinds the FILE *
-**
-** Parameters:
-** fp -- FILE * to rewind
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** rewinds the FILE * and puts it into read mode. Normally one
-** would bfopen() a file, write to it, then bfrewind() and
-** fread(). If fp is not a buffered file, this is equivalent to
-** rewind().
-**
-** Sets errno:
-** any value of errno specified by fseek()
-*/
-
-int
-bfrewind(fp)
- FILE *fp;
-{
- int err;
-
- /* check to see if there is an error on the stream */
- err = ferror(fp);
- (void) fflush(fp);
-
- /*
- ** Clear error if tried to fflush()
- ** a read-only file pointer and
- ** there wasn't a previous error.
- */
-
- if (err == 0)
- clearerr(fp);
-
- /* errno is set implicitly by fseek() before return */
- return fseek(fp, 0, SEEK_SET);
-}
-
- /*
-** BFTRUNCATE -- rewinds and truncates the FILE *
-**
-** Parameters:
-** fp -- FILE * to truncate
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** rewinds the FILE *, truncates it to zero length, and puts it
-** into write mode. If fp is not a buffered file, this is
-** equivalent to a rewind() and then an ftruncate(fileno(fp), 0).
-**
-** Sets errno:
-** any value of errno specified by fseek()
-** any value of errno specified by ftruncate()
-*/
-
-int
-bftruncate(fp)
- FILE *fp;
-{
- int ret;
-
- if (bfrewind(fp) == -1)
- {
- /* errno is set implicitly by bfrewind() */
- return -1;
- }
-
-#if NOFTRUNCATE
- /* XXX */
- errno = EINVAL;
- ret = -1;
-#else /* NOFTRUNCATE */
- /* errno is set implicitly by ftruncate() before return */
- ret = ftruncate(fileno(fp), 0);
-#endif /* NOFTRUNCATE */
- return ret;
-}
-
- /*
-** BFFSYNC -- fsync the fd associated with the FILE *
-**
-** Parameters:
-** fp -- FILE * to fsync
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Sets errno:
-** EINVAL if FILE * not bfcommitted yet.
-** any value of errno specified by fsync()
-*/
-
-int
-bffsync(fp)
- FILE *fp;
-{
- int fd;
- struct bf *bfp;
-
- /* Get associated bf structure */
- bfp = bflookup(fp);
-
- /* If called on a normal FILE *, noop */
- if (bfp != NULL && !bfp->bf_committed)
- fd = -1;
- else
- fd = fileno(fp);
-
- if (tTd(58, 10))
- dprintf("bffsync: fd = %d\n", fd);
-
- if (fd < 0)
- {
- errno = EINVAL;
- return -1;
- }
- return fsync(fd);
-}
-
- /*
-** BFCLOSE -- close a buffered file
-**
-** Parameters:
-** fp -- FILE * to close
-**
-** Returns:
-** 0 on success, EOF on failure
-**
-** Side Effects:
-** Closes fp. If fp is a buffered file, unlink it if it has not
-** already been committed. If fp is not a buffered file, this is
-** equivalent to fclose().
-**
-** Sets errno:
-** any value of errno specified by fclose()
-*/
-
-int
-bfclose(fp)
- FILE *fp;
-{
- int retval;
- struct bf *bfp = NULL;
-
- /* Get associated bf structure */
- bfp = bflookup(fp);
-
- /* Decrement and check refcount */
- if (bfp != NULL && --bfp->bf_refcount > 0)
- return 0;
-
- /* If bf, get bf structure and remove from list */
- if (bfp != NULL)
- bfp = bfdelete(fp);
-
- if (fclose(fp) == EOF)
- {
- if (tTd(58, 8))
- dprintf("bfclose: fclose failed\n");
- /* errno is set implicitly by fclose() */
- return -1;
- }
-
- if (bfp == NULL)
- return 0;
-
- /* Success unless we determine otherwise in next block */
- retval = 0;
-
- if (bfp != NULL)
- {
- /* Might have to unlink; certainly will have to deallocate */
- if (!bfp->bf_committed)
- retval = unlink(bfp->bf_filename);
-
- sm_free(bfp->bf_filename);
- sm_free(bfp);
- if (tTd(58, 8))
- dprintf("bfclose: freed %ld\n",
- (long) sizeof(struct bf));
- }
- else
- {
- if (tTd(58, 8))
- dprintf("bfclose: bfp was NULL\n");
- }
-
- return retval;
-}
-
- /*
-** BFTEST -- test if a FILE * is a buffered file
-**
-** Parameters:
-** fp -- FILE * to test
-**
-** Returns:
-** TRUE if fp is a buffered file, FALSE otherwise.
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** never.
-*/
-
-bool
-bftest(fp)
- FILE *fp;
-{
- return (bflookup(fp) != NULL);
-}
-
- /*
-** BFINSERT -- insert item in linking list
-**
-** Parameters:
-** datum -- item to insert
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** never.
-*/
-
-void
-bfinsert(datum)
- struct bf *datum;
-{
- datum->bf_cdr = bflist;
- bflist = datum;
-}
-
- /*
-** BFLOOKUP -- lookup FILE * in list
-**
-** Parameters:
-** fp -- FILE * to lookup
-**
-** Returns:
-** bf struct for the FILE *, NULL if not found
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** never.
-*/
-
-struct bf *
-bflookup(key)
- FILE *key;
-{
- struct bf *t;
-
- for (t = bflist; t != NULL; t = t->bf_cdr)
- {
- if (t->bf_key == key)
- {
- return t;
- }
- }
-
- /* If we got this far, we didn't find it */
- return NULL;
-}
-
- /*
-** BFDELETE -- delete a FILE * in list
-**
-** Parameters:
-** fp -- FILE * to delete
-**
-** Returns:
-** bf struct for deleted FILE *, NULL if not found,
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** never.
-*/
-
-struct bf *
-bfdelete(key)
- FILE *key;
-{
- struct bf *t, *u;
-
- if (bflist == NULL)
- return NULL;
-
- /* if first element, special case */
- if (bflist->bf_key == key)
- {
- u = bflist;
- bflist = bflist->bf_cdr;
- return u;
- }
-
- for (t = bflist; t->bf_cdr != NULL; t = t->bf_cdr)
- {
- if (t->bf_cdr->bf_key == key)
- {
- u = t->bf_cdr;
- t->bf_cdr = u->bf_cdr;
- return u;
- }
- }
-
- /* If we got this far, we didn't find it */
- return NULL;
-}
diff --git a/contrib/sendmail/src/bf_portable.h b/contrib/sendmail/src/bf_portable.h
deleted file mode 100644
index e319a74..0000000
--- a/contrib/sendmail/src/bf_portable.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 1999 Sendmail, Inc. and its suppliers.
- * All rights reserved.
- *
- * By using this file, you agree to the terms and conditions set
- * forth in the LICENSE file which can be found at the top level of
- * the sendmail distribution.
- *
- * $Id: bf_portable.h,v 8.6 1999/11/04 19:31:25 ca Exp $
- *
- * Contributed by Exactis.com, Inc.
- *
- */
-
-#ifndef BF_PORTABLE_H
-#define BF_PORTABLE_H 1
-/*
-** This implementation will behave differently from the Torek-based code in
-** the following major ways:
-** - The buffer size argument to bfopen() will be sent in, sent back,
-** queried, lost, found, subjected to public inquiry, lost again, and
-** finally buried in soft peat and recycled as firelighters.
-** - Errors in creating the file (but not necessarily writing to it) will
-** always be detected and reported synchronously with the bfopen()
-*/
-
-/* Linked structure for storing information about each buffered file */
-struct bf
-{
- FILE *bf_key; /* Unused except as a key for lookup */
- bool bf_committed; /* buffered file is on disk */
- char *bf_filename; /* Name of disk file */
- int bf_refcount; /* Reference count */
- struct bf *bf_cdr;
-};
-
-/*
-** Access routines for looking up bf structures
-**
-** maybe replace with a faster data structure later
-*/
-
-extern void bfinsert __P((struct bf *));
-extern struct bf *bflookup __P((FILE *));
-extern struct bf *bfdelete __P((FILE *));
-#endif /* BF_PORTABLE_H */
diff --git a/contrib/sendmail/src/bf_torek.c b/contrib/sendmail/src/bf_torek.c
deleted file mode 100644
index f74aecd..0000000
--- a/contrib/sendmail/src/bf_torek.c
+++ /dev/null
@@ -1,831 +0,0 @@
-/*
- * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers.
- * All rights reserved.
- *
- * By using this file, you agree to the terms and conditions set
- * forth in the LICENSE file which can be found at the top level of
- * the sendmail distribution.
- *
- * Contributed by Exactis.com, Inc.
- *
- */
-
-#ifndef lint
-static char id[] = "@(#)$Id: bf_torek.c,v 8.19.18.6 2001/05/08 06:52:19 gshapiro Exp $";
-#endif /* ! lint */
-
-#if SFIO
- ERROR README: Can not use bf_torek.c with SFIO.
-#endif /* SFIO */
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#ifdef BF_STANDALONE
-# define sm_free free
-# define xalloc malloc
-#else /* BF_STANDALONE */
-# include "sendmail.h"
-#endif /* BF_STANDALONE */
-#include "bf_torek.h"
-#include "bf.h"
-
- /*
-** BFOPEN -- create a new buffered file
-**
-** Parameters:
-** filename -- the file's name
-** fmode -- what mode the file should be created as
-** bsize -- amount of buffer space to allocate (may be 0)
-** flags -- if running under sendmail, passed directly to safeopen
-**
-** Returns:
-** a FILE * which may then be used with stdio functions, or NULL
-** on failure. FILE * is opened for writing (mode "w+").
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** ENOMEM -- out of memory
-** ENOENT -- illegal empty filename specified
-** any value of errno specified by open()
-** any value of errno specified by fdopen()
-** any value of errno specified by funopen()
-*/
-
-#ifdef BF_STANDALONE
-# define OPEN(fn, omode, cmode, sff) open(fn, omode, cmode)
-#else /* BF_STANDALONE */
-# define OPEN(fn, omode, cmode, sff) safeopen(fn, omode, cmode, sff)
-#endif /* BF_STANDALONE */
-
-FILE *
-bfopen(filename, fmode, bsize, flags)
- char *filename;
- int fmode;
- size_t bsize;
- long flags;
-{
- struct bf *bfp;
- FILE *retval;
- int save_errno, l;
- struct stat st;
-
- /* Sanity checks */
- /* Empty filename string */
- if (*filename == '\0')
- {
- errno = ENOENT;
- return NULL;
- }
-
- if (stat(filename, &st) == 0)
- {
- /* file already exists on disk */
- errno = EEXIST;
- return NULL;
- }
-
- /* Allocate memory */
- bfp = (struct bf *)xalloc(sizeof(struct bf));
- if (bfp == NULL)
- {
- errno = ENOMEM;
- return NULL;
- }
-
- /* A zero bsize is valid, just don't allocate memory */
- if (bsize > 0)
- {
- bfp->bf_buf = (char *)xalloc(bsize);
- if (bfp->bf_buf == NULL)
- {
- sm_free(bfp);
- errno = ENOMEM;
- return NULL;
- }
- }
- else
- bfp->bf_buf = NULL;
-
- /* Nearly home free, just set all the parameters now */
- bfp->bf_committed = FALSE;
- bfp->bf_ondisk = FALSE;
- bfp->bf_refcount = 1;
- bfp->bf_flags = flags;
- bfp->bf_bufsize = bsize;
- bfp->bf_buffilled = 0;
- l = strlen(filename) + 1;
- bfp->bf_filename = (char *)xalloc(l);
- if (bfp->bf_filename == NULL)
- {
- if (bfp->bf_buf != NULL)
- sm_free(bfp->bf_buf);
- sm_free(bfp);
- errno = ENOMEM;
- return NULL;
- }
- (void) strlcpy(bfp->bf_filename, filename, l);
- bfp->bf_filemode = fmode;
- bfp->bf_offset = 0;
- bfp->bf_size = 0;
-
- if (tTd(58, 8))
- dprintf("bfopen(%s, %d)\n", filename, bsize);
-
- /* The big test: will funopen accept it? */
- retval = funopen((void *)bfp, _bfread, _bfwrite, _bfseek, _bfclose);
- if (retval == NULL)
- {
- /* Just in case free() sets errno */
- save_errno = errno;
- sm_free(bfp->bf_filename);
- if (bfp->bf_buf != NULL)
- sm_free(bfp->bf_buf);
- sm_free(bfp);
- errno = save_errno;
- return NULL;
- }
- else
- {
- /* Success */
- return retval;
- }
-}
- /*
-** BFDUP -- increase refcount on buffered file
-**
-** Parameters:
-** fp -- FILE * to "duplicate"
-**
-** Returns:
-** If file is memory buffered, fp with increased refcount
-** If file is on disk, NULL (need to use link())
-*/
-
-FILE *
-bfdup(fp)
- FILE *fp;
-{
- struct bf *bfp;
-
- /* If called on a normal FILE *, noop */
- if (!bftest(fp))
- return NULL;
-
- /* Get associated bf structure */
- bfp = (struct bf *)fp->_cookie;
-
- /* Increase ref count */
- bfp->bf_refcount++;
-
- return fp;
-}
-
- /*
-** BFCOMMIT -- "commits" the buffered file
-**
-** Parameters:
-** fp -- FILE * to commit to disk
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** Forces the given FILE * to be written to disk if it is not
-** already, and ensures that it will be kept after closing. If
-** fp is not a buffered file, this is a no-op.
-**
-** Sets errno:
-** any value of errno specified by open()
-** any value of errno specified by write()
-** any value of errno specified by lseek()
-*/
-
-int
-bfcommit(fp)
- FILE *fp;
-{
- struct bf *bfp;
- int retval;
- int byteswritten;
-
- /* If called on a normal FILE *, noop */
- if (!bftest(fp))
- return 0;
-
- /* Get associated bf structure */
- bfp = (struct bf *)fp->_cookie;
-
- /* If already committed, noop */
- if (bfp->bf_committed)
- return 0;
-
- /* Do we need to open a file? */
- if (!bfp->bf_ondisk)
- {
- struct stat st;
-
- if (tTd(58, 8))
- dprintf("bfcommit(%s): to disk\n", bfp->bf_filename);
-
- if (stat(bfp->bf_filename, &st) == 0)
- {
- errno = EEXIST;
- return -1;
- }
-
- retval = OPEN(bfp->bf_filename, O_RDWR | O_CREAT | O_TRUNC,
- bfp->bf_filemode, bfp->bf_flags);
-
- /* Couldn't create file: failure */
- if (retval < 0)
- {
- /* errno is set implicitly by open() */
- return -1;
- }
-
- bfp->bf_disk_fd = retval;
- bfp->bf_ondisk = TRUE;
- }
-
- /* Write out the contents of our buffer, if we have any */
- if (bfp->bf_buffilled > 0)
- {
- byteswritten = 0;
-
- if (lseek(bfp->bf_disk_fd, 0, SEEK_SET) < 0)
- {
- /* errno is set implicitly by lseek() */
- return -1;
- }
-
- while (byteswritten < bfp->bf_buffilled)
- {
- retval = write(bfp->bf_disk_fd,
- bfp->bf_buf + byteswritten,
- bfp->bf_buffilled - byteswritten);
- if (retval < 0)
- {
- /* errno is set implicitly by write() */
- return -1;
- }
- else
- byteswritten += retval;
- }
- }
- bfp->bf_committed = TRUE;
-
- /* Invalidate buf; all goes to file now */
- bfp->bf_buffilled = 0;
- if (bfp->bf_bufsize > 0)
- {
- /* Don't need buffer anymore; free it */
- bfp->bf_bufsize = 0;
- sm_free(bfp->bf_buf);
- }
- return 0;
-}
-
- /*
-** BFREWIND -- rewinds the FILE *
-**
-** Parameters:
-** fp -- FILE * to rewind
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** rewinds the FILE * and puts it into read mode. Normally one
-** would bfopen() a file, write to it, then bfrewind() and
-** fread(). If fp is not a buffered file, this is equivalent to
-** rewind().
-**
-** Sets errno:
-** any value of errno specified by fseek()
-*/
-
-int
-bfrewind(fp)
- FILE *fp;
-{
- int err;
-
- /* check to see if there is an error on the stream */
- err = ferror(fp);
- (void) fflush(fp);
-
- /*
- ** Clear error if tried to fflush()
- ** a read-only file pointer and
- ** there wasn't a previous error.
- */
-
- if (err == 0)
- clearerr(fp);
-
- /* errno is set implicitly by fseek() before return */
- return fseek(fp, 0, SEEK_SET);
-}
-
- /*
-** BFTRUNCATE -- rewinds and truncates the FILE *
-**
-** Parameters:
-** fp -- FILE * to truncate
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Side Effects:
-** rewinds the FILE *, truncates it to zero length, and puts it
-** into write mode. If fp is not a buffered file, this is
-** equivalent to a rewind() and then an ftruncate(fileno(fp), 0).
-**
-** Sets errno:
-** any value of errno specified by fseek()
-** any value of errno specified by ftruncate()
-*/
-
-int
-bftruncate(fp)
- FILE *fp;
-{
- struct bf *bfp;
-
- if (bfrewind(fp) < 0)
- return -1;
-
- if (bftest(fp))
- {
- /* Get bf structure */
- bfp = (struct bf *)fp->_cookie;
- bfp->bf_buffilled = 0;
- bfp->bf_size = 0;
-
- /* Need to zero the buffer */
- if (bfp->bf_bufsize > 0)
- memset(bfp->bf_buf, '\0', bfp->bf_bufsize);
- if (bfp->bf_ondisk)
- return ftruncate(bfp->bf_disk_fd, 0);
- else
- return 0;
- }
- else
- return ftruncate(fileno(fp), 0);
-}
-
- /*
-** BFFSYNC -- fsync the fd associated with the FILE *
-**
-** Parameters:
-** fp -- FILE * to fsync
-**
-** Returns:
-** 0 on success, -1 on error
-**
-** Sets errno:
-** EINVAL if FILE * not bfcommitted yet.
-** any value of errno specified by fsync()
-*/
-
-int
-bffsync(fp)
- FILE *fp;
-{
- int fd;
- struct bf *bfp;
-
- if (bftest(fp))
- {
- /* Get bf structure */
- bfp = (struct bf *)fp->_cookie;
-
- if (bfp->bf_ondisk && bfp->bf_committed)
- fd = bfp->bf_disk_fd;
- else
- fd = -1;
- }
- else
- fd = fileno(fp);
-
- if (tTd(58, 10))
- dprintf("bffsync: fd = %d\n", fd);
-
- if (fd < 0)
- {
- errno = EINVAL;
- return -1;
- }
- return fsync(fd);
-}
-
- /*
-** BFCLOSE -- close a buffered file
-**
-** Parameters:
-** fp -- FILE * to close
-**
-** Returns:
-** 0 on success, EOF on failure
-**
-** Side Effects:
-** Closes fp. If fp is a buffered file, unlink it if it has not
-** already been committed. If fp is not a buffered file, this is
-** equivalent to fclose().
-**
-** Sets errno:
-** any value of errno specified by fclose()
-*/
-
-int
-bfclose(fp)
- FILE *fp;
-{
- struct bf *bfp;
-
- /* If called on a normal FILE *, call fclose() on it */
- if (!bftest(fp))
- return fclose(fp);
-
- /* Cast cookie back to correct type */
- bfp = (struct bf *)fp->_cookie;
-
- /* Check reference count to see if we actually want to close */
- if (bfp != NULL && --bfp->bf_refcount > 0)
- return 0;
-
- /*
- ** In this implementation, just call fclose--the _bfclose
- ** routine will be called by that
- */
-
- return fclose(fp);
-}
-
- /*
-** BFTEST -- test if a FILE * is a buffered file
-**
-** Parameters:
-** fp -- FILE * to test
-**
-** Returns:
-** TRUE if fp is a buffered file, FALSE otherwise.
-**
-** Side Effects:
-** none.
-**
-** Sets errno:
-** never.
-*/
-
-bool
-bftest(fp)
- FILE *fp;
-{
- /*
- ** Check to see if our special I/O routines are installed
- ** in this file structure
- */
-
- return ((fp->_close == _bfclose) &&
- (fp->_read == _bfread) &&
- (fp->_seek == _bfseek) &&
- (fp->_write == _bfwrite));
-}
-
- /*
-** _BFCLOSE -- close a buffered file
-**
-** Parameters:
-** cookie -- cookie of file to close
-**
-** Returns:
-** 0 to indicate success
-**
-** Side Effects:
-** deletes backing file, frees memory.
-**
-** Sets errno:
-** never.
-*/
-
-int
-_bfclose(cookie)
- void *cookie;
-{
- struct bf *bfp;
-
- /* Cast cookie back to correct type */
- bfp = (struct bf *)cookie;
-
- /* Need to clean up the file */
- if (bfp->bf_ondisk && !bfp->bf_committed)
- unlink(bfp->bf_filename);
-
- /* Need to free the buffer */
- if (bfp->bf_bufsize > 0)
- sm_free(bfp->bf_buf);
-
- /* Finally, free the structure */
- sm_free(bfp);
-
- return 0;
-}
-
- /*
-** _BFREAD -- read a buffered file
-**
-** Parameters:
-** cookie -- cookie of file to read
-** buf -- buffer to fill
-** nbytes -- how many bytes to read
-**
-** Returns:
-** number of bytes read or -1 indicate failure
-**
-** Side Effects:
-** none.
-**
-*/
-
-int
-_bfread(cookie, buf, nbytes)
- void *cookie;
- char *buf;
- int nbytes;
-{
- struct bf *bfp;
- int count = 0; /* Number of bytes put in buf so far */
- int retval;
-
- /* Cast cookie back to correct type */
- bfp = (struct bf *)cookie;
-
- if (bfp->bf_offset < bfp->bf_buffilled)
- {
- /* Need to grab some from buffer */
- count = nbytes;
- if ((bfp->bf_offset + count) > bfp->bf_buffilled)
- count = bfp->bf_buffilled - bfp->bf_offset;
-
- memcpy(buf, bfp->bf_buf + bfp->bf_offset, count);
- }
-
- if ((bfp->bf_offset + nbytes) > bfp->bf_buffilled)
- {
- /* Need to grab some from file */
-
- if (!bfp->bf_ondisk)
- {
- /* Oops, the file doesn't exist. EOF. */
- goto finished;
- }
-
- /* Catch a read() on an earlier failed write to disk */
- if (bfp->bf_disk_fd < 0)
- {
- errno = EIO;
- return -1;
- }
-
- if (lseek(bfp->bf_disk_fd,
- bfp->bf_offset + count, SEEK_SET) < 0)
- {
- if ((errno == EINVAL) || (errno == ESPIPE))
- {
- /*
- ** stdio won't be expecting these
- ** errnos from read()! Change them
- ** into something it can understand.
- */
-
- errno = EIO;
- }
- return -1;
- }
-
- while (count < nbytes)
- {
- retval = read(bfp->bf_disk_fd,
- buf + count,
- nbytes - count);
- if (retval < 0)
- {
- /* errno is set implicitly by read() */
- return -1;
- }
- else if (retval == 0)
- goto finished;
- else
- count += retval;
- }
- }
-
-finished:
- bfp->bf_offset += count;
- return count;
-}
-
- /*
-** _BFSEEK -- seek to a position in a buffered file
-**
-** Parameters:
-** cookie -- cookie of file to seek
-** offset -- position to seek to
-** whence -- how to seek
-**
-** Returns:
-** new file offset or -1 indicate failure
-**
-** Side Effects:
-** none.
-**
-*/
-
-fpos_t
-_bfseek(cookie, offset, whence)
- void *cookie;
- fpos_t offset;
- int whence;
-
-{
- struct bf *bfp;
-
- /* Cast cookie back to correct type */
- bfp = (struct bf *)cookie;
-
- switch (whence)
- {
- case SEEK_SET:
- bfp->bf_offset = offset;
- break;
-
- case SEEK_CUR:
- bfp->bf_offset += offset;
- break;
-
- case SEEK_END:
- bfp->bf_offset = bfp->bf_size + offset;
- break;
-
- default:
- errno = EINVAL;
- return -1;
- }
- return bfp->bf_offset;
-}
-
- /*
-** _BFWRITE -- write to a buffered file
-**
-** Parameters:
-** cookie -- cookie of file to write
-** buf -- data buffer
-** nbytes -- how many bytes to write
-**
-** Returns:
-** number of bytes written or -1 indicate failure
-**
-** Side Effects:
-** may create backing file if over memory limit for file.
-**
-*/
-
-int
-_bfwrite(cookie, buf, nbytes)
- void *cookie;
- const char *buf;
- int nbytes;
-{
- struct bf *bfp;
- int count = 0; /* Number of bytes written so far */
- int retval;
-
- /* Cast cookie back to correct type */
- bfp = (struct bf *)cookie;
-
- /* If committed, go straight to disk */
- if (bfp->bf_committed)
- {
- if (lseek(bfp->bf_disk_fd, bfp->bf_offset, SEEK_SET) < 0)
- {
- if ((errno == EINVAL) || (errno == ESPIPE))
- {
- /*
- ** stdio won't be expecting these
- ** errnos from write()! Change them
- ** into something it can understand.
- */
-
- errno = EIO;
- }
- return -1;
- }
-
- count = write(bfp->bf_disk_fd, buf, nbytes);
- if (count < 0)
- {
- /* errno is set implicitly by write() */
- return -1;
- }
- goto finished;
- }
-
- if (bfp->bf_offset < bfp->bf_bufsize)
- {
- /* Need to put some in buffer */
- count = nbytes;
- if ((bfp->bf_offset + count) > bfp->bf_bufsize)
- count = bfp->bf_bufsize - bfp->bf_offset;
-
- memcpy(bfp->bf_buf + bfp->bf_offset, buf, count);
- if ((bfp->bf_offset + count) > bfp->bf_buffilled)
- bfp->bf_buffilled = bfp->bf_offset + count;
- }
-
- if ((bfp->bf_offset + nbytes) > bfp->bf_bufsize)
- {
- /* Need to put some in file */
- if (!bfp->bf_ondisk)
- {
- /* Oops, the file doesn't exist. */
- if (tTd(58, 8))
- dprintf("_bfwrite(%s): to disk\n",
- bfp->bf_filename);
-
- retval = OPEN(bfp->bf_filename,
- O_RDWR | O_CREAT | O_TRUNC,
- bfp->bf_filemode, bfp->bf_flags);
-
- /* Couldn't create file: failure */
- if (retval < 0)
- {
- /*
- ** stdio may not be expecting these
- ** errnos from write()! Change to
- ** something which it can understand.
- ** Note that ENOSPC and EDQUOT are saved
- ** because they are actually valid for
- ** write().
- */
-
- if (!((errno == ENOSPC) || (errno == EDQUOT)))
- errno = EIO;
-
- return -1;
- }
- bfp->bf_disk_fd = retval;
- bfp->bf_ondisk = TRUE;
- }
-
- /* Catch a write() on an earlier failed write to disk */
- if (bfp->bf_ondisk && bfp->bf_disk_fd < 0)
- {
- errno = EIO;
- return -1;
- }
-
- if (lseek(bfp->bf_disk_fd,
- bfp->bf_offset + count, SEEK_SET) < 0)
- {
- if ((errno == EINVAL) || (errno == ESPIPE))
- {
- /*
- ** stdio won't be expecting these
- ** errnos from write()! Change them into
- ** something which it can understand.
- */
-
- errno = EIO;
- }
- return -1;
- }
-
- while (count < nbytes)
- {
- retval = write(bfp->bf_disk_fd, buf + count,
- nbytes - count);
- if (retval < 0)
- {
- /* errno is set implicitly by write() */
- return -1;
- }
- else
- count += retval;
- }
- }
-
-finished:
- bfp->bf_offset += count;
- if (bfp->bf_offset > bfp->bf_size)
- bfp->bf_size = bfp->bf_offset;
- return count;
-}
diff --git a/contrib/sendmail/src/bf_torek.h b/contrib/sendmail/src/bf_torek.h
deleted file mode 100644
index 48c3995..0000000
--- a/contrib/sendmail/src/bf_torek.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 1999 Sendmail, Inc. and its suppliers.
- * All rights reserved.
- *
- * By using this file, you agree to the terms and conditions set
- * forth in the LICENSE file which can be found at the top level of
- * the sendmail distribution.
- *
- * $Id: bf_torek.h,v 8.6 1999/11/04 19:31:25 ca Exp $
- *
- * Contributed by Exactis.com, Inc.
- *
- */
-
-#ifndef BF_TOREK_H
-#define BF_TOREK_H 1
-/*
-** Data structure for storing information about each buffered file
-*/
-
-struct bf
-{
- bool bf_committed; /* Has this buffered file been committed? */
- bool bf_ondisk; /* On disk: committed or buffer overflow */
- int bf_flags;
- int bf_disk_fd; /* If on disk, associated file descriptor */
- char *bf_buf; /* Memory buffer */
- int bf_bufsize; /* Length of above buffer */
- int bf_buffilled; /* Bytes of buffer actually filled */
- char *bf_filename; /* Name of buffered file, if ever committed */
- mode_t bf_filemode; /* Mode of buffered file, if ever committed */
- fpos_t bf_offset; /* Currect file offset */
- int bf_size; /* Total current size of file */
- int bf_refcount; /* Reference count */
-};
-
-/* Our lower-level I/O routines */
-extern int _bfclose __P((void *));
-extern int _bfread __P((void *, char *, int));
-extern fpos_t _bfseek __P((void *, fpos_t, int));
-extern int _bfwrite __P((void *, const char *, int));
-#endif /* BF_TOREK_H */
diff --git a/contrib/sendmail/src/clock.c b/contrib/sendmail/src/clock.c
deleted file mode 100644
index 0e3ec94..0000000
--- a/contrib/sendmail/src/clock.c
+++ /dev/null
@@ -1,513 +0,0 @@
-/*
- * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
- * All rights reserved.
- * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * By using this file, you agree to the terms and conditions set
- * forth in the LICENSE file which can be found at the top level of
- * the sendmail distribution.
- *
- */
-
-#ifndef lint
-static char id[] = "@(#)$Id: clock.c,v 8.52.18.18 2001/08/14 16:07:04 ca Exp $";
-#endif /* ! lint */
-
-#include <sendmail.h>
-
-#ifndef sigmask
-# define sigmask(s) (1 << ((s) - 1))
-#endif /* ! sigmask */
-
-static SIGFUNC_DECL sm_tick __P((int));
-static void endsleep __P((void));
-
-
-/*
-** SETEVENT -- set an event to happen at a specific time.
-**
-** Events are stored in a sorted list for fast processing.
-** An event only applies to the process that set it.
-**
-** Parameters:
-** intvl -- intvl until next event occurs.
-** func -- function to call on event.
-** arg -- argument to func on event.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** none.
-*/
-
-static EVENT *volatile EventQueue; /* head of event queue */
-static EVENT *volatile FreeEventList; /* list of free events */
-
-EVENT *
-setevent(intvl, func, arg)
- time_t intvl;
- void (*func)();
- int arg;
-{
- register EVENT *ev;
-
- if (intvl <= 0)
- {
- syserr("554 5.3.0 setevent: intvl=%ld\n", intvl);
- return NULL;
- }
-
- ENTER_CRITICAL();
- if (FreeEventList == NULL)
- {
- FreeEventList = (EVENT *) xalloc(sizeof *FreeEventList);
- FreeEventList->ev_link = NULL;
- }
- LEAVE_CRITICAL();
-
- ev = sigsafe_setevent(intvl, func, arg);
-
- if (tTd(5, 5))
- dprintf("setevent: intvl=%ld, for=%ld, func=%lx, arg=%d, ev=%lx\n",
- (long) intvl, (long) (curtime() + intvl),
- (u_long) func, arg,
- ev == NULL ? 0 : (u_long) ev);
-
- return ev;
-}
-
-/*
-**
-** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
-** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
-** DOING.
-*/
-
-EVENT *
-sigsafe_setevent(intvl, func, arg)
- time_t intvl;
- void (*func)();
- int arg;
-{
- register EVENT **evp;
- register EVENT *ev;
- auto time_t now;
- int wasblocked;
-
- if (intvl <= 0)
- return NULL;
-
- wasblocked = blocksignal(SIGALRM);
- now = curtime();
-
- /* search event queue for correct position */
- for (evp = (EVENT **) (&EventQueue);
- (ev = *evp) != NULL;
- evp = &ev->ev_link)
- {
- if (ev->ev_time >= now + intvl)
- break;
- }
-
- ENTER_CRITICAL();
- if (FreeEventList == NULL)
- {
- /*
- ** This shouldn't happen. If called from setevent(),
- ** we have just malloced a FreeEventList entry. If
- ** called from a signal handler, it should have been
- ** from an existing event which sm_tick() just added to the
- ** FreeEventList.
- */
-
- LEAVE_CRITICAL();
- return NULL;
- }
- else
- {
- ev = FreeEventList;
- FreeEventList = ev->ev_link;
- }
- LEAVE_CRITICAL();
-
- /* insert new event */
- ev->ev_time = now + intvl;
- ev->ev_func = func;
- ev->ev_arg = arg;
- ev->ev_pid = getpid();
- ENTER_CRITICAL();
- ev->ev_link = *evp;
- *evp = ev;
- LEAVE_CRITICAL();
-
- (void) setsignal(SIGALRM, sm_tick);
- intvl = EventQueue->ev_time - now;
- (void) alarm((unsigned) intvl < 1 ? 1 : intvl);
- if (wasblocked == 0)
- (void) releasesignal(SIGALRM);
- return ev;
-}
- /*
-** CLREVENT -- remove an event from the event queue.
-**
-** Parameters:
-** ev -- pointer to event to remove.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** arranges for event ev to not happen.
-*/
-
-void
-clrevent(ev)
- register EVENT *ev;
-{
- register EVENT **evp;
- int wasblocked;
-
- if (tTd(5, 5))
- dprintf("clrevent: ev=%lx\n", (u_long) ev);
- if (ev == NULL)
- return;
-
- /* find the parent event */
- wasblocked = blocksignal(SIGALRM);
- for (evp = (EVENT **) (&EventQueue);
- *evp != NULL;
- evp = &(*evp)->ev_link)
- {
- if (*evp == ev)
- break;
- }
-
- /* now remove it */
- if (*evp != NULL)
- {
- ENTER_CRITICAL();
- *evp = ev->ev_link;
- ev->ev_link = FreeEventList;
- FreeEventList = ev;
- LEAVE_CRITICAL();
- }
-
- /* restore clocks and pick up anything spare */
- if (wasblocked == 0)
- (void) releasesignal(SIGALRM);
- if (EventQueue != NULL)
- (void) kill(getpid(), SIGALRM);
- else
- {
- /* nothing left in event queue, no need for an alarm */
- (void) alarm(0);
- }
-}
- /*
-** CLEAR_EVENTS -- remove all events from the event queue.
-**
-** Parameters:
-** none.
-**
-** Returns:
-** none.
-*/
-
-void
-clear_events()
-{
- register EVENT *ev;
- int wasblocked;
-
- if (tTd(5, 5))
- dprintf("clear_events: EventQueue=%lx\n", (u_long) EventQueue);
-
- if (EventQueue == NULL)
- return;
-
- /* nothing will be left in event queue, no need for an alarm */
- (void) alarm(0);
- wasblocked = blocksignal(SIGALRM);
-
- /* find the end of the EventQueue */
- for (ev = EventQueue; ev->ev_link != NULL; ev = ev->ev_link)
- continue;
-
- ENTER_CRITICAL();
- ev->ev_link = FreeEventList;
- FreeEventList = EventQueue;
- EventQueue = NULL;
- LEAVE_CRITICAL();
-
- /* restore clocks and pick up anything spare */
- if (wasblocked == 0)
- (void) releasesignal(SIGALRM);
-}
- /*
-** SM_TICK -- take a clock sm_tick
-**
-** Called by the alarm clock. This routine runs events as needed.
-** Always called as a signal handler, so we assume that SIGALRM
-** has been blocked.
-**
-** Parameters:
-** One that is ignored; for compatibility with signal handlers.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** calls the next function in EventQueue.
-**
-** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
-** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
-** DOING.
-*/
-
-/* ARGSUSED */
-static SIGFUNC_DECL
-sm_tick(sig)
- int sig;
-{
- register time_t now;
- register EVENT *ev;
- pid_t mypid;
- int save_errno = errno;
-
- (void) alarm(0);
-
- FIX_SYSV_SIGNAL(sig, sm_tick);
-
- errno = save_errno;
- CHECK_CRITICAL(sig);
-
- mypid = getpid();
- while (PendingSignal != 0)
- {
- int sigbit = 0;
- int sig = 0;
-
- if (bitset(PEND_SIGHUP, PendingSignal))
- {
- sigbit = PEND_SIGHUP;
- sig = SIGHUP;
- }
- else if (bitset(PEND_SIGINT, PendingSignal))
- {
- sigbit = PEND_SIGINT;
- sig = SIGINT;
- }
- else if (bitset(PEND_SIGTERM, PendingSignal))
- {
- sigbit = PEND_SIGTERM;
- sig = SIGTERM;
- }
- else if (bitset(PEND_SIGUSR1, PendingSignal))
- {
- sigbit = PEND_SIGUSR1;
- sig = SIGUSR1;
- }
- else
- {
- /* If we get here, we are in trouble */
- abort();
- }
- PendingSignal &= ~sigbit;
- kill(mypid, sig);
- }
-
- now = curtime();
- if (tTd(5, 4))
- dprintf("sm_tick: now=%ld\n", (long) now);
-
- while ((ev = EventQueue) != NULL &&
- (ev->ev_time <= now || ev->ev_pid != mypid))
- {
- void (*f)();
- int arg;
- pid_t pid;
-
- /* process the event on the top of the queue */
- ENTER_CRITICAL();
- ev = EventQueue;
- EventQueue = EventQueue->ev_link;
- LEAVE_CRITICAL();
- if (tTd(5, 6))
- dprintf("sm_tick: ev=%lx, func=%lx, arg=%d, pid=%d\n",
- (u_long) ev, (u_long) ev->ev_func,
- ev->ev_arg, ev->ev_pid);
-
- /* we must be careful in here because ev_func may not return */
- f = ev->ev_func;
- arg = ev->ev_arg;
- pid = ev->ev_pid;
- ENTER_CRITICAL();
- ev->ev_link = FreeEventList;
- FreeEventList = ev;
- LEAVE_CRITICAL();
- if (pid != mypid)
- continue;
- if (EventQueue != NULL)
- {
- if (EventQueue->ev_time > now)
- (void) alarm((unsigned) (EventQueue->ev_time - now));
- else
- (void) alarm(3);
- }
-
- /* call ev_func */
- errno = save_errno;
- (*f)(arg);
- (void) alarm(0);
- now = curtime();
- }
- if (EventQueue != NULL)
- (void) alarm((unsigned) (EventQueue->ev_time - now));
- errno = save_errno;
- return SIGFUNC_RETURN;
-}
- /*
-** PEND_SIGNAL -- Add a signal to the pending signal list
-**
-** Parameters:
-** sig -- signal to add
-**
-** Returns:
-** none.
-**
-** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
-** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
-** DOING.
-*/
-
-void
-pend_signal(sig)
- int sig;
-{
- int sigbit;
- int save_errno = errno;
-
- /*
- ** Don't want to interrupt something critical, hence delay
- ** the alarm for one second. Hopefully, by then we
- ** will be out of the critical section. If not, then
- ** we will just delay again. The events to be run will
- ** still all be run, maybe just a little bit late.
- */
-
- switch (sig)
- {
- case SIGHUP:
- sigbit = PEND_SIGHUP;
- break;
-
- case SIGINT:
- sigbit = PEND_SIGINT;
- break;
-
- case SIGTERM:
- sigbit = PEND_SIGTERM;
- break;
-
- case SIGUSR1:
- sigbit = PEND_SIGUSR1;
- break;
-
- case SIGALRM:
- /* don't have to pend these */
- sigbit = 0;
- break;
-
- default:
- /* If we get here, we are in trouble */
- abort();
-
- /* NOTREACHED */
- /* shut up stupid compiler warning on HP-UX 11 */
- sigbit = 0;
- break;
- }
-
- if (sigbit != 0)
- PendingSignal |= sigbit;
- (void) setsignal(SIGALRM, sm_tick);
- (void) alarm(1);
- errno = save_errno;
-}
- /*
-** SM_SIGNAL_NOOP -- A signal no-op function
-**
-** Parameters:
-** sig -- signal received
-**
-** Returns:
-** SIGFUNC_RETURN
-*/
-
-/* ARGSUSED */
-SIGFUNC_DECL
-sm_signal_noop(sig)
- int sig;
-{
- int save_errno = errno;
-
- FIX_SYSV_SIGNAL(sig, sm_signal_noop);
- errno = save_errno;
- return SIGFUNC_RETURN;
-}
- /*
-** SLEEP -- a version of sleep that works with this stuff
-**
-** Because sleep uses the alarm facility, I must reimplement
-** it here.
-**
-** Parameters:
-** intvl -- time to sleep.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** waits for intvl time. However, other events can
-** be run during that interval.
-*/
-
-
-static bool volatile SleepDone;
-
-#ifndef SLEEP_T
-# define SLEEP_T unsigned int
-#endif /* ! SLEEP_T */
-
-SLEEP_T
-sleep(intvl)
- unsigned int intvl;
-{
- int was_held;
-
- if (intvl == 0)
- return (SLEEP_T) 0;
- SleepDone = FALSE;
- (void) setevent((time_t) intvl, endsleep, 0);
- was_held = releasesignal(SIGALRM);
- while (!SleepDone)
- (void) pause();
- if (was_held > 0)
- (void) blocksignal(SIGALRM);
- return (SLEEP_T) 0;
-}
-
-static void
-endsleep()
-{
- /*
- ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
- ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
- ** DOING.
- */
-
- SleepDone = TRUE;
-}
OpenPOWER on IntegriCloud