See platform.h. The shape here is the one src/main.c:1104 already uses for * --port=: an end pointer says where the read stopped, errno catches a number * too large, and *end == '\0' catches anything left over. */
| 471 | * --port=: an end pointer says where the read stopped, errno catches a number |
| 472 | * too large, and *end == '\0' catches anything left over. */ |
| 473 | bool cbm_env_long(const char *name, long *out) { |
| 474 | if (!out) { |
| 475 | return false; |
| 476 | } |
| 477 | char raw[CBM_SZ_64] = {0}; |
| 478 | if (!cbm_safe_getenv(name, raw, sizeof(raw), NULL) || !raw[0]) { |
| 479 | return false; |
| 480 | } |
| 481 | /* strtol skips leading blanks of its own accord, so " 5" would read as 5. |
| 482 | * A blank in front of a setting is a slip, not a number, so refuse it here |
| 483 | * rather than let strtol quietly step over it. */ |
| 484 | if (isspace((unsigned char)raw[0])) { |
| 485 | return false; |
| 486 | } |
| 487 | char *end = NULL; |
| 488 | errno = 0; |
| 489 | long value = strtol(raw, &end, CBM_DECIMAL_BASE); |
| 490 | if (errno != 0 || !end || end == raw || *end != '\0') { |
| 491 | return false; |
| 492 | } |
| 493 | *out = value; |
| 494 | return true; |
| 495 | } |
| 496 | |
| 497 | /* ── Home directory (cross-platform) ───────────────────── */ |
| 498 |
no test coverage detected