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

Generated by: LCOV version 1.13