LTP GCOV extension - code coverage report
Current view: directory - src - vstr_dup.c
Test: Vstr coverage
Date: 2005-01-10 Instrumented lines: 55
Code covered: 100.0 % Executed lines: 55

       1                 : #define VSTR_DUP_C
       2                 : /*
       3                 :  *  Copyright (C) 1999, 2000, 2001, 2002, 2003  James Antill
       4                 :  *
       5                 :  *  This library is free software; you can redistribute it and/or
       6                 :  *  modify it under the terms of the GNU Lesser General Public
       7                 :  *  License as published by the Free Software Foundation; either
       8                 :  *  version 2 of the License, or (at your option) any later version.
       9                 :  *
      10                 :  *  This library is distributed in the hope that it will be useful,
      11                 :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :  *  Lesser General Public License for more details.
      14                 :  *
      15                 :  *  You should have received a copy of the GNU Lesser General Public
      16                 :  *  License along with this library; if not, write to the Free Software
      17                 :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      18                 :  *
      19                 :  *  email: james@and.org
      20                 :  */
      21                 : /* These are similar to strdup(), for Vstr ... with 1.0.10 it might be
      22                 :  * useful to create temp. strings with them. */
      23                 : #include "main.h"
      24                 : 
      25                 : Vstr_base *vstr_dup_buf(Vstr_conf *conf, const void *data, size_t len)
      26             481 : {
      27             481 :   Vstr_base *ret = vstr_make_base(conf);
      28                 : 
      29             481 :   if (!ret)
      30               4 :     goto make_base_fail;
      31                 : 
      32             477 :   if (len && !vstr_add_buf(ret, 0, data, len))
      33               2 :     goto add_vstr_fail;
      34                 : 
      35             475 :   return (ret);
      36                 : 
      37                 :  add_vstr_fail:
      38               2 :   vstr_free_base(ret);
      39                 :  make_base_fail:
      40                 : 
      41               6 :   return (NULL);
      42                 : }
      43                 : 
      44                 : Vstr_base *vstr_dup_non(Vstr_conf *conf, size_t len)
      45              10 : {
      46              10 :   Vstr_base *ret = vstr_make_base(conf);
      47                 : 
      48              10 :   if (!ret)
      49               4 :     goto make_base_fail;
      50                 : 
      51               6 :   if (len && !vstr_add_non(ret, 0, len))
      52               1 :     goto add_vstr_fail;
      53                 : 
      54               5 :   return (ret);
      55                 : 
      56                 :  add_vstr_fail:
      57               1 :   vstr_free_base(ret);
      58                 :  make_base_fail:
      59                 : 
      60               5 :   return (NULL);
      61                 : }
      62                 : 
      63                 : Vstr_base *vstr_dup_ptr(Vstr_conf *conf, const void *data, size_t len)
      64             697 : {
      65             697 :   Vstr_base *ret = vstr_make_base(conf);
      66                 : 
      67             697 :   if (!ret)
      68               4 :     goto make_base_fail;
      69                 : 
      70             693 :   if (len && !vstr_add_ptr(ret, 0, data, len))
      71               1 :     goto add_vstr_fail;
      72                 : 
      73             692 :   return (ret);
      74                 : 
      75                 :  add_vstr_fail:
      76               1 :   vstr_free_base(ret);
      77                 :  make_base_fail:
      78                 : 
      79               5 :   return (NULL);
      80                 : }
      81                 : 
      82                 : Vstr_base *vstr_dup_ref(Vstr_conf *conf,
      83                 :                         Vstr_ref *ref, size_t off, size_t len)
      84              25 : {
      85              25 :   Vstr_base *ret = vstr_make_base(conf);
      86                 : 
      87              25 :   if (!ret)
      88               4 :     goto make_base_fail;
      89                 : 
      90              21 :   if (len && !vstr_add_ref(ret, 0, ref, off, len))
      91               1 :     goto add_vstr_fail;
      92                 : 
      93              20 :   return (ret);
      94                 : 
      95                 :  add_vstr_fail:
      96               1 :   vstr_free_base(ret);
      97                 :  make_base_fail:
      98                 : 
      99               5 :   return (NULL);
     100                 : }
     101                 : 
     102                 : Vstr_base *vstr_dup_vstr(Vstr_conf *conf,
     103                 :                          const Vstr_base *base, size_t pos, size_t len,
     104                 :                          unsigned int type)
     105            1872 : {
     106            1872 :   Vstr_base *ret = vstr_make_base(conf);
     107                 : 
     108            1872 :   if (!ret)
     109             270 :     goto make_base_fail;
     110                 : 
     111            1602 :   if (len && !vstr_add_vstr(ret, 0, base, pos, len, type))
     112             312 :     goto add_vstr_fail;
     113                 : 
     114            1290 :   return (ret);
     115                 : 
     116                 :  add_vstr_fail:
     117             312 :   vstr_free_base(ret);
     118                 :  make_base_fail:
     119             582 :   base->conf->malloc_bad = TRUE;
     120                 : 
     121             582 :   return (NULL);
     122                 : }
     123                 : 
     124                 : Vstr_base *vstr_dup_rep_chr(Vstr_conf *conf, char chr, size_t len)
     125              50 : {
     126              50 :   Vstr_base *ret = vstr_make_base(conf);
     127                 : 
     128              50 :   if (!ret)
     129               4 :     goto make_base_fail;
     130                 : 
     131              46 :   if (len && !vstr_add_rep_chr(ret, 0, chr, len))
     132               1 :     goto add_vstr_fail;
     133                 : 
     134              45 :   return (ret);
     135                 : 
     136                 :  add_vstr_fail:
     137               1 :   vstr_free_base(ret);
     138                 :  make_base_fail:
     139                 : 
     140               5 :   return (NULL);
     141                 : }

Generated by: LTP GCOV extension version 1.1