chiark / gitweb /
@@@ tvec and tty mess
[mLib] / codec / null-codec.c
1 /* -*-c-*-
2  *
3  * Null codec implementation
4  *
5  * (c) 2009 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Library General Public License as
14  * published by the Free Software Foundation; either version 2 of the
15  * License, or (at your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib; if not, write to the Free
24  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include <string.h>
31
32 #include "codec.h"
33 #include "sub.h"
34
35 /*----- Data structures ---------------------------------------------------*/
36
37 typedef struct null_codec {
38   codec c;
39 } null_codec;
40
41 /*----- Main code ---------------------------------------------------------*/
42
43 static int encdec(codec *c, const void *p, size_t sz, dstr *d)
44   { DPUTM(d, p, sz); return (0); }
45
46 static void destroy(codec *c)
47   { null_codec *nc = (null_codec *)c; DESTROY(nc); }
48
49 static const codec_ops ops = { &null_codec_class, encdec, destroy };
50
51 static codec *encoder(unsigned flags, const char *indent, unsigned maxlen)
52 {
53   null_codec *nc;
54
55   NEW(nc);
56   nc->c.ops = &ops;
57   return (&nc->c);
58 }
59
60 static codec *decoder(unsigned flags)
61 {
62   null_codec *nc;
63
64   NEW(nc);
65   nc->c.ops = &ops;
66   return (&nc->c);
67 }
68
69 const codec_class null_codec_class = { "null", encoder, decoder };
70
71 /*----- That's all, folks -------------------------------------------------*/