3 * $Id: pool-file.c,v 1.1 2000/07/16 12:28:48 mdw Exp $
5 * File handles in resource pools
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
32 * $Log: pool-file.c,v $
33 * Revision 1.1 2000/07/16 12:28:48 mdw
34 * Support for resource pools, based on the Apache model.
38 /*----- Header files ------------------------------------------------------*/
44 /*----- Main code ---------------------------------------------------------*/
46 /* --- @pool_fopen@ --- *
48 * Arguments: @pool *p@ = pointer to a pool
49 * @const char *file@ = name of the file to open
50 * @const char *how@ = string specifying opening parameters
52 * Returns: A pointer to a pool resource containing an open file handle,
53 * or null if the file open filed.
55 * Use: Opens a file so that it will be freed again when a pool is
59 static void pf_destroy(pool_resource *r) { pool_fclose((pool_file *)r); }
61 pool_file *pool_fopen(pool *p, const char *file, const char *how)
66 if ((fp = fopen(file, how)) == 0)
68 pf = pool_alloc(p, sizeof(pool_file));
69 POOL_ADD(p, &pf->r, pf_destroy);
74 /* --- @pool_fclose@ --- *
76 * Arguments: @pool_file *pf@ = pointer to a file resource
78 * Returns: The response from the @fclose@ function.
80 * Use: Closes a file. It is not an error to close a file multiple
84 int pool_fclose(pool_file *pf)
89 return (fclose(pf->fp));
92 /*----- That's all, folks -------------------------------------------------*/