chan.c (chan_open): Actually initialize the error indicator.
[fwd] / reffd.c
CommitLineData
07d71f34 1/* -*-c-*-
2 *
07d71f34 3 * Reference counted file descriptors
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
206212ca 8/*----- Licensing notice --------------------------------------------------*
07d71f34 9 *
9155ea97 10 * This file is part of the `fwd' port forwarder.
07d71f34 11 *
9155ea97 12 * `fwd' is free software; you can redistribute it and/or modify
07d71f34 13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
206212ca 16 *
9155ea97 17 * `fwd' is distributed in the hope that it will be useful,
07d71f34 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
206212ca 21 *
07d71f34 22 * You should have received a copy of the GNU General Public License
9155ea97 23 * along with `fwd'; if not, write to the Free Software Foundation,
07d71f34 24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
9155ea97 27#include "fwd.h"
07d71f34 28
29/*----- Main code ---------------------------------------------------------*/
30
31/* --- @reffd_init@ --- *
32 *
33 * Arguments: @int fd@ = file descriptor
34 *
35 * Returns: Reference-counted file descriptor object.
36 *
37 * Use: Creates a refcounted file descriptor.
38 */
39
40reffd *reffd_init(int fd)
41{
42 reffd *r = CREATE(reffd);
43 r->fd = fd;
44 r->ref = 1;
45 r->proc = 0;
46 r->p = 0;
47 return (r);
48}
49
50/* --- @reffd_handler@ --- *
51 *
52 * Arguments: @reffd *r@ = pointer to reference counted filehandle
53 * @void (*proc)(void *p)@ = procedure to call
54 * @void *p@
55 *
56 * Returns: ---
57 *
58 * Use: Sets the reference counted file descriptor to call @proc@
59 * when it is no longer required.
60 */
61
62void reffd_handler(reffd *r, void (*proc)(void *p), void *p)
63{
64 r->proc = proc;
65 r->p = p;
66}
67
68/* --- @reffd_inc@ --- *
69 *
70 * Arguments: @reffd *r@ = pointer to reference counted filehandle
71 *
72 * Returns: ---
73 *
74 * Use: Increments the reference count for a file descriptor.
75 */
76
77void reffd_inc(reffd *r) { REFFD_INC(r); }
78
79/* --- @reffd_dec@ --- *
80 *
81 * Arguments: @reffd *r@ = pointer to reference counted filehandle
82 *
83 * Returns: ---
84 *
85 * Use: Decrements the reference count for a file descriptor.
86 */
87
88void reffd_dec(reffd *r) { REFFD_DEC(r); }
89
90/*----- That's all, folks -------------------------------------------------*/