LCOV - code coverage report
Current view: top level - shared - libmount-util.h (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 18 20 90.0 %
Date: 2019-08-23 13:36:53 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 18 77.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : #pragma once
       3                 :            : 
       4                 :            : #include <stdio.h>
       5                 :            : 
       6                 :            : /* This needs to be after sys/mount.h */
       7                 :            : #include <libmount.h>
       8                 :            : 
       9                 :            : #include "macro.h"
      10                 :            : 
      11         [ +  + ]:        160 : DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table);
      12         [ +  + ]:        160 : DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter);
      13                 :            : 
      14                 :         76 : static inline int libmount_parse(
      15                 :            :                 const char *path,
      16                 :            :                 FILE *source,
      17                 :            :                 struct libmnt_table **ret_table,
      18                 :            :                 struct libmnt_iter **ret_iter) {
      19                 :            : 
      20                 :         76 :         _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
      21                 :         76 :         _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
      22                 :            :         int r;
      23                 :            : 
      24                 :            :         /* Older libmount seems to require this. */
      25   [ +  +  -  + ]:         76 :         assert(!source || path);
      26                 :            : 
      27                 :         76 :         table = mnt_new_table();
      28                 :         76 :         iter = mnt_new_iter(MNT_ITER_FORWARD);
      29   [ +  -  -  + ]:         76 :         if (!table || !iter)
      30                 :          0 :                 return -ENOMEM;
      31                 :            : 
      32                 :            :         /* If source or path are specified, we use on the functions which ignore utab.
      33                 :            :          * Only if both are empty, we use mnt_table_parse_mtab(). */
      34                 :            : 
      35         [ +  + ]:         76 :         if (source)
      36                 :         16 :                 r = mnt_table_parse_stream(table, source, path);
      37         [ +  + ]:         60 :         else if (path)
      38                 :         12 :                 r = mnt_table_parse_file(table, path);
      39                 :            :         else
      40                 :         48 :                 r = mnt_table_parse_mtab(table, NULL);
      41         [ -  + ]:         76 :         if (r < 0)
      42                 :          0 :                 return r;
      43                 :            : 
      44                 :         76 :         *ret_table = TAKE_PTR(table);
      45                 :         76 :         *ret_iter = TAKE_PTR(iter);
      46                 :         76 :         return 0;
      47                 :            : }

Generated by: LCOV version 1.14