LCOV - code coverage report
Current view: top level - lib/dpkg - utils.c (source / functions) Coverage Total Hit
Test: dpkg 1.22.7-3-g89f48 C code coverage Lines: 88.2 % 17 15
Test Date: 2024-07-17 02:53:43 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80.0 % 10 8

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * libdpkg - Debian packaging suite library routines
       3                 :             :  * utils.c - helper functions for dpkg
       4                 :             :  *
       5                 :             :  * Copyright © 1995, 2008 Ian Jackson <ijackson@chiark.greenend.org.uk>
       6                 :             :  *
       7                 :             :  * This is free software; you can redistribute it and/or modify
       8                 :             :  * it under the terms of the GNU General Public License as published by
       9                 :             :  * the Free Software Foundation; either version 2 of the License, or
      10                 :             :  * (at your option) any later version.
      11                 :             :  *
      12                 :             :  * This is distributed in the hope that it will be useful,
      13                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             :  * GNU General Public License for more details.
      16                 :             :  *
      17                 :             :  * You should have received a copy of the GNU General Public License
      18                 :             :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      19                 :             :  */
      20                 :             : 
      21                 :             : #include <config.h>
      22                 :             : #include <compat.h>
      23                 :             : 
      24                 :             : #include <string.h>
      25                 :             : 
      26                 :             : #include <dpkg/i18n.h>
      27                 :             : #include <dpkg/dpkg.h>
      28                 :             : 
      29                 :             : int
      30                 :         347 : fgets_checked(char *buf, size_t bufsz, FILE *f, const char *fn)
      31                 :             : {
      32                 :             :         int l;
      33                 :             : 
      34         [ +  + ]:         347 :         if (!fgets(buf, bufsz, f)) {
      35         [ -  + ]:          73 :                 if (ferror(f))
      36                 :           0 :                         ohshite(_("read error in '%.250s'"), fn);
      37                 :          73 :                 return -1;
      38                 :             :         }
      39                 :         274 :         l = strlen(buf);
      40         [ -  + ]:         274 :         if (l == 0)
      41                 :           0 :                 ohshit(_("fgets gave an empty string from '%.250s'"), fn);
      42         [ +  + ]:         274 :         if (buf[--l] != '\n')
      43                 :           1 :                 ohshit(_("too-long line or missing newline in '%.250s'"), fn);
      44                 :         273 :         buf[l] = '\0';
      45                 :             : 
      46                 :         273 :         return l;
      47                 :             : }
      48                 :             : 
      49                 :             : int
      50                 :         175 : fgets_must(char *buf, size_t bufsz, FILE *f, const char *fn)
      51                 :             : {
      52                 :         175 :         int l = fgets_checked(buf, bufsz, f, fn);
      53                 :             : 
      54         [ +  + ]:         175 :         if (l < 0)
      55                 :           2 :                 ohshit(_("unexpected end of file reading '%.250s'"), fn);
      56                 :             : 
      57                 :         173 :         return l;
      58                 :             : }
        

Generated by: LCOV version 2.0-1