LCOV - code coverage report
Current view: top level - glib/girepository/cmph - cmph_structs.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 12 39 30.8 %
Date: 2024-05-07 05:15:23 Functions: 2 4 50.0 %
Branches: 1 20 5.0 %

           Branch data     Line data    Source code
       1                 :            : #include "cmph_structs.h"
       2                 :            : 
       3                 :            : #include <string.h>
       4                 :            : #include <errno.h>
       5                 :            : 
       6                 :            : //#define DEBUG
       7                 :            : #include "debug.h"
       8                 :            : 
       9                 :          3 : cmph_config_t *__config_new(cmph_io_adapter_t *key_source)
      10                 :            : {
      11                 :          3 :         cmph_config_t *mph = (cmph_config_t *)malloc(sizeof(cmph_config_t));
      12                 :          3 :         memset(mph, 0, sizeof(cmph_config_t));
      13         [ -  + ]:          3 :         if (mph == NULL) return NULL;
      14                 :          3 :         mph->key_source = key_source;
      15                 :          3 :         mph->verbosity = 0;
      16                 :          3 :         mph->data = NULL;
      17                 :          3 :         mph->c = 0;
      18                 :          3 :         return mph;
      19                 :            : }
      20                 :            : 
      21                 :          3 : void __config_destroy(cmph_config_t *mph)
      22                 :            : {
      23                 :          3 :         free(mph);
      24                 :          3 : }
      25                 :            : 
      26                 :          0 : void __cmph_dump(cmph_t *mphf, FILE *fd)
      27                 :            : {
      28                 :            :         register size_t nbytes;
      29                 :          0 :         nbytes = fwrite(cmph_names[mphf->algo], (size_t)(strlen(cmph_names[mphf->algo]) + 1), (size_t)1, fd);
      30                 :          0 :         nbytes = fwrite(&(mphf->size), sizeof(mphf->size), (size_t)1, fd);
      31   [ #  #  #  # ]:          0 :         if (nbytes == 0 && ferror(fd)) {
      32                 :          0 :           fprintf(stderr, "ERROR: %s\n", strerror(errno));
      33                 :            :         }
      34                 :          0 : }
      35                 :          0 : cmph_t *__cmph_load(FILE *f) 
      36                 :            : {
      37                 :          0 :         cmph_t *mphf = NULL;
      38                 :            :         cmph_uint32 i;
      39                 :            :         char algo_name[BUFSIZ];
      40                 :          0 :         char *ptr = algo_name;
      41                 :          0 :         CMPH_ALGO algo = CMPH_COUNT;
      42                 :            :         register size_t nbytes;
      43                 :            :         
      44                 :            :         DEBUGP("Loading mphf\n");
      45                 :            :         while(1)
      46                 :          0 :         {
      47                 :          0 :                 size_t c = fread(ptr, (size_t)1, (size_t)1, f);
      48         [ #  # ]:          0 :                 if (c != 1) return NULL;
      49         [ #  # ]:          0 :                 if (*ptr == 0) break;
      50                 :          0 :                 ++ptr;
      51                 :            :         }
      52         [ #  # ]:          0 :         for(i = 0; i < CMPH_COUNT; ++i)
      53                 :            :         {
      54         [ #  # ]:          0 :                 if (strcmp(algo_name, cmph_names[i]) == 0)
      55                 :            :                 {
      56                 :          0 :                         algo = i;
      57                 :            :                 }
      58                 :            :         }
      59         [ #  # ]:          0 :         if (algo == CMPH_COUNT) 
      60                 :            :         {
      61                 :            :                 DEBUGP("Algorithm %s not found\n", algo_name);
      62                 :          0 :                 return NULL;
      63                 :            :         }
      64                 :          0 :         mphf = (cmph_t *)malloc(sizeof(cmph_t));
      65                 :          0 :         mphf->algo = algo;
      66                 :          0 :         nbytes = fread(&(mphf->size), sizeof(mphf->size), (size_t)1, f);
      67                 :          0 :         mphf->data = NULL;
      68                 :            :         DEBUGP("Algorithm is %s and mphf is sized %u\n", cmph_names[algo],  mphf->size);
      69   [ #  #  #  # ]:          0 :         if (nbytes == 0 && ferror(f)) {
      70                 :          0 :           fprintf(stderr, "ERROR: %s\n", strerror(errno));
      71                 :            :         }
      72                 :            : 
      73                 :          0 :         return mphf;
      74                 :            : }
      75                 :            : 
      76                 :            : 

Generated by: LCOV version 1.14