Parse a positive MB-valued retention env knob (CBM_RETAIN_*_MB) into bytes. * Follows the limits.c strtol convention: unset / unparseable / non-positive * → return 0 so the caller keeps its derived default. */
| 143 | * Follows the limits.c strtol convention: unset / unparseable / non-positive |
| 144 | * → return 0 so the caller keeps its derived default. */ |
| 145 | static size_t cbm_retain_env_bytes(const char *name) { |
| 146 | const char *raw = cbm_runtime_getenv(name); |
| 147 | if (!raw || !raw[0]) { |
| 148 | return 0; |
| 149 | } |
| 150 | errno = 0; |
| 151 | char *end = NULL; |
| 152 | long v = strtol(raw, &end, 10); |
| 153 | if (errno != 0 || end == raw || *end != '\0' || v <= 0) { |
| 154 | return 0; |
| 155 | } |
| 156 | return (size_t)v * 1024 * 1024; |
| 157 | } |
| 158 | |
| 159 | /* Auto-derived TOTAL retention budget: a fraction of the process memory |
| 160 | * budget, clamped to the absolute ceiling. The clamp bounds ONLY this |
no test coverage detected