LCOV - code coverage report
Current view: top level - lib/dpkg - fsys-iter.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 39.4 % 33 13
Test Date: 2024-07-17 02:53:43 Functions: 50.0 % 6 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25.0 % 8 2

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * libdpkg - Debian packaging suite library routines
       3                 :             :  * fsys-iter.c - filesystem nodes iterators
       4                 :             :  *
       5                 :             :  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :             :  * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@debian.org>
       7                 :             :  * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
       8                 :             :  *
       9                 :             :  * This is free software; you can redistribute it and/or modify
      10                 :             :  * it under the terms of the GNU General Public License as published by
      11                 :             :  * the Free Software Foundation; either version 2 of the License, or
      12                 :             :  * (at your option) any later version.
      13                 :             :  *
      14                 :             :  * This is distributed in the hope that it will be useful,
      15                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17                 :             :  * GNU General Public License for more details.
      18                 :             :  *
      19                 :             :  * You should have received a copy of the GNU General Public License
      20                 :             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21                 :             :  */
      22                 :             : 
      23                 :             : #include <config.h>
      24                 :             : #include <compat.h>
      25                 :             : 
      26                 :             : #include <stdlib.h>
      27                 :             : 
      28                 :             : #include <dpkg/dpkg.h>
      29                 :             : #include <dpkg/dpkg-db.h>
      30                 :             : #include <dpkg/pkg-list.h>
      31                 :             : 
      32                 :             : #include "fsys.h"
      33                 :             : 
      34                 :             : /*
      35                 :             :  * Reverse iterator.
      36                 :             :  */
      37                 :             : 
      38                 :             : /*
      39                 :             :  * Initializes an iterator that appears to go through the file list ‘files’
      40                 :             :  * in reverse order, returning the namenode from each. What actually happens
      41                 :             :  * is that we walk the list here, building up a reverse list, and then peel
      42                 :             :  * it apart one entry at a time.
      43                 :             :  */
      44                 :             : void
      45                 :           0 : fsys_hash_rev_iter_init(struct fsys_hash_rev_iter *iter,
      46                 :             :                         struct fsys_namenode_list *files)
      47                 :             : {
      48                 :             :         struct fsys_namenode_list *newent;
      49                 :             : 
      50                 :           0 :         iter->todo = NULL;
      51         [ #  # ]:           0 :         while (files) {
      52                 :           0 :                 newent = m_malloc(sizeof(*newent));
      53                 :           0 :                 newent->namenode = files->namenode;
      54                 :           0 :                 newent->next = iter->todo;
      55                 :           0 :                 iter->todo = newent;
      56                 :           0 :                 files = files->next;
      57                 :             :         }
      58                 :           0 : }
      59                 :             : 
      60                 :             : struct fsys_namenode *
      61                 :           0 : fsys_hash_rev_iter_next(struct fsys_hash_rev_iter *iter)
      62                 :             : {
      63                 :             :         struct fsys_namenode *next;
      64                 :             :         struct fsys_namenode_list *todo;
      65                 :             : 
      66                 :           0 :         todo = iter->todo;
      67         [ #  # ]:           0 :         if (!todo)
      68                 :           0 :                 return NULL;
      69                 :           0 :         next = todo->namenode;
      70                 :           0 :         iter->todo = todo->next;
      71                 :           0 :         free(todo);
      72                 :             : 
      73                 :           0 :         return next;
      74                 :             : }
      75                 :             : 
      76                 :             : /*
      77                 :             :  * Clients must call this function to clean up the fsys_hash_rev_iter
      78                 :             :  * if they wish to break out of the iteration before it is all done.
      79                 :             :  * Calling this function is not necessary if fsys_hash_rev_iter_next() has
      80                 :             :  * been called until it returned 0.
      81                 :             :  */
      82                 :             : void
      83                 :           0 : fsys_hash_rev_iter_abort(struct fsys_hash_rev_iter *iter)
      84                 :             : {
      85         [ #  # ]:           0 :         while (fsys_hash_rev_iter_next(iter))
      86                 :             :                 ;
      87                 :           0 : }
      88                 :             : 
      89                 :             : /*
      90                 :             :  * Iterator for packages owning a file.
      91                 :             :  */
      92                 :             : 
      93                 :             : struct fsys_node_pkgs_iter {
      94                 :             :         struct pkg_list *pkg_node;
      95                 :             : };
      96                 :             : 
      97                 :             : struct fsys_node_pkgs_iter *
      98                 :           7 : fsys_node_pkgs_iter_new(struct fsys_namenode *fnn)
      99                 :             : {
     100                 :             :         struct fsys_node_pkgs_iter *iter;
     101                 :             : 
     102                 :           7 :         iter = m_malloc(sizeof(*iter));
     103                 :           7 :         iter->pkg_node = fnn->packages;
     104                 :             : 
     105                 :           7 :         return iter;
     106                 :             : }
     107                 :             : 
     108                 :             : struct pkginfo *
     109                 :           7 : fsys_node_pkgs_iter_next(struct fsys_node_pkgs_iter *iter)
     110                 :             : {
     111                 :             :         struct pkg_list *pkg_node;
     112                 :             : 
     113         [ +  + ]:           7 :         if (iter->pkg_node == NULL)
     114                 :           6 :                 return NULL;
     115                 :             : 
     116                 :           1 :         pkg_node = iter->pkg_node;
     117                 :           1 :         iter->pkg_node = pkg_node->next;
     118                 :             : 
     119                 :           1 :         return pkg_node->pkg;
     120                 :             : }
     121                 :             : 
     122                 :             : void
     123                 :           7 : fsys_node_pkgs_iter_free(struct fsys_node_pkgs_iter *iter)
     124                 :             : {
     125                 :           7 :         free(iter);
     126                 :           7 : }
        

Generated by: LCOV version 2.0-1