LCOV - code coverage report
Current view: top level - src - bu.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 47 52 90.4 %
Date: 2019-11-30 11:33:35 Functions: 8 8 100.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "alloc.h"
       3             : #include "bu.h"
       4             : #include "prepend.h"
       5             : 
       6        1312 : struct bu *bu_alloc(void)
       7             : {
       8        1312 :         return (struct bu *)calloc_w(1, sizeof(struct bu), __func__);
       9             : }
      10             : 
      11        1197 : int bu_init(struct bu *bu, char *fullpath, char *basename,
      12             :         char *timestampstr, uint16_t flags)
      13             : {
      14        1197 :         if(!(bu->data=prepend_s(fullpath, "data"))
      15        1197 :           || !(bu->delta=prepend_s(fullpath, "deltas.reverse")))
      16             :                 goto error;
      17        1197 :         bu->path=fullpath;
      18        1197 :         bu->basename=basename;
      19        1197 :         bu->timestamp=timestampstr;
      20        1197 :         bu->flags=flags;
      21        1197 :         bu->bno=strtoul(timestampstr, NULL, 10);
      22        1197 :         return 0;
      23             : error:
      24           0 :         free_w(&bu->data);
      25           0 :         free_w(&bu->delta);
      26           0 :         return -1;
      27             : }
      28             : 
      29        1312 : static void bu_free_content(struct bu *bu)
      30             : {
      31        1312 :         if(!bu) return;
      32        1312 :         free_w(&bu->path);
      33        1312 :         free_w(&bu->basename);
      34        1312 :         free_w(&bu->data);
      35        1312 :         free_w(&bu->delta);
      36        1312 :         free_w(&bu->timestamp);
      37             : }
      38             : 
      39        1312 : void bu_free(struct bu **bu)
      40             : {
      41        1312 :         if(!bu || !*bu) return;
      42        1312 :         bu_free_content(*bu);
      43        1312 :         free_v((void **)bu);
      44             : }
      45             : 
      46         470 : void bu_list_free(struct bu **bu_list)
      47             : {
      48             :         struct bu *bu;
      49             :         struct bu *next;
      50         470 :         struct bu *prev=NULL;
      51         470 :         if(*bu_list) prev=(*bu_list)->prev;
      52        1672 :         for(bu=*bu_list; bu; bu=next)
      53             :         {
      54        1202 :                 next=bu->next;
      55        1202 :                 bu_free(&bu);
      56             :         }
      57             :         // Do it in both directions.
      58         520 :         for(bu=prev; bu; bu=prev)
      59             :         {
      60          50 :                 prev=bu->prev;
      61          50 :                 bu_free(&bu);
      62             :         }
      63         470 :         *bu_list=NULL;
      64         470 : }
      65             : 
      66          66 : static struct bu *bu_find(struct bu *bu, uint16_t flag)
      67             : {
      68          66 :         struct bu *cbu=NULL;
      69          66 :         if(!bu) return NULL;
      70          57 :         if(bu->flags & flag) return bu;
      71             :         // Search in both directions.
      72          21 :         if(bu->next)
      73           0 :                 for(cbu=bu; cbu; cbu=cbu->next)
      74           0 :                         if(cbu->flags & flag) return cbu;
      75          21 :         if(bu->prev)
      76          45 :                 for(cbu=bu; cbu; cbu=cbu->prev)
      77          51 :                         if(cbu->flags & flag) return cbu;
      78             :         return cbu;
      79             : }
      80             : 
      81          39 : struct bu *bu_find_current(struct bu *bu)
      82             : {
      83          39 :         return bu_find(bu, BU_CURRENT);
      84             : }
      85             : 
      86          15 : struct bu *bu_find_working_or_finishing(struct bu *bu)
      87             : {
      88          15 :         struct bu *cbu=NULL;
      89          15 :         if((cbu=bu_find(bu, BU_WORKING))) return cbu;
      90          12 :         return bu_find(bu, BU_FINISHING);
      91             : }

Generated by: LCOV version 1.13