null.c

00001 /*
00002  * Copyright (c) 2005-2012 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.15 2007/10/26 08:57:59 tho 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 
00017 
00018 struct codec_null_s
00019 {
00020     codec_t codec;
00021 };
00022 
00023 typedef struct codec_null_s codec_null_t;
00024 
00025 static ssize_t null_flush(codec_t *cn, char *dst, size_t *dcount)
00026 {
00027     u_unused_args(cn, dst);
00028     *dcount = 0;
00029     return CODEC_FLUSH_COMPLETE;
00030 }
00031 
00032 static ssize_t null_transform(codec_t *cn, char *dst, size_t *dcount, 
00033         const char *src, size_t src_sz)
00034 {
00035     ssize_t wr;
00036     
00037     dbg_err_if (src == NULL);
00038     dbg_err_if (dst == NULL);
00039     dbg_err_if (dcount == NULL || *dcount == 0);
00040     dbg_err_if (src_sz == 0);
00041 
00042     u_unused_args(cn);
00043 
00044     wr = U_MIN(src_sz, *dcount); 
00045     memcpy(dst, src, wr);
00046     *dcount = wr;
00047 
00048     dbg_err_if(wr == 0);
00049     return wr;
00050 err:
00051     return -1;
00052 }
00053 
00054 static int null_free(codec_t *cn)
00055 {
00056     U_FREE(cn);
00057 
00058     return 0;
00059 }
00060 
00075 int codec_null_create(codec_t **pcn)
00076 {
00077     codec_null_t *cn = NULL;
00078 
00079     dbg_return_if (pcn == NULL, ~0);
00080 
00081     cn = u_zalloc(sizeof(codec_null_t));
00082     dbg_err_if(cn == NULL);
00083 
00084     cn->codec.transform = null_transform;
00085     cn->codec.flush = null_flush;
00086     cn->codec.free = null_free;      
00087 
00088     *pcn = (codec_t*)cn;
00089 
00090     return 0;
00091 err:
00092     U_FREE(cn);
00093     return ~0;
00094 }
00095 

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