GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/libcvmfs_options.cc
Date: 2025-06-22 02:36:02
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 96 SimpleOptionsParser *cvmfs_options_clone(SimpleOptionsParser *opts) {
20 SimpleOptionsParser *result = new SimpleOptionsParser(
21
1/2
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
96 *reinterpret_cast<SimpleOptionsParser *>(opts));
22 96 return result;
23 }
24
25
26
1/2
✓ Branch 0 taken 578 times.
✗ Branch 1 not taken.
578 void cvmfs_options_fini(SimpleOptionsParser *opts) { delete opts; }
27
28
29 void cvmfs_options_free(char *value) { free(value); }
30
31
32 96 char *cvmfs_options_get(SimpleOptionsParser *opts, const char *key) {
33 96 string arg;
34
2/4
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 96 times.
✗ Branch 6 not taken.
96 const bool retval = opts->GetValue(key, &arg);
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if (!retval)
36 return NULL;
37 96 char *result = strdup(arg.c_str());
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 assert(result != NULL);
39 96 return result;
40 96 }
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 917 SimpleOptionsParser *cvmfs_options_init() { return cvmfs_options_init_v2(0); }
51
52
53 917 SimpleOptionsParser *cvmfs_options_init_v2(int taint_environ) {
54
1/2
✓ Branch 2 taken 917 times.
✗ Branch 3 not taken.
917 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 917 result->set_taint_environment(taint_environ);
58 // Not strictly necessary but avoids a failure log message
59
3/6
✓ Branch 2 taken 917 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 917 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 917 times.
✗ Branch 10 not taken.
917 result->SetValue("CVMFS_MOUNT_DIR", "/cvmfs");
60 917 return result;
61 }
62
63
64 2504 void cvmfs_options_set(SimpleOptionsParser *opts, const char *key,
65 const char *value) {
66
3/6
✓ Branch 2 taken 2504 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 2504 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2504 times.
✗ Branch 10 not taken.
2504 opts->SetValue(key, value);
67 2504 }
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