xref: /illumos-gate/usr/src/cmd/sendmail/libsm/fwalk.c (revision 2a8bcb4e)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1993
5*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * This code is derived from software contributed to Berkeley by
8*7c478bd9Sstevel@tonic-gate  * Chris Torek.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
11*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
12*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
16*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: fwalk.c,v 1.19 2001/03/02 03:22:18 ca Exp $")
17*7c478bd9Sstevel@tonic-gate #include <errno.h>
18*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
19*7c478bd9Sstevel@tonic-gate #include "local.h"
20*7c478bd9Sstevel@tonic-gate #include "glue.h"
21*7c478bd9Sstevel@tonic-gate 
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate **  SM_FWALK -- apply a function to all found-open file pointers
24*7c478bd9Sstevel@tonic-gate **
25*7c478bd9Sstevel@tonic-gate **	Parameters:
26*7c478bd9Sstevel@tonic-gate **		function -- a function vector to be applied
27*7c478bd9Sstevel@tonic-gate **		timeout -- time to complete actions (milliseconds)
28*7c478bd9Sstevel@tonic-gate **
29*7c478bd9Sstevel@tonic-gate **	Returns:
30*7c478bd9Sstevel@tonic-gate **		The (binary) OR'd result of each function call
31*7c478bd9Sstevel@tonic-gate */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate int
34*7c478bd9Sstevel@tonic-gate sm_fwalk(function, timeout)
35*7c478bd9Sstevel@tonic-gate 	int (*function) __P((SM_FILE_T *, int *));
36*7c478bd9Sstevel@tonic-gate 	int *timeout;
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	register SM_FILE_T *fp;
39*7c478bd9Sstevel@tonic-gate 	register int n, ret;
40*7c478bd9Sstevel@tonic-gate 	register struct sm_glue *g;
41*7c478bd9Sstevel@tonic-gate 	int fptimeout;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 	ret = 0;
44*7c478bd9Sstevel@tonic-gate 	for (g = &smglue; g != NULL; g = g->gl_next)
45*7c478bd9Sstevel@tonic-gate 	{
46*7c478bd9Sstevel@tonic-gate 		for (fp = g->gl_iobs, n = g->gl_niobs; --n >= 0; fp++)
47*7c478bd9Sstevel@tonic-gate 		{
48*7c478bd9Sstevel@tonic-gate 			if (fp->f_flags != 0)
49*7c478bd9Sstevel@tonic-gate 			{
50*7c478bd9Sstevel@tonic-gate 				if (*timeout == SM_TIME_DEFAULT)
51*7c478bd9Sstevel@tonic-gate 					fptimeout = fp->f_timeout;
52*7c478bd9Sstevel@tonic-gate 				else
53*7c478bd9Sstevel@tonic-gate 					fptimeout = *timeout;
54*7c478bd9Sstevel@tonic-gate 				if (fptimeout == SM_TIME_IMMEDIATE)
55*7c478bd9Sstevel@tonic-gate 					continue; /* skip it */
56*7c478bd9Sstevel@tonic-gate 				ret |= (*function)(fp, &fptimeout);
57*7c478bd9Sstevel@tonic-gate 			}
58*7c478bd9Sstevel@tonic-gate 		}
59*7c478bd9Sstevel@tonic-gate 	}
60*7c478bd9Sstevel@tonic-gate 	return ret;
61*7c478bd9Sstevel@tonic-gate }
62