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