X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/fwd/blobdiff_plain/755e6619263d316dc46fa504e0c333c963ec8eaa..57ceb980e3c55306f3f70f92604703abf132cf27:/target.c diff --git a/target.c b/target.c new file mode 100644 index 0000000..5590761 --- /dev/null +++ b/target.c @@ -0,0 +1,60 @@ +/* -*-c-*- + * + * Common functionality for targets + * + * (c) 2018 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of the `fwd' port forwarder. + * + * `fwd' 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. + * + * `fwd' 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 `fwd'. If not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/*----- Header files ------------------------------------------------------*/ + +#include "fwd.h" + +/*----- Main code ---------------------------------------------------------*/ + +/* --- @target_inc@ --- * + * + * Arguments: @target *t@ = pointer to a source + * + * Returns: --- + * + * Use: Increments a target's refcount. + */ + +void target_inc(target *t) { t->ref++; } + +/* --- @target_dec@ --- * + * + * Arguments: @target *t@ = pointer to a target + * + * Returns: --- + * + * Use: Decrements a target's refcount, destroying it if necessary. + */ + +void target_dec(target *t) +{ + assert(t->ref > 0); + t->ref--; + if (!t->ref) t->ops->destroy(t); +} + +/*----- That's all, folks -------------------------------------------------*/