fwalk.c revision 266692
1168404Spjd/* 2168404Spjd * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers. 3168404Spjd * All rights reserved. 4168404Spjd * Copyright (c) 1990, 1993 5185029Spjd * The Regents of the University of California. All rights reserved. 6185029Spjd * 7168404Spjd * This code is derived from software contributed to Berkeley by 8168404Spjd * Chris Torek. 9168404Spjd * 10168404Spjd * By using this file, you agree to the terms and conditions set 11168404Spjd * forth in the LICENSE file which can be found at the top level of 12168404Spjd * the sendmail distribution. 13168404Spjd */ 14168404Spjd 15168404Spjd#include <sm/gen.h> 16168404SpjdSM_RCSID("@(#)$Id: fwalk.c,v 1.22 2013-11-22 20:51:43 ca Exp $") 17168404Spjd#include <errno.h> 18168404Spjd#include <sm/io.h> 19168404Spjd#include "local.h" 20168404Spjd#include "glue.h" 21168404Spjd 22219089Spjd/* 23168404Spjd** SM_FWALK -- apply a function to all found-open file pointers 24168404Spjd** 25168404Spjd** Parameters: 26168404Spjd** function -- a function vector to be applied 27219089Spjd** timeout -- time to complete actions (milliseconds) 28219089Spjd** 29219089Spjd** Returns: 30219089Spjd** The (binary) OR'd result of each function call 31219089Spjd*/ 32168404Spjd 33168404Spjdint 34168404Spjdsm_fwalk(function, timeout) 35168404Spjd int (*function) __P((SM_FILE_T *, int *)); 36219089Spjd int *timeout; 37219089Spjd{ 38168404Spjd register SM_FILE_T *fp; 39219089Spjd register int n, ret; 40219089Spjd register struct sm_glue *g; 41219089Spjd int fptimeout; 42168404Spjd 43219089Spjd ret = 0; 44219089Spjd for (g = &smglue; g != NULL; g = g->gl_next) 45219089Spjd { 46219089Spjd for (fp = g->gl_iobs, n = g->gl_niobs; --n >= 0; fp++) 47219089Spjd { 48219089Spjd if (fp->f_flags != 0) 49219089Spjd { 50219089Spjd if (*timeout == SM_TIME_DEFAULT) 51219089Spjd fptimeout = fp->f_timeout; 52219089Spjd else 53219089Spjd fptimeout = *timeout; 54168404Spjd if (fptimeout == SM_TIME_IMMEDIATE) 55 continue; /* skip it */ 56 ret |= (*function)(fp, &fptimeout); 57 } 58 } 59 } 60 return ret; 61} 62