Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

null.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: null.c,v 1.14 2006/01/11 14:19:21 tat Exp $
00009  */
00010 
00011 #include "klone_conf.h"
00012 #include <u/libu.h>
00013 #include <klone/codec.h>
00014 #include <klone/cnull.h>
00015 #include <klone/utils.h>
00016 
00022 struct codec_null_s
00023 {
00024     codec_t codec;
00025 };
00026 
00027 typedef struct codec_null_s codec_null_t;
00028 
00029 static ssize_t null_flush(codec_t *cn, char *dst, size_t *dcount)
00030 {
00031     u_unused_args(cn, dst);
00032     *dcount = 0;
00033     return CODEC_FLUSH_COMPLETE;
00034 }
00035 
00036 static ssize_t null_transform(codec_t *cn, char *dst, size_t *dcount, 
00037         const char *src, size_t src_sz)
00038 {
00039     ssize_t wr;
00040     
00041     dbg_err_if (src == NULL);
00042     dbg_err_if (dst == NULL);
00043     dbg_err_if (dcount == NULL || *dcount == 0);
00044     dbg_err_if (src_sz == 0);
00045 
00046     u_unused_args(cn);
00047 
00048     wr = MIN(src_sz, *dcount); 
00049     memcpy(dst, src, wr);
00050     *dcount = wr;
00051 
00052     dbg_err_if(wr == 0);
00053     return wr;
00054 err:
00055     return -1;
00056 }
00057 
00058 static int null_free(codec_t *cn)
00059 {
00060     U_FREE(cn);
00061 
00062     return 0;
00063 }
00064 
00074 int codec_null_create(codec_t **pcn)
00075 {
00076     codec_null_t *cn = NULL;
00077 
00078     dbg_return_if (pcn == NULL, ~0);
00079 
00080     cn = u_zalloc(sizeof(codec_null_t));
00081     dbg_err_if(cn == NULL);
00082 
00083     cn->codec.transform = null_transform;
00084     cn->codec.flush = null_flush;
00085     cn->codec.free = null_free;      
00086 
00087     *pcn = (codec_t*)cn;
00088 
00089     return 0;
00090 err:
00091     U_FREE(cn);
00092     return ~0;
00093 }
00094 

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved