--- /dev/null
+/* -*-c-*-
+ *
+ * $Id: reffd.c,v 1.1 1999/07/26 23:33:01 mdw Exp $
+ *
+ * Reference counted file descriptors
+ *
+ * (c) 1999 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of the `fw' port forwarder.
+ *
+ * `fw' is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * `fw' is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with `fw'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------*
+ *
+ * $Log: reffd.c,v $
+ * Revision 1.1 1999/07/26 23:33:01 mdw
+ * Infrastructure for the new design.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <mLib/sub.h>
+
+#include "reffd.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @reffd_init@ --- *
+ *
+ * Arguments: @int fd@ = file descriptor
+ *
+ * Returns: Reference-counted file descriptor object.
+ *
+ * Use: Creates a refcounted file descriptor.
+ */
+
+reffd *reffd_init(int fd)
+{
+ reffd *r = CREATE(reffd);
+ r->fd = fd;
+ r->ref = 1;
+ r->proc = 0;
+ r->p = 0;
+ return (r);
+}
+
+/* --- @reffd_handler@ --- *
+ *
+ * Arguments: @reffd *r@ = pointer to reference counted filehandle
+ * @void (*proc)(void *p)@ = procedure to call
+ * @void *p@
+ *
+ * Returns: ---
+ *
+ * Use: Sets the reference counted file descriptor to call @proc@
+ * when it is no longer required.
+ */
+
+void reffd_handler(reffd *r, void (*proc)(void *p), void *p)
+{
+ r->proc = proc;
+ r->p = p;
+}
+
+/* --- @reffd_inc@ --- *
+ *
+ * Arguments: @reffd *r@ = pointer to reference counted filehandle
+ *
+ * Returns: ---
+ *
+ * Use: Increments the reference count for a file descriptor.
+ */
+
+void reffd_inc(reffd *r) { REFFD_INC(r); }
+
+/* --- @reffd_dec@ --- *
+ *
+ * Arguments: @reffd *r@ = pointer to reference counted filehandle
+ *
+ * Returns: ---
+ *
+ * Use: Decrements the reference count for a file descriptor.
+ */
+
+void reffd_dec(reffd *r) { REFFD_DEC(r); }
+
+/*----- That's all, folks -------------------------------------------------*/