chiark / gitweb /
Source code reorganization:
[disorder] / lib / sink.c
index 245ee26b6761261126a7acb38d12bf4a236839fe..925bb013c7cf74abf0146d1846d815fa5b05f9ec 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2004 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @brief Abstract output sink type
  */
 
-#include <config.h>
-#include "types.h"
+#include "common.h"
 
-#include <stdio.h>
 #include <stdarg.h>
-#include <string.h>
 #include <errno.h>
 
 #include "mem.h"
@@ -131,6 +128,38 @@ struct sink *sink_dynstr(struct dynstr *output) {
   return (struct sink *)s;
 }
 
+/* discard sink **************************************************************/
+
+static int sink_discard_write(struct sink attribute((unused)) *s,
+                             const void attribute((unused)) *buffer,
+                             int nbytes) {
+  return nbytes;
+}
+
+/** @brief Return a sink which discards all output */
+struct sink *sink_discard(void) {
+  struct sink *s = xmalloc(sizeof *s);
+
+  s->write = sink_discard_write;
+  return s;
+}
+
+/* error sink **************************************************************/
+
+static int sink_error_write(struct sink attribute((unused)) *s,
+                           const void attribute((unused)) *buffer,
+                           int attribute((unused)) nbytes) {
+  return -1;
+}
+
+/** @brief Return a sink which discards all output */
+struct sink *sink_error(void) {
+  struct sink *s = xmalloc(sizeof *s);
+
+  s->write = sink_error_write;
+  return s;
+}
+
 /*
 Local Variables:
 c-basic-offset:2