LCOV - code coverage report
Current view: top level - spdk/lib/util - file.c (source / functions) Hit Total Coverage
Test: Combined Lines: 14 22 63.6 %
Date: 2024-07-11 13:28:34 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 8 37.5 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2015 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/file.h"
       7                 :            : 
       8                 :            : void *
       9                 :       1601 : spdk_posix_file_load(FILE *file, size_t *size)
      10                 :            : {
      11                 :       1601 :         uint8_t *newbuf, *buf = NULL;
      12                 :       1601 :         size_t rc, buf_size, cur_size = 0;
      13                 :            : 
      14                 :       1601 :         *size = 0;
      15                 :       1601 :         buf_size = 128 * 1024;
      16                 :            : 
      17         [ +  - ]:       1601 :         while (buf_size <= 1024 * 1024 * 1024) {
      18                 :       1601 :                 newbuf = realloc(buf, buf_size);
      19         [ -  + ]:       1601 :                 if (newbuf == NULL) {
      20                 :          0 :                         free(buf);
      21                 :          0 :                         return NULL;
      22                 :            :                 }
      23                 :       1601 :                 buf = newbuf;
      24                 :            : 
      25                 :       1601 :                 rc = fread(buf + cur_size, 1, buf_size - cur_size, file);
      26                 :       1601 :                 cur_size += rc;
      27                 :            : 
      28         [ +  - ]:       1601 :                 if (feof(file)) {
      29                 :       1601 :                         *size = cur_size;
      30                 :       1601 :                         return buf;
      31                 :            :                 }
      32                 :            : 
      33         [ #  # ]:          0 :                 if (ferror(file)) {
      34                 :          0 :                         free(buf);
      35                 :          0 :                         return NULL;
      36                 :            :                 }
      37                 :            : 
      38                 :          0 :                 buf_size *= 2;
      39                 :            :         }
      40                 :            : 
      41                 :          0 :         free(buf);
      42                 :          0 :         return NULL;
      43                 :            : }

Generated by: LCOV version 1.14