LCOV - code coverage report
Current view: top level - sql/server - rel_file_loader.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 28 71.4 %
Date: 2024-12-20 20:06:10 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #include "monetdb_config.h"
      14             : #include "rel_file_loader.h"
      15             : 
      16             : #define NR_FILE_LOADERS 255
      17             : static file_loader_t file_loaders[NR_FILE_LOADERS] = { 0 };
      18             : 
      19             : void
      20           0 : fl_exit(void)
      21             : {
      22           0 :         for (int i = 0; i < NR_FILE_LOADERS; i++) {
      23           0 :                 if (file_loaders[i].name)
      24           0 :                         GDKfree(file_loaders[i].name);
      25             :         }
      26           0 : }
      27             : 
      28             : void
      29         957 : fl_unregister(char *name)
      30             : {
      31         957 :         file_loader_t *fl = fl_find(name);
      32         957 :         if (fl) {
      33         957 :                 GDKfree(fl->name);
      34         957 :                 fl->name = NULL;
      35             :         }
      36         957 : }
      37             : 
      38             : int
      39         960 : fl_register(char *name, fl_add_types_fptr add_types, fl_load_fptr load)
      40             : {
      41         960 :         file_loader_t *fl = fl_find(name);
      42         960 :         if (fl) {
      43           0 :                 TRC_WARNING(SQL_TRANS,"file_loader re-registering %s\n", name);
      44           0 :                 GDKfree(fl->name);
      45           0 :                 fl->name = NULL;
      46             :         }
      47             : 
      48        1920 :         for (int i = 0; i < NR_FILE_LOADERS; i++) {
      49        1920 :                 if (file_loaders[i].name == NULL) {
      50         960 :                         file_loaders[i].name = GDKstrdup(name);
      51         960 :                         file_loaders[i].add_types = add_types;
      52         960 :                         file_loaders[i].load = load;
      53         960 :                         return 0;
      54             :                 }
      55             :         }
      56             : 
      57             :         /* all file_loaders array locations are occupied */
      58             :         return -1;      /* could not register file_loader */
      59             : }
      60             : 
      61             : file_loader_t*
      62        1971 : fl_find(char *name)
      63             : {
      64        1971 :         if (!name)
      65             :                 return NULL;
      66      250284 :         for (int i = 0; i < NR_FILE_LOADERS; i++) {
      67      249314 :                 if (file_loaders[i].name && strcmp(file_loaders[i].name, name) == 0)
      68        1001 :                         return file_loaders+i;
      69             :         }
      70             :         return NULL;
      71             : }

Generated by: LCOV version 1.14