3 * $Id: pool-file.c,v 1.2 2004/04/08 01:36:13 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 /*----- Header files ------------------------------------------------------*/
36 /*----- Main code ---------------------------------------------------------*/
38 /* --- @pool_fopen@ --- *
40 * Arguments: @pool *p@ = pointer to a pool
41 * @const char *file@ = name of the file to open
42 * @const char *how@ = string specifying opening parameters
44 * Returns: A pointer to a pool resource containing an open file handle,
45 * or null if the file open filed.
47 * Use: Opens a file so that it will be freed again when a pool is
51 static void pf_destroy(pool_resource
*r
) { pool_fclose((pool_file
*)r
); }
53 pool_file
*pool_fopen(pool
*p
, const char *file
, const char *how
)
58 if ((fp
= fopen(file
, how
)) == 0)
60 pf
= pool_alloc(p
, sizeof(pool_file
));
61 POOL_ADD(p
, &pf
->r
, pf_destroy
);
66 /* --- @pool_fclose@ --- *
68 * Arguments: @pool_file *pf@ = pointer to a file resource
70 * Returns: The response from the @fclose@ function.
72 * Use: Closes a file. It is not an error to close a file multiple
76 int pool_fclose(pool_file
*pf
)
81 return (fclose(pf
->fp
));
84 /*----- That's all, folks -------------------------------------------------*/