GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/libcvmfs_options.cc
Date: 2025-06-29 02:35:41
Exec Total Coverage
Lines: 21 34 61.8%
Branches: 13 42 31.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * Implements the C wrapper of the OptionsManager
5 */
6
7
8 #include <cassert>
9 #include <cstdlib>
10 #include <cstring>
11 #include <string>
12
13 #include "libcvmfs.h"
14 #include "options.h"
15
16 using namespace std; // NOLINT
17
18
19 81 SimpleOptionsParser *cvmfs_options_clone(SimpleOptionsParser *opts) {
20 SimpleOptionsParser *result = new SimpleOptionsParser(
21
1/2
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
81 *reinterpret_cast<SimpleOptionsParser *>(opts));
22 81 return result;
23 }
24
25
26
1/2
✓ Branch 0 taken 485 times.
✗ Branch 1 not taken.
485 void cvmfs_options_fini(SimpleOptionsParser *opts) { delete opts; }
27
28
29 void cvmfs_options_free(char *value) { free(value); }
30
31
32 82 char *cvmfs_options_get(SimpleOptionsParser *opts, const char *key) {
33 82 string arg;
34
2/4
✓ Branch 2 taken 82 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 82 times.
✗ Branch 6 not taken.
82 const bool retval = opts->GetValue(key, &arg);
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if (!retval)
36 return NULL;
37 82 char *result = strdup(arg.c_str());
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 assert(result != NULL);
39 82 return result;
40 82 }
41
42
43 char *cvmfs_options_dump(SimpleOptionsParser *opts) {
44 char *result = strdup(opts->Dump().c_str());
45 assert(result != NULL);
46 return result;
47 }
48
49
50 767 SimpleOptionsParser *cvmfs_options_init() { return cvmfs_options_init_v2(0); }
51
52
53 767 SimpleOptionsParser *cvmfs_options_init_v2(int taint_environ) {
54
1/2
✓ Branch 2 taken 767 times.
✗ Branch 3 not taken.
767 SimpleOptionsParser *result = new SimpleOptionsParser();
55 // In contrast to the fuse module, we don't want to taint the process'
56 // environment with parameters from the cvmfs configuration in libcvmfs
57 767 result->set_taint_environment(taint_environ);
58 // Not strictly necessary but avoids a failure log message
59
3/6
✓ Branch 2 taken 767 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 767 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 767 times.
✗ Branch 10 not taken.
767 result->SetValue("CVMFS_MOUNT_DIR", "/cvmfs");
60 767 return result;
61 }
62
63
64 2098 void cvmfs_options_set(SimpleOptionsParser *opts, const char *key,
65 const char *value) {
66
3/6
✓ Branch 2 taken 2098 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 2098 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2098 times.
✗ Branch 10 not taken.
2098 opts->SetValue(key, value);
67 2098 }
68
69
70 int cvmfs_options_parse(SimpleOptionsParser *opts, const char *path) {
71 const bool result = opts->TryParsePath(path);
72 return result ? 0 : -1;
73 }
74
75 void cvmfs_options_parse_default(SimpleOptionsParser *opts, const char *fqrn) {
76 opts->ParseDefault(fqrn);
77 }
78
79 void cvmfs_options_unset(SimpleOptionsParser *opts, const char *key) {
80 opts->UnsetValue(key);
81 }
82