/* -*-c-*-
*
- * $Id: key-io.c,v 1.5 2003/10/17 16:30:46 mdw Exp $
+ * $Id$
*
* Adding new keys to a key file
*
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: key-io.c,v $
- * Revision 1.5 2003/10/17 16:30:46 mdw
- * Report errors if key files don't exist!
- *
- * Revision 1.4 2001/02/03 11:57:38 mdw
- * Allow creating keyfiles with no file attached.
- *
- * Revision 1.3 2001/01/20 11:56:48 mdw
- * Use mLib exported tuning parameters for hashtable.
- *
- * Revision 1.2 2000/02/12 18:21:02 mdw
- * Overhaul of key management (again).
- *
- * Revision 1.1 1999/12/22 15:47:48 mdw
- * Major key-management revision.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <ctype.h>
if (err == KERR_DUPTAG) {
if (rep)
rep(file, line, "duplicate key tag stripped", arg);
- free(k->tag);
+ xfree(k->tag);
k->tag = 0;
goto again;
}
skip_3:
if (k->tag)
- free(k->tag);
- free(k->type);
+ xfree(k->tag);
+ xfree(k->type);
skip_2:
key_destroy(&k->k);
skip_1:
return (0);
}
-/* --- @key_close@ --- *
+/* --- @key_discard@ --- *
*
* Arguments: @key_file *f@ = pointer to key file block
*
- * Returns: A @KWRITE_@ code indicating how it went.
+ * Returns: ---
*
- * Use: Frees all the key data, writes any changes. Make sure that
- * all hell breaks loose if this returns @KWRITE_BROKEN@.
+ * Use: Frees all the key data, without writing changes.
*/
-int key_close(key_file *f)
+int key_discard(key_file *f)
{
- int e;
hash_base *b;
hash_iter i;
- if (f->fp && (e = key_save(f)) != KWRITE_OK)
- return (e);
-
/* --- Free all the individual keys --- */
for (hash_mkiter(&i, &f->byid); (b = hash_next(&i)) != 0; ) {
key *k = (key *)b;
key_destroy(&k->k);
- free(k->type);
- free(k->tag);
+ xfree(k->type);
+ xfree(k->tag);
if (k->c)
- free(k->c);
+ xfree(k->c);
for (sym_mkiter(&j, &k->a); (a = sym_next(&j)) != 0; )
- free(a->p);
+ xfree(a->p);
sym_destroy(&k->a);
DESTROY(k);
}
if (f->fp)
fclose(f->fp);
- free(f->name);
+ xfree(f->name);
+}
+
+/* --- @key_close@ --- *
+ *
+ * Arguments: @key_file *f@ = pointer to key file block
+ *
+ * Returns: A @KWRITE_@ code indicating how it went.
+ *
+ * Use: Frees all the key data, writes any changes. Make sure that
+ * all hell breaks loose if this returns @KWRITE_BROKEN@.
+ */
+
+int key_close(key_file *f)
+{
+ int e;
+
+ if (f->fp && (e = key_save(f)) != KWRITE_OK)
+ return (e);
+ key_discard(f);
return (KWRITE_OK);
}
if ((e = insert(f, k)) == 0)
f->f |= KF_MODIFIED;
else {
- free(k->type);
+ xfree(k->type);
DESTROY(k);
k = 0;
}