3 * File handles in resource pools
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
34 /*----- Main code ---------------------------------------------------------*/
36 /* --- @pool_fopen@ --- *
38 * Arguments: @pool *p@ = pointer to a pool
39 * @const char *file@ = name of the file to open
40 * @const char *how@ = string specifying opening parameters
42 * Returns: A pointer to a pool resource containing an open file handle,
43 * or null if the file open filed.
45 * Use: Opens a file so that it will be freed again when a pool is
49 static void pf_destroy(pool_resource *r) { pool_fclose((pool_file *)r); }
51 pool_file *pool_fopen(pool *p, const char *file, const char *how)
56 if ((fp = fopen(file, how)) == 0)
58 pf = pool_alloc(p, sizeof(pool_file));
59 POOL_ADD(p, &pf->r, pf_destroy);
64 /* --- @pool_fclose@ --- *
66 * Arguments: @pool_file *pf@ = pointer to a file resource
68 * Returns: The response from the @fclose@ function.
70 * Use: Closes a file. It is not an error to close a file multiple
74 int pool_fclose(pool_file *pf)
79 return (fclose(pf->fp));
82 /*----- That's all, folks -------------------------------------------------*/