| 1 | /* |
| 2 | Authors: |
| 3 | Pavel Březina <[email protected]> |
| 4 | |
| 5 | Copyright (C) 2024 Red Hat |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <errno.h> |
| 22 | #include <string.h> |
| 23 | #include <stdlib.h> |
| 24 | |
| 25 | #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/ |
| 26 | #include "lib/constants.h"cxx . . $ `<file>/src/lib/constants.h`/ |
| 27 | #include "lib/util/util.h"cxx . . $ `<file>/src/lib/util/util.h`/ |
| 28 | #include "lib/util/config.h"cxx . . $ `<file>/src/lib/util/config.h`/ |
| 29 | |
| 30 | static char * |
| 31 | config_read_profile_idcxx . . $ config_read_profile_id(84d1e2b99ba8db4c).(char **config) |
| 32 | { |
| 33 | return strdupcxx . . $ strdup(a8b8e32347182212).(config[0]); |
| 34 | } |
| 35 | |
| 36 | static char ** |
| 37 | config_read_featurescxx . . $ config_read_features(b6d3baa0f5548ffa).(char **config) |
| 38 | { |
| 39 | char **features; |
| 40 | int i; |
| 41 | |
| 42 | features = string_array_createcxx . . $ string_array_create(4d3fbc76ec7ad0ba).(0); |
| 43 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 44 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 45 | } |
| 46 | |
| 47 | /* Skip profile name. */ |
| 48 | for (i = 1; config[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; i++) { |
| 49 | features = string_array_add_valuecxx . . $ string_array_add_value(db56f6d53b8c0a98).(features, config[i], truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!); |
| 50 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 51 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return features; |
| 56 | } |
| 57 | |
| 58 | errno_tcxx . . $ errno_t# |
| 59 | config_readcxx . . $ config_read(2fdb31789c666a26).(const char *path, |
| 60 | char **_profile_id, |
| 61 | char ***_features) |
| 62 | { |
| 63 | char *profile_id; |
| 64 | char **features; |
| 65 | char *content; |
| 66 | char **lines; |
| 67 | errno_tcxx . . $ errno_t# ret; |
| 68 | |
| 69 | ret = textfile_readcxx . . $ textfile_read(d26d230207164ac8).(path, AUTHSELECT_FILE_SIZE_LIMITcxx . . $ `src/lib/constants.h:31:9`!, &content); |
| 70 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | lines = string_explodecxx . . $ string_explode(4a6f5072951f8444).(content, '\n', STRING_EXPLODE_ALLcxx . . $ `src/lib/util/string.h:33:9`!); |
| 75 | freecxx . . $ free(5d22bdacc48458e8).(content); |
| 76 | if (lines == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 77 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 78 | } |
| 79 | |
| 80 | if (lines[0] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 81 | ret = ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 82 | goto done; |
| 83 | } |
| 84 | |
| 85 | profile_id = config_read_profile_idcxx . . $ config_read_profile_id(84d1e2b99ba8db4c).(lines); |
| 86 | if (profile_id == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 87 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 88 | goto done; |
| 89 | } |
| 90 | |
| 91 | if (_features != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 92 | features = config_read_featurescxx . . $ config_read_features(b6d3baa0f5548ffa).(lines); |
| 93 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 94 | freecxx . . $ free(5d22bdacc48458e8).(profile_id); |
| 95 | ret = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 96 | goto done; |
| 97 | } |
| 98 | |
| 99 | *_features = features; |
| 100 | } |
| 101 | |
| 102 | *_profile_id = profile_id; |
| 103 | |
| 104 | ret = EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 105 | |
| 106 | done: |
| 107 | string_array_freecxx . . $ string_array_free(3ed91490e421178f).(lines); |
| 108 | |
| 109 | return ret; |
| 110 | } |